-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaron_Kenny_Sobel.Rmd
More file actions
55 lines (42 loc) · 2.55 KB
/
Copy pathBaron_Kenny_Sobel.Rmd
File metadata and controls
55 lines (42 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "Baron and Kenny procedure and Sobel test"
author: "Michael Blum"
date: "June, 2, 2017"
output: html_document
---
# Mediation with a single mediator
### Read the data file stored on github
```{r}
require(data.table)
nb_med<-5000
data1<-fread("https://raw.githubusercontent.com/BioShock38/mediation-challenge/master/data/challenge1.txt",header=TRUE,data.table=FALSE)
print(dim(data1))
summary(data1$exposure)
summary(data1$phenotype)
```
### Baron and Kenny procedure
We show how to perform Baron and Kenny procedure to test that the effect of exposure on the phenotype is mediated by the first "epigenetic" marker.
We start by [Step 1 of Baron and Kenny method](https://en.wikipedia.org/wiki/Mediation_(statistics)#Baron_and_Kenny.27s_.281986.29_steps_for_mediation) to test that the exposure is a significant predictor of the phenotype.
```{r}
step1<-summary(lm(phenotype~exposure,data=data1))
```
We find that the effect of*exposure* on *phenotype* is significant because the P-value is equal to `r coef(step1)[2,"Pr(>|t|)"]`.
Then, we perform [Step 2 and 3 of Baron and Kenny procedure](https://en.wikipedia.org/wiki/Mediation_(statistics)#Baron_and_Kenny.27s_.281986.29_steps_for_mediation).
```{r}
x<-1
p_step2<-coef(summary(lm(data1[,x]~data1$exposure)))[2,"Pr(>|t|)"]
p_step3<-coef(summary(lm(data1$phenotype~data1[,x]+data1$exposure)))[2,"Pr(>|t|)"]
cat("P-value Step 2 ",p_step2,", P-value Step 3 ",p_step3,"\n")
```
Because there is one P-value larger than $0.05$, we conclude that there is no evidence that the first marker is involved in mediation.
## Baron and Kenny (B&K) procedure with a [Sobel test](https://en.wikipedia.org/wiki/Sobel_test)
An additional criterion is sometimes included in Baron and Kenny procedure (see [e.g. Kupers et al. 2015](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4588868/). The Sobel statistic is computed to test that the product of the effect of the exposure on the mediator and the effect of the mediator on the phenotype (while controlling for exposure) is different from 0.
```{r}
require(multilevel)
z_sobel<-sobel(pred=data1$exposure,med=data1[,x],out=data1$phenotype)$z.value
p_sobel<-2*pnorm(abs(z_sobel),lower.tail=F)
cat("P-value Sobel",p_sobel,"\n")
```
Same conclusion as before.
# Mediation with multiple mediators
Now, you should analyse the full data that include mulliple mediators. Some R packages might be useful (or not) including [fdrtool](https://cran.r-project.org/web/packages/fdrtool/index.html), and [qvalue](http://bioconductor.org/packages/release/bioc/html/qvalue.html), [hima](https://github.com/YinanZheng/HIMA).