Last data update: 2014.03.03

R: Mediation Analysis with Continuous Predictor
med.contxR Documentation

Mediation Analysis with Continuous Predictor

Description

To estimate the mediation effects when the predictor is continuous.

Usage

med.contx(x, y, dirx, binm = NULL, contm = NULL, catm = NULL, 
  jointm = NULL, margin = 1, n = 20, seed = sample(1:1000, 1), 
  mart = F, nu = 0.001, D = 3, distn = "gaussian", 
  family1 = gaussian(link = "identity"))

Arguments

x

a data frame contains the predictor, all mediators and covariates.

y

the vector of outcome variable.

dirx

the column number of x that locates the predictor.

binm

the column number of x that locates the binary mediators.

contm

the column numbers of x that locate the potential continuous mediators.

catm

categorical mediators should be binarized and be presented as a list, where the first item is the number of categorical variables and the following items are the column numbers of each binarized categorical variable in x. data.org organizes the categorical mediators in this format after they pass the mediator tests.

jointm

a list where the first item is the number of groups of joint mediators to be considered, and each of the following items identifies the column numbers of the mediators in x for each group of joint mediators.

margin

the change in predictor when calculating the mediation effects, see Yu et al. (2014).

n

the time of resampling in calculating the indirect effects, default is n=20, see Yu et al. (2014).

seed

set seed to make the calculation repeatable. The default value of seed is from sample(1:1000,1).

mart

if TURE, Multiple Additive Regression Trees (MART) will be used to fit the final full model in estimating the outcome. The default value of mart is FALSE, in which case, a generalized linear model will be used to fit the final full model.

nu

set the parameter "interaction.depth" in gbm function if MART is to be used, by default, nu=0.001. See also help(gbm.fit).

D

set the parameter "shrinkage" in gbm function if MART is to be used, by default, D=3. See also help(gbm.fit).

distn

the assumed distribution of the outcome if MART is used for final full model. The default value of distn is "gaussian". If y is binary, may use distn="bernoulli".

family1

define the conditional distribution of y given x, and the linkage function that links the mean of y with the system component if generalized linear model is used as the final full model. The default value of family1 is gaussian(link="identity"). If y is binary, family1 can be defined as binomial(link = "logit").

Details

The mediators are not tested in this function. data.org should be used for the tests and the resulted list can be used directly to define the parameters in this function. med.contx considers all variables in x as mediators or covariates in the final model and all variables identified by contm, binm, catm, or jointm as mediators.

Value

denm

a matrix where each column gives the estimated direct effect not from the corresponding mediator (identified by the column name), see Yu et al. (2014) for the definition, and each row corresponding to the results from one resampling.

ie

a matrix where each column gives the estimated indirect effect from the corresponding mediator (identified by the column name) and each row corresponding to the results from one resampling.

te

a vector of the estimated total effect from each resampling.

model

a list, where the first item, mart, is TRUE if a MART is fitted as the final model; the second item, full.model, is the fitted final full model where y is the outcome and all predictor, covariates, and mediators are the explanatory variables; and the third item, best.iter, is the number of best iterations if MART is used to fit the final model, is NULL if the final model is a generalized linear model.

Author(s)

Qingzhao Yu qyu@lsuhsc.edu

References

J.H. Friedman, T. Hastie, R. Tibshirani (2000) <doi: 10.1214/aos/1016120463>. "Additive Logistic Regression: a Statistical View of Boosting," Annals of Statistics 28(2):337-374.

J.H. Friedman (2001) <doi: 10.1214/aos/1013203451>. "Greedy Function Approximation: A Gradient Boosting Machine," Annals of Statistics 29(5):1189-1232.

Yu, Q., Fan, Y., and Wu, X. (2014) <doi: 10.4172/2155-6180.1000189>. "General Multiple Mediation Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journal of Biometrics & Biostatistics,5(2): 189.

See Also

"boot.med.contx" to make inferences on the estimated mediation effects using bootstrap method, "med.binx" and "boot.med.binx" for mediation analysis when the preditor is binary.

Examples

data("weight_behavior")
 #binary y
 x=weight_behavior[,2:14]
 y=weight_behavior[,15]
 data.contx<-data.org(x,y,pred=1,contmed=c(5,8:10),binmed=c(7,11),
   binref=c(1,1),catmed=6,catref=1,binpred=FALSE,alpha=0.4,alpha2=0.4)
 temp5<-med.contx(x=data.contx$x,y,dirx=data.contx$dirx,binm=data.contx$binm, 
   contm=data.contx$contm,catm=data.contx$catm,seed=1,n=2,
   family1=binomial(link = "logit"))
 temp6<-med.contx(x=data.contx$x,y=y,dirx=data.contx$dirx,binm=data.contx$binm, 
   contm=data.contx$contm,catm=data.contx$catm,seed=1,n=2,mart=TRUE,nu=0.05,
   distn="bernoulli")
 
 #continuous y
 x=weight_behavior[,2:14]
 y=weight_behavior[,1]
 data.contx<-data.org(x,y,pred=1,contmed=c(12:13),binmed=c(7,11),
   binref=c(1,1),catmed=6,catref=1,binpred=FALSE,
   family1=gaussian(link="identity"),alpha=0.4,alpha2=0.4)
 temp7<-med.contx(x=data.contx$x,y,dirx=data.contx$dirx,binm=data.contx$binm, 
   contm=data.contx$contm,catm=data.contx$catm,seed=1,n=2) 
 temp8<-med.contx(x=data.contx$x,y=y,dirx=data.contx$dirx,binm=data.contx$binm, 
   contm=data.contx$contm,catm=data.contx$catm, seed=1,n=2,mart=TRUE,nu=0.05) 

Results