##More details on this example are given in the accompanying vignette.
data(NavyAdenoma)
##the exposure of interest is the daily intake of fish
##the possible mediators are 149 normalized serum metabolite values
##the outcome of interest is colorectal adenoma case-control status
##get weights needed due to retrospective sampling, to use for all regressions
##that do not have adenoma status as the outcome
prev <- 0.228
p <- sum(NavyAdenoma$Adenoma==1)/nrow(NavyAdenoma)
w <- rep(NA, nrow(NavyAdenoma))
w[NavyAdenoma$Adenoma == 1] <- prev/p
w[NavyAdenoma$Adenoma == 0] <- (1-prev)/(1-p)
##perform the test of mediation, adjusting for the covariates
##BMI, gender, age, and current smoking status
##(only running 10 permutations in this example - would need to
##perform more to get an accurate p-value)
set.seed(840218)
medsFish <- medTest(E=NavyAdenoma$Fish,
M=NavyAdenoma[, 6:154],
Y=NavyAdenoma$Adenoma,
Z=NavyAdenoma[, 2:5],
nperm=10, w=w)
##get metabolite with lowest p-value
medsFish[which.min(medsFish[,"p"]),]
colnames(NavyAdenoma[,-(1:5)])[which.min(medsFish[,"p"])]
Run the code above in your browser using DataLab