---
title: "CauMedi"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{CauMedi}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

## Introduction
Welcome to the CauMedi vignette! This document provides an overview of the CauMedi package. CauMedi is a causal mediation framework for cell type-specific single-cell data based on joint mediator multilevel models. The framework jointly models overdispersed counts and zero inflation for the mediators.

### Installation
To install the package, please use:
```{r}
#install.packages("CauMedi")
```

## Example Usage

Run prepare_CauMedi_data first to prepare inputs before running main function.

```{r}
library(CauMedi)
set.seed(42)
n_subj <- 100
n_gene <- 50

gene_ids <- paste0("gene", seq_len(n_gene))
M_mat <- matrix(rgamma(n_subj * n_gene, shape = 2, rate = 1),
                nrow = n_subj, ncol = n_gene,
                dimnames = list(paste0("subj", seq_len(n_subj)), gene_ids))
F_mat <- matrix(runif(n_subj * n_gene, min = 0, max = 1),
                nrow = n_subj, ncol = n_gene,
                dimnames = list(paste0("subj", seq_len(n_subj)), gene_ids))
Y <- rnorm(n_subj)
X <- rbinom(n_subj, 1, 0.5)

feature_meta <- data.frame(
  feature_id = gene_ids,
  cell_type  = "Vasculature_cells",
  gene       = gene_ids,
  stringsAsFactors = FALSE
)

pd <- prep_CauMedi_data(M_mat = M_mat, F_mat = F_mat, feature_meta = feature_meta, Y = Y, X = X)
```

Use outputs from prep_CauMedi_data function as inputs for main function CauMedi.

```{r}
res <- CauMedi(data = pd$data, feature_meta = pd$feature_meta)
print(res)
```


