Last data update: 2014.03.03

R: Multilevel Mediation Analysis
mlmaR Documentation

Multilevel Mediation Analysis

Description

The function transforms the data set and does multilevel mediation analysis. The total, direct, and indirect effects will be returned as the results.

Usage

mlma(y, biny=FALSE, data1=NULL, x, levelx=1, levely=1, m, l1=NULL,            
     l2=NULL,c1=NULL,c1r=rep(1,length(c1)), c2=NULL, c2r=rep(1,length(c2)),   
     level,weight=rep(1,length(x)), random="(1|level)", random.m1=NULL, 
     intercept=TRUE,covariates=NULL,cy1=NULL,cy2=NULL,cm=NULL,joint=NULL, 
     org.data=FALSE,f01y=NULL,f10y=NULL,f02ky=NULL,f20ky=NULL,f01km1=NULL,
     f01km2=NULL,f10km=NULL)

Arguments

y

the vector of the outcome variable.

biny

True if the outcome is binary, otherwise False. Default is False.

data1

The transformed and organized data set from data.org. If the data set has not been organized, leave data1=NULL (by default), and set org.data=T with the transformation functions (f arguments). Otherwise, set data1 as the output from the data.org function and do not include the arguments: org.data and fs.

x

the vector of the predictive variable.

levelx

the level of x (1 or 2), 1 by default.

levely

the level of y (1 or 2), 1 by default.

m

the matrix or vector of mediators.

l1

the column numbers of level 1 continuous mediators in m or the list of names of the level 1 continuous mediators.

l2

the column numbers of level 2 continuous mediators in m or the list of names of the level 2 continuous mediators.

c1

the column numbers of level 1 categorical mediators in m or the list of names of the level 1 categorical mediators.

c1r

the reference groups of categorical mediators specified by c1.

c2

the column numbers of level 2 categorical mediators in m or the list of names of the level 2 categorical mediators.

c2r

the reference groups of categorical mediators specified by c2.

level

a vector that record the group number for each observation.

weight

the weight of cases in groups.

random

the random effect part for the full model. random = "(1|level)" by default.

random.m1

the random effect part for model explaining the mediators. All other random effects are random = "(1|level)" if not specified here.

intercept

True if fit an intercept to models, by default.

covariates

the covariates matrix to explain the outcome, y, and/or the mediators, m.

cy1

the column numbers of covariates that are level 1 and used to explain y.

cy2

the column numbers of covariates that are level 2 and used to explain y.

cm

the column numbers of covariates that are used to explain m. cm[[1]] gives the mediators (in l1, cl, l2, or c2) that can be partially explained by covariates. Each of the rest items of the cm list shows the column number(s) in covariates that should be used to explain each mediator listed in cm[[1]] and by that order.

joint

the list of group(s) of mediators whose joint mediation effect is of interests. joint[[1]] list the levels of mediators in each group and by the order of the list. Note that if any mediator in the group is of level 2, the level of the group should be 2.

org.data

if is TRUE, first organize the data set and do transformations using the function "data.org". In such case, need to specify the transformation function arguments.

f01y, f10y, f02ky, f20ky, f01km1, f01km2, f10km

the transformation functions as describe in the function "data.org". Need these arguments only when org.data=T.

Details

The multilevel mediation is based on the following linear multilevel additive models:

Y_{ij} = u_{0j}^Y(X_{.j}, mathbf{M}_{.j}, mathbf{Z}_{.j})+u_{1j}^Y(X_{ij}-X_{.j})+∑_{k=1}^Ku_{2jk}^Y(M_{ijk}-M_{.jk})+u_{3j}^Y(mathbf{Z}_{ij}-mathbf{Z}_{.j})+r_{ij}^Y

where

u_{0j}^Y(X_{.j}, mathbf{M}_{.j}, mathbf{Z}_{.j}) = c_{00}^Y + {oldsymbol{β}_{01}^Y}^Tmathbf{f}_{01}^Y(X_{.j}) + ∑_{k=1}^K{oldsymbol{β}_{02k}^Y}^Tmathbf{f}_{02k}^Y(M_{.jk}) + {oldsymbol{β}_{03}^Y}^Tmathbf{Z}_{.j} + r_{0j}^Y

u_{1j}^Y(X_{ij}-X_{.j}) = {oldsymbol{β}_{10}^Y}^Tmathbf{f}_{10}^Y(X_{ij}-X_{.j}) + r_{1j}^Y

u_{2jk}^Y(M_{ijk}-M_{.jk}) = {oldsymbol{β}_{20k}^Y}^Tmathbf{f}_{20k}^Y(M_{ijk}-M_{.jk}) + r_{2jk}^Y, mbox{~~~~~~}k=1,…,K

u_{3j}^Y(mathbf{Z}_{ij}-mathbf{Z}_{.j}) = {oldsymbol{β}_{30}^Y}^T(mathbf{Z}_{ij}-mathbf{Z}_{.j}) + r_{3j}^Y

For k=1,…,K,

M_{.jk} = c_{00k}^M+u_{1jk}^M(X_{ij}-X_{.j})+r_{ijk}^M

u_{0jk}^M(X_{.j}) = c_{00k}^M + {oldsymbol{β}_{01k}^M}^Tmathbf{f}_{01k}^{M1}(X_{.j}) + r_{0jk}^M

u_{1jk}^M(X_{ij}-X_{.j}) = {oldsymbol{β}_{10k}^M}^Tmathbf{f}_{10k}^M(X_{ij}-X_{.j}) + r_{1jk}^M

If for some k, M_k is level 2 variable,

M_{.jk} = c_{00k}^M + {oldsymbol{β}_{01k}^M}^Tmathbf{f}_{01k}^{M2}(X_{.j}) + r_{0jk}^M

Note that in the models, mathbf{f}(cdot)=(f_1(cdot), f_2(cdot), cdots, f_l(cdot))^T is a set of l transformation functions on cdot, with the corresponding linear coefficients vector oldsymbol{β}=(β_1, β_2, cdots, β_l)^T. mathbf{f} and l are known for model fitting. l may be different with mathbf{f} of different sub- and super-scripts.

Value

A "mlma" mode list will be returned with the following items:

de1

level 1 direct effect from predictor.

de2

level 2 direct effect from predictor.

ie1

level 1 indirect effect from level 1 mediator.

ie12

level 2 indirect effect from level 1 mediator.

ie2

level 2 indirect effect from level 2 mediator.

f1

the overall multilevel model.

fm1

a list, where the first item identifies the level 1 mediators, and in that order, the following items give the prediction functions of the mediators.

fm2

a list, where the first item identifies the level 2 mediators, and in that order, the following items give the prediction functions of the mediators.

ie1_list

a list, where the first item identifies the level 1 mediators, and in that order, the following items give the column(s) of the indirect effects of the mediator in ie1.

ie2_list

a list, where the first item identifies the level 2 mediators, and in that order, the following items give the column(s) of the indirect effects of the mediator in ie2.

iej2_list

a list, where the first item identifies the level 2 joint mediators, and in that order, the following items give the column(s) of the indirect effects of the mediator in cbind(ie12,ie2).

ie12_1,ie12_2, ie1_1, ie1_2, ie2_1, ie2_2

the first and second part of the corresponding indirect effects.

x

the vector of the predictive variable.

x.j

the vector of the aggregated variable at the higher level by the order of unique(level[!is.na(level)]).

data1

The results from data.org.

Author(s)

Qingzhao Yu (qyu@lsuhsc.edu), Bin Li (bli@lsu.edu).

Examples

data(sim.111)
data1<-data.org(x=sim.111$x, levelx=1, m=sim.111$m, l1=1:2, c1=3, c1r=1, 
                f01y=c("x","log(x^2)"), f10y=c("x^2","sqrt(x+6)"), 
                f20ky=list(2,c("x","x^3")), f01km1=list(2,"sqrt(x)+3"), 
                f10km=list(2,"log(x+2)"), level=sim.111$level)
temp<-mlma(y=sim.111$y, biny=FALSE, data1=data1, x=sim.111$x, levelx=1, m=sim.111$m, 
                l1=1:2,c1=3, c1r=1,level=sim.111$level)
#can also do the above analysis using the following code
temp<-mlma(y=sim.111$y, biny=FALSE, data1=data1, x=sim.111$x, levelx=1, m=sim.111$m, 
                l1=1:2,c1=3, c1r=1,level=sim.111$level,org.data=TRUE,
                f01y=c("x","log(x^2)"), f10y=c("x^2","sqrt(x+6)"), 
                f20ky=list(2,c("x","x^3")), f01km1=list(2,"sqrt(x)+3"), 
                f10km=list(2,"log(x+2)"))

data(sim.211)
data1<-data.org(x=sim.211$x, levelx=2, m=sim.211$m, l1=2,l2=1, c1=3, c1r=1,
                   f01y=c("x","log(x^2)"), f02ky=list(1,c("x","x^2")), 
                   f20ky=list(2,c("x","x^3")), f01km1=list(2,"sqrt(x)+3"), 
                   f01km2=list(1,c("x^1.2","x^2.3")), level=sim.211$level)
temp<-mlma(y=sim.211$y, biny=FALSE, data1, x=sim.211$x, levelx=2, m=sim.211$m, 
           l1=2, l2=1, c1=3, c1r=1,level=sim.211$level)                               

Results