---
title: "SMAHP"
author: "Weijia Fu, Seungjun Ahn"
date: "Feb 5th, 2025"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{SMAHP}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

## Introduction
Welcome to the SMAHP vignette! This document provides an overview of the SMAHP package. SMAHP (Survival Mediation Analysis of High-dimensional Proteogenomic data) is a novel method for survival mediation analysis that simultaneously handles high-dimensional exposures and mediators, integrates multi-omics data, and offers a robust statistical framework for identifying causal pathways on survival outcomes. SMAHP package is a software extension of our methodology work.

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

## Example Usage
We will use the example data built in the package to demonstrate how to use the main function.
```{r}
library(SMAHP)
# load example data
data("example_dat")
```

The example data is a simulated dataset for demonstration purpose. It contains exposure (X), mediators (M), covariates (C) and survival data (surv_dat).

```{r}
surv_dat <- example_dat$surv_dat
res <- SMAHP(example_dat$X, example_dat$M, example_dat$C, 
             time = surv_dat$time, status = surv_dat$status)
```
```{r}
print(res$p_final_matrix)
```

```{r}
print(res$p_adjusted_matrix)
```

```{r}
print(res$p_med_matrix)
```

The main function returns a list containing three matrices: (1) p_final_matrix, which is the raw p-value before adjustment, (2) p_adjusted_matrix, which contains p-values adjusted using the selected adjustment method, and (3) p_med_matrix, a mediation-exposure matrix encoded with 0s and 1s. In p_med_matrix, a value of 1 indicates a detected mediation association, while 0 means no significant mediation association. The NAs in p_final_matrix and p_adjusted_matrix mean the exposure-mediator pairs were not selected in previous steps.

The function get_sig_pathway can be used to extract the the name of exposure and mediator from identified significant mediation pathways with related adjusted p-values.

```{r}
get_sig_pathway(res_SMAHP = res)
```

The function get_coef can be used to extract the the name of exposure and mediator from identified significant mediation pathways with related coefficient estimates.

```{r}
get_coef(res_SMAHP = res)
```