Title: | Multilevel Mediation Analysis |
---|---|
Description: | Do multilevel mediation analysis with generalized additive multilevel models. The analysis method is described in Yu and Li (2020), "Third-Variable Effect Analysis with Multilevel Additive Models", PLoS ONE 15(10): e0241072. |
Authors: | Qingzhao Yu, Bin Li |
Maintainer: | Qingzhao Yu <[email protected]> |
License: | GPL (>= 2) |
Version: | 6.3-1 |
Built: | 2025-01-21 03:55:55 UTC |
Source: | https://github.com/cran/mlma |
The package is used to do mediation analysis with generalized multilevel models.
"data.org"
is used to transform the variables and organize the predictor, mediators and outcome into the format that are ready to be used for multilevel mediation analysis. "mlma"
is for multilevel mediation analysis on the original data set. "boot.mlma"
is a combined function that organized data set, do multilevel mediation analysis on original data sets and bootstrapping samples.
The multilevel mediation is based on the following linear multilevel additive models:
where
For
If for some k, is level 2 variable,
Note that in the models, is a set of l transformation functions on
, with the corresponding linear coefficients vector
.
and l are known for model fitting. l may be different with
of different sub- and super-scripts.
Qingzhao Yu [email protected], Bin Li [email protected]
Maintainer: Qingzhao Yu [email protected]
Yu, Q. and Li, B., (2020). <doi:10.1371/journal.pone.0241072>. "Third-Variable Effect Analysis with Multilevel Additive Models," PLoS ONE 15(10): e0241072.
Yu, Q., Yu, M., Zou, J., Wu, X., Gomez, SL, Li, B. (2021). <doi:10.1177/26320843211061292>. "Multilevel Mediation Analysis on Time-to-Event Outcomes - Exploring racial/ethnic Disparities in Breast Cancer Survival in California," Research Methods in Medicine & Health Sciences.
Yu, Q. and Li, B., 2022. Statistical Methods for Mediation, Confounding and Moderation Analysis Using R and SAS. Chapman and Hall/CRC. ISBN 9780367365479.
Bootstrap samples are selected from the original data set. The bootstrap sample has the same number of groups and in each group, the same number of observations as in the original data set. Based on each bootstrap sample, a multilevel mediation analysis is done and the results saved to make inferences on the total, direct and indirect effects.
boot.mlma(y, data1=NULL,x=data1$parameter$x, m=data1$parameter$m, levelx=data1$parameter$levelx, levely=data1$parameter$levely, xref=NULL, yref=NULL, l1=data1$parameter$l1,l2=data1$parameter$l2, c1=data1$parameter$c1, #levelx is the level of x c1r=data1$parameter$c1r, c2=data1$parameter$c2, c2r=data1$parameter$c2r,level=data1$parameter$level, weight=rep(1,nrow(as.matrix(x))), random="(1|level)", random.m1=NULL,intercept=TRUE, family1=NULL, familym=vector("list",ncol(m)), covariates=NULL, cy1=NULL, cy2=NULL, cm=NULL, joint=NULL,f01y=data1$parameter$f01y, f10y=data1$parameter$f10y, f02ky=data1$parameter$f02ky, f20ky=data1$parameter$f20ky, f01km1=data1$parameter$f01km1, f01km2=data1$parameter$f01km2, f10km=data1$parameter$f10km, data2=NULL, x.new=NULL, m.new=m, level.new=level, weight.new=NULL,covariates.new=covariates,boot=100,echo=TRUE, plot.it=TRUE, cov.mat=FALSE)
boot.mlma(y, data1=NULL,x=data1$parameter$x, m=data1$parameter$m, levelx=data1$parameter$levelx, levely=data1$parameter$levely, xref=NULL, yref=NULL, l1=data1$parameter$l1,l2=data1$parameter$l2, c1=data1$parameter$c1, #levelx is the level of x c1r=data1$parameter$c1r, c2=data1$parameter$c2, c2r=data1$parameter$c2r,level=data1$parameter$level, weight=rep(1,nrow(as.matrix(x))), random="(1|level)", random.m1=NULL,intercept=TRUE, family1=NULL, familym=vector("list",ncol(m)), covariates=NULL, cy1=NULL, cy2=NULL, cm=NULL, joint=NULL,f01y=data1$parameter$f01y, f10y=data1$parameter$f10y, f02ky=data1$parameter$f02ky, f20ky=data1$parameter$f20ky, f01km1=data1$parameter$f01km1, f01km2=data1$parameter$f01km2, f10km=data1$parameter$f10km, data2=NULL, x.new=NULL, m.new=m, level.new=level, weight.new=NULL,covariates.new=covariates,boot=100,echo=TRUE, plot.it=TRUE, cov.mat=FALSE)
y |
the vector of the outcome variable. |
data1 |
the results from data.org. If data1=NULL, needs to set up x, m, levelx, xref, l1, l2, c1,c2, c2r, f01y, f10y, f02ky, f20ky, f01km1, f01km2, f10km ... |
x |
the vector of the predictive variable. |
m |
the mediators. The program will identify the levels and types of each mediator if not specified by l1, l2, c1, or c2. A mediator is identified as categorical if the mediator is a factor, a character, or has only two unque values. |
levelx |
the level of x (1 or 2). If it is not given, levelx will be decided by x. |
levely |
the level of y (1 or 2). If it is not given, levely will be decided by y. |
xref |
the reference group of x if it is binary. By default it will be the first level of x. |
yref |
the reference group of y if it is binary. By default it will be the first level of y. |
l1 |
the column numbers of level 1 continuous mediators in m. |
l2 |
the column numbers of level 2 continuous mediators in m. |
c1 |
the column numbers of level 1 categorical mediators in m. |
c1r |
the reference groups of categorical mediators specified by c1. |
c2 |
the column numbers of level 2 categorical mediators in m. |
c2r |
the reference groups of categorical mediators specified by c2. |
f01y , f10y , f02ky , f20ky , f01km1 , f01km2 , f10km
|
the transformation functions as describe in the function |
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. |
family1 |
the glm family for the response variable y. If it is null, will be binomial with logic link for binary y and gaussian with identity link for continuous y. |
familym |
a list of length ncol(m), each item gives the glm family for the corresponding column of m. If an item is null, the family will be binomial with logic link for binary m and gaussian with identity link for continuous m. |
boot |
the number of bootstrapping samples. |
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.For example, joint=list(1,c("m.2","m.4")) means find the joint effects of level 1 mediators m.2 and m.4. |
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. |
data2 |
the results from data.org on x.new, covariates.new, m.new, level.new, and weight.new. If data1=NULL, needs to rerun data.org on the new data. If x.new is also NULL, set data2=data1. The new data is the same as the old data. |
x.new , covariates.new , m.new , level.new , weight.new
|
the settings that we want to make inferences on the mediation effects. If m.new=NULL, generate new mediators from x.new. |
echo |
print a i when finish the ith bootstrap estimation if echo=T. |
plot.it |
If true, middle results will be stored for future use to plot confidence intervals. |
cov.mat |
If true, the result on full dataset include the estimation of variances through normal approximation. |
The multilevel mediation is based on the following linear multilevel additive models:
where
For
If for some k, is level 2 variable,
Note that in the models, is a set of l transformation functions on
, with the corresponding linear coefficients vector
.
and l are known for model fitting. l may be different with
of different sub- and super-scripts.
Return a "mlma.boot" mode list, which include the following items:
de1 |
direct effect(s) of level 1 exposure(s). de1 is a matrix of dimension n times boot by nx1, where n is the number of observations, and nx1 is the number of level 1 exposures. boot is the number of bootstrap samples. |
de2 |
direct effect(s) of level 2 exposure(s). de2 is a matrix of dimension n2 times boot by nx2, where n2 is the number of unique levels, and nx2 is the number of level 2 exposures. |
ade1 |
average direct effect(s) of level 1 exposure(s). ade1 is a matrix of dimension boot by nx1. |
ade2 |
average direct effect(s) of level 2 exposure(s). ade2 is a matric of dimension boot by nx2. |
te1 |
total effect of each level 1 exposure. te1 is a matrix of dimension n times boot by nx1, where n is the number of observations, and nx1 is the number of level 1 exposures. |
te2 |
total effect of each level 2 exposure. te2 is a matrix of dimension n2 times boot by nx2, where n2 is the number of unique levels, and nx2 is the number of level 2 exposures. |
ate1 |
average total effect(s) of level 1 exposure(s). ate1 is a matrix of dimension boot by nx1. |
ate2 |
average total effect(s) of level 2 exposure(s). ate2 is a matrix of dimension boot by nx2. |
ie1 |
level 1 indirect effect from level 1 exposure(s) to level 1 mediator(s) on the outcome. ie1 is an array of dimension (n*boot,nm1,nx1), where nm1 is the number of level 1 mediators. |
ie2 |
level 2 indirect effect from level 2 exposure(s) to level 2 mediator(s) on the outcome. ie2 is an array of dimension (n2*boot,nm2,nx2), where nm2 is the number of level 2 mediators. |
ie12 |
level 2 indirect effect from level 2 exposure(s) to level 1 mediator(s) on the outcome. ie12 is an array of dimension (n2*boot,nm1,nx2). |
aie1 |
level 1 average indirect effect from level 1 exposure(s) to level 1 mediator(s) on the outcome. aie1 is a matrix of dimension (nm1*boot,nx1). |
aie2 |
level 2 average indirect effect from level 2 exposure(s) to level 2 mediator(s) on the outcome. aie2 is a matrix of dimension (nm2*boot,nx2). |
aie12 |
level 2 average indirect effect from level 2 exposure(s) to level 1 mediator(s) on the outcome. aie12 is a matrix of dimension (nm1*boot,nx2). |
je1 |
joint level 1 indirect effect from level 1 exposure(s) to joint level 1 mediators on the outcome. je1 is an array of dimension (n*boot,nj1,nx1), where nj1 is the number of groups of level 1 mediators. |
je2 |
joint level 2 indirect effect from level 2 exposure(s) to joint level 2 mediators on the outcome. je2 is an array of dimension (n2*boot,nj2,nx2), where nj2 is the number of groups oflevel 2 mediators. |
je12 |
joint level 2 indirect effect from level 2 exposure(s) to joint level 1 mediators on the outcome. je12 is an array of dimension (n2*boot,nj1,nx2). |
aje1 |
average joint level 1 indirect effect from level 1 exposure(s) to joint level 1 mediators on the outcome. aje1 is a matrix of dimension (nj1*boot,nx1). |
aje2 |
average joint level 2 indirect effect from level 2 exposure(s) to joint level 2 mediators on the outcome. je2 is a matrix of dimension (nj2*boot,nx2), where nj2 is the number of groups oflevel 2 mediators. |
aje12 |
average joint level 2 indirect effect from level 2 exposure(s) to joint level 1 mediators on the outcome. je12 is a matrix of dimension (nj1*boot,nx2). |
full |
an "mlma" results using the original data set. |
xboot |
a n*boot vector of the level 1 predictors in all boot bootstrap samples. |
xjboot |
a g*boot vector of the (aggregated) level 2 predictors in all boot bootstrap samples. |
levelx |
inherited from the same argument. |
level |
inherited from the same argument. |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.111) sim.111$m[,3]=as.factor(sim.111$m[,3]) data2<-data.org(ifelse(sim.111$x>1.9,1,0), m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2.boot<-boot.mlma(y=sim.111$y, data1=data2,boot=2,joint=list(1,1:2)) #can also do the above analysis using the following code temp2.boot<-boot.mlma(y=ifelse(sim.111$y>4.5,1,0), x=sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level,boot=2) #with a level 2 exposure data(sim.211) data1<-data.org(x=ifelse(sim.211$x>2.2,1,0), m=sim.211$m, f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1.boot<-boot.mlma(y=sim.211$y, data1=data1,boot=2) #with both level 1 and 2 exposure data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3.boot<-boot.mlma(y=sim.211$y, data1=data3,boot=2)
data(sim.111) sim.111$m[,3]=as.factor(sim.111$m[,3]) data2<-data.org(ifelse(sim.111$x>1.9,1,0), m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2.boot<-boot.mlma(y=sim.111$y, data1=data2,boot=2,joint=list(1,1:2)) #can also do the above analysis using the following code temp2.boot<-boot.mlma(y=ifelse(sim.111$y>4.5,1,0), x=sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level,boot=2) #with a level 2 exposure data(sim.211) data1<-data.org(x=ifelse(sim.211$x>2.2,1,0), m=sim.211$m, f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1.boot<-boot.mlma(y=sim.211$y, data1=data1,boot=2) #with both level 1 and 2 exposure data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3.boot<-boot.mlma(y=sim.211$y, data1=data3,boot=2)
To transform variables and generate data sets for mediation analysis.
data.org(x, m, levely = 1, y = NULL, levelx = NULL, xref = NULL, l1 = NULL, l2 = NULL, c1 = NULL, c1r = NULL, c2 = NULL, c2r = NULL, f01y = NULL, f10y = NULL, f02ky = NULL, f20ky = NULL, f01km1 = NULL, f01km2 = NULL, f10km = NULL, level = 1:nrow(as.matrix(x)), weight = NULL)
data.org(x, m, levely = 1, y = NULL, levelx = NULL, xref = NULL, l1 = NULL, l2 = NULL, c1 = NULL, c1r = NULL, c2 = NULL, c2r = NULL, f01y = NULL, f10y = NULL, f02ky = NULL, f20ky = NULL, f01km1 = NULL, f01km2 = NULL, f10km = NULL, level = 1:nrow(as.matrix(x)), weight = NULL)
x |
the data frame of exposure variable(s). If there are multiple exposures, a categorical exposure should be binarized with the reference group coded as 0. |
m |
the data frame of all mediators. The program will identify the levels and types of each mediator if not specified by l1, l2, c1, or c2. A mediator is identified as categorical if the mediator is a factor, a character, or has only two unque values. Note: the name for one mediator should NOT be the subset of the name of another mediator. |
levely |
the level of y (1 or 2), 1 by default. If it is NULL, levely will be decided automatically by y. |
y |
only needed if levely is not given. |
levelx |
the vector of levels of every column of x (1 or 2). If it is not given, levelx will be decided automaticaly. If there is only level 1 exposure, but there are level 2 mediator(s), the level 2 exposure will be created by aggregate all the level 1 exposure(s) to level 2. |
xref |
the reference group of x if it is a single binary variable. By default it will be the first level of x. |
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. |
f01y |
the transformation function expressions on level 2 exposures (x.jm) in explaining y (eg, list(1,c("x^2","log(x)"))). The first item lists column numbers/variable names of the level 2 exposures in x, which needs to be transformed. By that order, each of the rest items of f01y list the transformation functional expressions for each exposure. The exposures not specified in the list will not be transformed in any way. |
f10y |
the transformation function expressions on level 1 exposure (xijm) in explaining y. (eg, list(2,c("x^2","log(x)"))). The first item lists column numbers/variable names of the level 1 exposures in x, which needs to be transformed. By that order, each of the rest items of f10y list the transformation functional expressions for each exposure. The exposures not specified in the list will not be transformed in any way. |
f02ky |
the transformation-function-expression list on level 2 mediators (m.jk) in explaining y (eg, list(2:3,c("log(x)","sqrt(x)"), "2*x")). The first item lists column numbers/variable names of the level 2 mediators in m, which needs to be transformed. By that order, each of the rest items of f02ky list the transformation functional expressions for each mediator. The mediators not specified in the list will not be transformed in any way. |
f20ky |
the transformation-function-expression list on level 1 mediators (mijk-m.jk) in explaining y.The first item lists column numbers/variable names of the level 1 mediators in m, which needs to be transformed. By that order, each of the rest items of f20ky list the transformation functional expressions for each mediator. The mediators not specified in the list will not be transformed in any way. |
f01km1 |
the transformation-function-expression list on level 2 predictor (x.jm) in explaining the level 1 mediators. The first item is a matrix with two columns, the first column is the column numbers of the level 1 mediators in m, which should be explained by the transformed predictor(s). The second column indicates the column number of the exposure in x that will be transformed to explain the mediator identified by the 1st column of the same row. By the order of the rows of the first item, each of the rest items of f01km1 lists the transformation functional expressions for the level 2 exposure (identified by column 2) in explaining each mediator (identified by column 1). The mediators not specified in the list will be explained by the original format of the level 2 exposures. e.g.list(matrix(c(1,2,1,1),2,2), "x^2","x^2") means x[,1]^2 is used to explain both m[,1] and m[,2]. |
f01km2 |
the transformation-function-expression list on level 2 predictor (x.jm) in explaining the level 2 mediators. The first item is a matrix with two columns, the first column is the column numbers of the level 2 mediators in m, which should be explained by the transformed predictor(s). The second column indicates the column number of the exposure in x that will be transformed to explain the mediator identified by the 1st column of the same row. By the order of the rows of the first item, each of the rest items of f01km2 lists the transformation functional expressions for the level 2 exposure (identified by column 2) in explaining each mediator (identified by column 1). The mediators not specified in the list will be explained by the original format of all level 2 exposures. |
f10km |
the transformation-function-expression list on level 1 predictor (xijm) in explaining the level 1 mediators. The first item is a matrix with two columns, the first column is the column numbers of the level 1 mediators in m, which should be explained by the transformed level 1 exposure(s). The second column indicates the column number of the exposure in x that will be transformed to explain the mediator identified by the 1st column of the same row. By the order of the rows of the first item, each of the rest items of f10km lists the transformation functional expressions for the level 1 exposure (identified by column 2) in explaining each mediator (identified by column 1). The mediators not specified in the list will be explained by the original format of all level 1 exposures. |
level |
a vector that record the group number for each observation. |
weight |
the weight of cases in groups. |
The arguments starting with "f" are used to specify the transformation functions of the predictor or mediators in explaining y, or the transformation functions of the predictor in explaining the mediators. If the name of the argument includes a "k", the transformation is on the mediators. If the names of the arguments end with "y", the transformation is to explain the outcome. Otherwise, the transformation is on x to predict mediators (the argument ends with "m1" or "m" (for level 1 mediator), or "m2" (for level 2 mediator)). The functions corresponds to the functions in the following multilevel additive models, reading as f+subscript+superscript. For example, f01y specifies .
where
For
If for some k, is level 2 variable,
The transformation function can be any function that is differentiable by the function deriv(), or the ifelse function with those functions. The transformation function can also be the ns() and bs() functions for natural and b spline basis.
The function returns a list with transformed and organized data with the following items:
x1 |
the level 1 and 2 transformed predictor variable matrix in explaining y (eg, f01y(x.j) & f10y(xij)). |
lx |
a matrix with ncol(x) rows and three columns. The ith row is for the jth column of x. The first column of the ith row gives the level (1 or 2) of the ith column of x. lx[i,2]:lx[i,3] gives the column numbers of transformed ith x in x1. |
m1y |
the level 1 mediator matrix in explaining y (eg, f20ky(mijk-m.jk) & mijk or binarized mijk for categorical mediators). |
m1 |
a list where the first item identify column numbers of level 1 mediators in m (ie, c(l1,c1)). For every mediator identified by m1[[1]] and by that order, each of the rest item identify the column number(s) in m1y the (transformed) value(s) of the mediator in explaining y. |
m2y |
the level 2 mediator (original or aggregated) matrix in explaining y (eg, f02ky(m.jk) & m.jk). |
m2 |
a list where the first item identify column numbers of level 2 mediators in m (i.e., c(l2,c2)). For every mediator identified by m2[[1]] and by that order, each of the rest item identify the column number(s) in m2y the (transformed) value(s) of the mediator in explaining y. |
xm1 |
the (transformed) level 1 and level 2 predictor(s) in explaining level 1 mediators. |
fm11 |
a list where the first item identify column numbers of level 1 mediators in m. For every mediator identified by fm11[[1]] and by that order, each of the rest item identify the column number(s) in xm1 the (transformed) level 1 predictor(s) in explaining the mediator. |
fm12 |
a list where the first item identify column numbers of level 1 mediators in m. For every mediator identified by fm12[[1]] and by that order, each of the rest item identify the column number(s) in xm1 the (transformed/aggregated) level 2 predictor(s) in explaining the mediator. |
m.2 |
a matrix of level 2 mediators (one row for each group). |
xm2 |
the (transformed/aggregated) level 2 predictor(s) in explaining level 2 mediators (one row for each group). |
fm22 |
a list where the first item identify column numbers of level 2 mediators in m. For every mediator identified by fm22[[1]] and by that order, each of the rest item identify the column number(s) in xm2 the (transformed) level 2 predictor(s) in explaining the mediator. |
x1.der , m2y.der , m1y.der , xm2.der , xm1.der
|
the derivative of x1, m2y, m1y, xm2, and xm1 respectively. |
f01km1.2 |
the first item is f01km1[[1]]. The rest are the column numbers of f01km1[[i]] in xm1. |
f01km2.2 |
the first item is f01km2[[1]]. The rest are the column numbers of f01km2[[i]] in xm2. |
f10km.2 |
the first item is f10km[[1]]. The rest are the column numbers of f10km[[i]] in xm1. |
binx |
the ith item of binx is TRUE if the ith predictor is binary, otherwise is FALSE. |
parameter |
The list of all arguments. |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.211) example1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), level=sim.211$level) data(sim.111) example2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) #f01y=list(1,c("x","log(x^2)")), example3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level)
data(sim.211) example1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), level=sim.211$level) data(sim.111) example2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) #f01y=list(1,c("x","log(x^2)")), example3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level)
This function provides the inference information (estimation, standard deviation, etc.) for the joint and relative effect of a list of mediators.
joint.effect(object,var.list,digits=4,...,alpha=0.05) ## S3 method for class 'joint.effect' print(x,...)
joint.effect(object,var.list,digits=4,...,alpha=0.05) ## S3 method for class 'joint.effect' print(x,...)
object |
an "boot.mlma" object. |
x |
an "joint.effect" object from the joint.effect function. |
var.list |
a list of mediators whose joint effects are of interest. |
... |
arguments to be passed to methods. |
alpha |
the significance level at which to draw the confidence bands. |
digits |
number of digits to be printed. |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.111) data(sim.211) data3<-data.org(x=cbind(ifelse(sim.211$x>1.9,1,0),sim.111$x), m=sim.211$m, f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3.boot<-boot.mlma(y=sim.211$y, data1=data3,boot=2) joint.effect(temp3.boot, var.list=c("m.4"))
data(sim.111) data(sim.211) data3<-data.org(x=cbind(ifelse(sim.211$x>1.9,1,0),sim.111$x), m=sim.211$m, f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3.boot<-boot.mlma(y=sim.211$y, data1=data3,boot=2) joint.effect(temp3.boot, var.list=c("m.4"))
The function transforms the data set and does multilevel mediation analysis. The total, direct, and indirect effects will be returned as the results.
mlma(y, data1=NULL, x=data1$parameter$x, m=data1$parameter$m, yref=NULL, xref=NULL, levelx=data1$parameter$levelx, levely=data1$parameter$levely, l1=data1$parameter$l1,l2=data1$parameter$l2, c1=data1$parameter$c1, #levelx is the level of x c1r=data1$parameter$c1r, c2=data1$parameter$c2, c2r=data1$parameter$c2r,level=data1$parameter$level, weight=rep(1, nrow(data.frame(x))), random="(1|level)", random.m1=NULL,intercept=TRUE, family1=NULL, familym=vector("list",ncol(m)), covariates=NULL, cy1=NULL, cy2=NULL, cm=NULL,joint=NULL, f01y=data1$parameter$f01y,f10y=data1$parameter$f10y, f02ky=data1$parameter$f02ky, f20ky=data1$parameter$f20ky, f01km1=data1$parameter$f01km1,f01km2=data1$parameter$f01km2, f10km=data1$parameter$f10km, data2=NULL, x.new=NULL, m.new=NULL, level.new=level, weight.new=NULL, covariates.new=covariates,cov.mat=FALSE)
mlma(y, data1=NULL, x=data1$parameter$x, m=data1$parameter$m, yref=NULL, xref=NULL, levelx=data1$parameter$levelx, levely=data1$parameter$levely, l1=data1$parameter$l1,l2=data1$parameter$l2, c1=data1$parameter$c1, #levelx is the level of x c1r=data1$parameter$c1r, c2=data1$parameter$c2, c2r=data1$parameter$c2r,level=data1$parameter$level, weight=rep(1, nrow(data.frame(x))), random="(1|level)", random.m1=NULL,intercept=TRUE, family1=NULL, familym=vector("list",ncol(m)), covariates=NULL, cy1=NULL, cy2=NULL, cm=NULL,joint=NULL, f01y=data1$parameter$f01y,f10y=data1$parameter$f10y, f02ky=data1$parameter$f02ky, f20ky=data1$parameter$f20ky, f01km1=data1$parameter$f01km1,f01km2=data1$parameter$f01km2, f10km=data1$parameter$f10km, data2=NULL, x.new=NULL, m.new=NULL, level.new=level, weight.new=NULL, covariates.new=covariates,cov.mat=FALSE)
y |
the vector of the outcome variable. |
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 the transformation functions (f arguments). Otherwise, set data1 as the output from the data.org function and do not include the arguments starting with fs. |
x |
the vector of the predictive variable. |
m |
the mediators. The program will identify the levels and types of each mediator if not specified by l1, l2, c1, or c2. A mediator is identified as categorical if the mediator is a factor, a character, or has only two unque values. |
yref |
the reference group of y if it is binary. By default it will be the first level of y. |
xref |
the reference group of x if it is binary. By default it will be the first level of x. |
levelx |
the level of x (1 or 2). If it is not given, levelx will be decided by x. |
levely |
the level of y (1 or 2). If it is not given, levely will be decided by y. |
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. If not null, 1st item of random.m1 is the list of level 1 mediators, following items are the random item of the same order. 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. |
family1 |
the glm family for the response variable y. If it is null, will be binomial with logic link for binary y and gaussian with identity link for continuous y. |
familym |
a list of length ncol(m), each item gives the glm family for the corresponding column of m. If an item is null, the family will be binomial with logic link for binary m and gaussian with identity link for continuous 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. |
f01y , f10y , f02ky , f20ky , f01km1 , f01km2 , f10km
|
the transformation functions as describe in the function |
x.new , m.new , level.new , weight.new , covariates.new
|
the settings that we want to make inferences on the mediation effects. |
data2 |
The transformed and organized data set from data.org on the set of new x.new and m.new etc.. If the data set has not been organized, leave data2=NULL (by default). |
cov.mat |
If true, save the estimated variances for mediation effects by normal assumption. |
The multilevel mediation is based on the following linear multilevel additive models:
where
For
If for some k, is level 2 variable,
Note that in the models, is a set of l transformation functions on
, with the corresponding linear coefficients vector
.
and l are known for model fitting. l may be different with
of different sub- and super-scripts.
A "mlma" mode list will be returned with the following items:
de1 |
direct effect(s) of level 1 exposure(s). de1 is a matrix of dimension n by nx1, where n is the number of observations, and nx1 is the number of level 1 exposures. |
de2 |
direct effect(s) of level 2 exposure(s). de2 is a matrix of dimension n2 by nx2, where n2 is the number of unique levels, and nx2 is the number of level 2 exposures. |
ade1 |
average direct effect(s) of level 1 exposure(s). ade1 is a vector of length nx1. |
ade2 |
average direct effect(s) of level 2 exposure(s). ade2 is a vector of length nx2. |
te1 |
total effect of each level 1 exposure. te1 is a matrix of dimension n by nx1, where n is the number of observations, and nx1 is the number of level 1 exposures. |
te2 |
total effect of each level 2 exposure. te2 is a matrix of dimension n2 by nx2, where n2 is the number of unique levels, and nx2 is the number of level 2 exposures. |
ate1 |
average total effect(s) of level 1 exposure(s). ate1 is a vector of length nx1. |
ate2 |
average total effect(s) of level 2 exposure(s). ate2 is a vector of length nx2. |
ie1 |
level 1 indirect effect from level 1 exposure(s) to level 1 mediator(s) on the outcome. ie1 is an array of dimension (n,nm1,nx1), where nm1 is the number of level 1 mediators. |
ie2 |
level 2 indirect effect from level 2 exposure(s) to level 2 mediator(s) on the outcome. ie2 is an array of dimension (n2,nm2,nx2), where nm2 is the number of level 2 mediators. |
ie12 |
level 2 indirect effect from level 2 exposure(s) to level 1 mediator(s) on the outcome. ie12 is an array of dimension (n2,nm1,nx2). |
aie1 |
level 1 average indirect effect from level 1 exposure(s) to level 1 mediator(s) on the outcome. aie1 is a matrix of dimension (nm1,nx1). |
aie2 |
level 2 average indirect effect from level 2 exposure(s) to level 2 mediator(s) on the outcome. aie2 is a matrix of dimension (nm2,nx2). |
aie12 |
level 2 average indirect effect from level 2 exposure(s) to level 1 mediator(s) on the outcome. aie12 is a matrix of dimension (nm1,nx2). |
je1 |
joint level 1 indirect effect from level 1 exposure(s) to joint level 1 mediators on the outcome. je1 is an array of dimension (n,nj1,nx1), where nj1 is the number of groups of level 1 mediators. |
je2 |
joint level 2 indirect effect from level 2 exposure(s) to joint level 2 mediators on the outcome. je2 is an array of dimension (n2,nj2,nx2), where nj2 is the number of groups oflevel 2 mediators. |
je12 |
joint level 2 indirect effect from level 2 exposure(s) to joint level 1 mediators on the outcome. je12 is an array of dimension (n2,nj1,nx2). |
aje1 |
average joint level 1 indirect effect from level 1 exposure(s) to joint level 1 mediators on the outcome. aje1 is a matrix of dimension (nj1,nx1). |
aje2 |
average joint level 2 indirect effect from level 2 exposure(s) to joint level 2 mediators on the outcome. je2 is a matrix of dimension (nj2,nx2), where nj2 is the number of groups oflevel 2 mediators. |
aje12 |
average joint level 2 indirect effect from level 2 exposure(s) to joint level 1 mediators on the outcome. je12 is a matrix of dimension (nj1,nx2). |
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_1 , ie1_2 , ie1_3 , ie2_1 , ie2_2 , ie2_3
|
the first, second and third part of the corresponding indirect effects. |
x |
the matrix of the new exposure variable(s) (x.new). |
x.j |
the vector of the aggregated x at the higher level by the order of unique(level.new[!is.na(level.new)]). |
data1 |
The results from data.org on the original data (x, m, etc.). |
data2 |
The results from data.org on the new data (x.new, m.new, etc.). |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
#with a level 1 exposure data(sim.111) data2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) #can also do the above analysis using the following code temp2<-mlma(y=sim.111$y, x=sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) #with a level 2 exposure data(sim.211) data1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1<-mlma(y=sim.211$y, data1) #with both level 1 and 2 exposure data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3<-mlma(y=sim.211$y, data3)
#with a level 1 exposure data(sim.111) data2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) #can also do the above analysis using the following code temp2<-mlma(y=sim.111$y, x=sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) #with a level 2 exposure data(sim.211) data1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1<-mlma(y=sim.211$y, data1) #with both level 1 and 2 exposure data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3<-mlma(y=sim.211$y, data3)
Plot the overall mediation effect or decomposed indirect effect from the selected mediator.
## S3 method for class 'mlma' plot(x,..., var=NULL, cate=FALSE, w2=rep(1,nrow(as.matrix(object$de2))))
## S3 method for class 'mlma' plot(x,..., var=NULL, cate=FALSE, w2=rep(1,nrow(as.matrix(object$de2))))
x |
an "mlma" object. |
... |
arguments to be passed to methods. |
var |
the name of the mediator that is to be plotted. If var is NULL, plot the relative mediation effects of all mediators. |
cate |
an indicator of whether the variable is categorical or not. |
w2 |
the weight for observations at level 2, which should be the same order as unique(level[!is.na(level)]). The default is rep(1,length(object$de2)). |
Plot the relative effects of direct effects and indirect effects of mediators at level 1 (if levelx=1) and level 2 respectively if var=NULL. Otherwise, plot the indirect effect of var, the estimated differential effect of the predictor on var, and the predicted relationship between y and var at individual level and/or (aggregated) group level.
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.211) data1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1<-mlma(y=sim.211$y, data1) plot(temp1) plot(temp1,var="m.1") plot(temp1,var="m.3") #plot(temp1,var="m.4") data(sim.111) data2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) plot(temp2) #plot(temp2,var="m.2") #plot(temp2,var="m.4") plot(temp2,var="m.3") data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3<-mlma(y=sim.211$y, data3) plot(temp3) plot(temp3,var="m.1") #plot(temp3,var="m.4") plot(temp3,var="m.3")
data(sim.211) data1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1<-mlma(y=sim.211$y, data1) plot(temp1) plot(temp1,var="m.1") plot(temp1,var="m.3") #plot(temp1,var="m.4") data(sim.111) data2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) plot(temp2) #plot(temp2,var="m.2") #plot(temp2,var="m.4") plot(temp2,var="m.3") data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3<-mlma(y=sim.211$y, data3) plot(temp3) plot(temp3,var="m.1") #plot(temp3,var="m.4") plot(temp3,var="m.3")
For the mediator identified by var, the function draws the level 1 and/or (aggregated) level 2 indirect effects versus the predictor and the confidence bands at alpha significance level. If var is NULL, draw the relative mediation effects with confidence intervals.
## S3 method for class 'mlma.boot' plot(x,..., var=NULL, alpha=0.05,quant=FALSE, plot.it=x$plot.it)
## S3 method for class 'mlma.boot' plot(x,..., var=NULL, alpha=0.05,quant=FALSE, plot.it=x$plot.it)
x |
an "mlma" object. |
... |
arguments to be passed to methods. |
var |
the name of the mediator that is to be plotted. |
alpha |
the significance level at which to draw the confidence bands. |
quant |
if true, confidence interval is calculated using quantil when plot the relative effects. By default, the CIs are calculated using normal approximation. This argument does nothing for the CIs calculated when var is not null. |
plot.it |
If true, will plot confidence intervals. |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.211) data1<-data.org(x=ifelse(sim.211$x>2.2,1,0), m=sim.211$m, f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1.boot<-boot.mlma(y=sim.211$y, data1=data1,boot=2) plot(temp1.boot) plot(temp1.boot,var="m.1") plot(temp1.boot,var="m.3") #plot(temp1.boot,var="m.4")
data(sim.211) data1<-data.org(x=ifelse(sim.211$x>2.2,1,0), m=sim.211$m, f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1.boot<-boot.mlma(y=sim.211$y, data1=data1,boot=2) plot(temp1.boot) plot(temp1.boot,var="m.1") plot(temp1.boot,var="m.3") #plot(temp1.boot,var="m.4")
print the level 1 and level 2 mediation effecs from the object.
## S3 method for class 'mlma' print(x,...,w2=rep(1,nrow(as.matrix(object$de2))),digits=2)
## S3 method for class 'mlma' print(x,...,w2=rep(1,nrow(as.matrix(object$de2))),digits=2)
x |
an "mlma" object. |
... |
arguments to be passed to methods. |
w2 |
the weight for observations at level 2, which should be the same order as unique(level[!is.na(level)]). The default is rep(1,length(object$de2)). |
digits |
the number of digits to print. |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.111) #with a level 1 exposure data(sim.111) data2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) print(temp2) #with a level 2 exposure data(sim.211) data1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1<-mlma(y=sim.211$y, data1) temp1 #with both level 1 and 2 exposure data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3<-mlma(y=sim.211$y, data3) temp3
data(sim.111) #with a level 1 exposure data(sim.111) data2<-data.org(sim.111$x, m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) print(temp2) #with a level 2 exposure data(sim.211) data1<-data.org(x=sim.211$x, m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"),level=sim.211$level) temp1<-mlma(y=sim.211$y, data1) temp1 #with both level 1 and 2 exposure data3<-data.org(x=cbind(sim.211$x,sim.111$x), m=sim.211$m, f01y=list(1,c("x","log(x^2)")), f02ky=list(1,c("x","x^2")), f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3<-mlma(y=sim.211$y, data3) temp3
print the level 1 and level 2 mediation effecs from the object.
## S3 method for class 'mlma.boot' print(x,...)
## S3 method for class 'mlma.boot' print(x,...)
x |
an "mlma.boot" object. |
... |
other arguments |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.111) data2<-data.org(ifelse(sim.111$x>1.9,1,0), m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2.boot<-boot.mlma(y=sim.111$y, data1=data2,boot=2) print(temp2.boot)
data(sim.111) data2<-data.org(ifelse(sim.111$x>1.9,1,0), m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2.boot<-boot.mlma(y=sim.111$y, data1=data2,boot=2) print(temp2.boot)
A simulated data set, where both predictor and outcome are level 1 variables.
data("sim.111")
data("sim.111")
The data set contains 10 groups, each group has 30 observations. The format is list, where there are four elements:
x: the level 1 continuous predictor.
y: the level 1 continuous outcome.
m: the matrix of mediators, where there are three level 1 mediators, where m.2 and m.3 are continuous, and m.4 is categorical with 3 levels.
level: the group level for each observation.
data(sim.111)
data(sim.111)
A simulated data set, where the predictor is a level 2 and the outcome is a level 1 variable.
data("sim.211")
data("sim.211")
The data set contains 10 groups, each group has 30 observations. The format is list, where there are four elements:
x: the level 1 continuous predictor.
y: the level 1 continuous outcome.
m: the matrix of mediators, where there are one level 2 mediator, m.1, and two level 1 mediators, m.3 and m.4. m.4 is categorical with 3 levels.
level: the group level for each observation.
data(sim.211)
data(sim.211)
This function provides ANOVA tests on the predictors and mediators in the full model and on the predictors for models in explaining each mediators.
## S3 method for class 'mlma' summary(object,...,type="III") ## S3 method for class 'summary.mlma' print(x, ...)
## S3 method for class 'mlma' summary(object,...,type="III") ## S3 method for class 'summary.mlma' print(x, ...)
object |
an "mlma" object. |
x |
a summary.mlma.boot object created initially call to summary.mlma.boot. |
... |
arguments to be passed to methods. |
type |
type of test, "II", "III", 2, or 3. |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.111) data2<-data.org(ifelse(sim.111$x>1.9,1,0), m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) summary(temp2)
data(sim.111) data2<-data.org(ifelse(sim.111$x>1.9,1,0), m=sim.111$m, f10y=list(1,c("x^2","sqrt(x+6)")), f20ky=list(2,c("x","x^3")), f10km=list(matrix(c(2,1),1),"log(x+2)"), level=sim.111$level) temp2<-mlma(y=sim.111$y, data1=data2) summary(temp2)
This function provide summary statistics for all mediation effects.
## S3 method for class 'mlma.boot' summary(object, ..., alpha = 0.05,RE=FALSE,digits=4) ## S3 method for class 'summary.mlma.boot' print(x, ..., digits=x$digits)
## S3 method for class 'mlma.boot' summary(object, ..., alpha = 0.05,RE=FALSE,digits=4) ## S3 method for class 'summary.mlma.boot' print(x, ..., digits=x$digits)
object |
an "mlma" object. |
x |
a summary.mlma.boot object created initially call to summary.mlma.boot. |
... |
arguments to be passed to methods. |
alpha |
the significance level at which to draw the confidence bands. |
RE |
if true, print the relative effects, otherwise show the mediation effects. |
digits |
the number of digits to print. |
Qingzhao Yu ([email protected]), Bin Li ([email protected]).
data(sim.111) data(sim.211) data3<-data.org(x=cbind(ifelse(sim.211$x>1.9,1,0),sim.111$x), m=sim.211$m, f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3.boot<-boot.mlma(y=sim.211$y, data1=data3,boot=2) summary(temp3.boot, digits=2) summary(temp3.boot, RE=TRUE)
data(sim.111) data(sim.211) data3<-data.org(x=cbind(ifelse(sim.211$x>1.9,1,0),sim.111$x), m=sim.211$m, f20ky=list(2,c("x","x^3")), f01km1=list(matrix(c(2,1),1),"sqrt(x)+3"), f01km2=list(matrix(c(1,1),1),c("x^1.2","x^2.3")), level=sim.211$level) temp3.boot<-boot.mlma(y=sim.211$y, data1=data3,boot=2) summary(temp3.boot, digits=2) summary(temp3.boot, RE=TRUE)