Learn R Programming

mma (version 1.0-0)

data.org2: Data Organization Considering Joint Mediators

Description

Do a preliminary data analysis to identify potential mediators and covariates. Each variable listed in jointm is forced in the final estimation model as a mediator. Also organize the data into a format that can be directly used for the mediation analysis functions.

Usage

data.org2(x, y, pred, contmed = NULL, binmed = NULL, binref = NULL, 
   catmed = NULL, catref = NULL, jointm = NULL, biny = T, 
   family1 = binomial(link = "logit"), binpred = T, predref = 1, 
   alpha = 0.1, alpha2 = 0.1)

Arguments

x
a data frame contains the predictor, all potential mediators and covariates
y
the vector of outcome variable.
pred
the column number that locates the predictor in x.
contmed
a vector of column numbers that locate the potential continuous mediators in x.
binmed
a vector of column numbers that locate the potential binary mediators in x.
binref
the defined reference groups of the binary potential mediators in binmed.
catmed
a vector of column numbers that locate the potential categorical mediators in x.
catref
the defined reference groups of the categorical potential mediators in catmed.
jointm
a list that identifies the mediators that need to be considered jointly, where the first item indicates the number of groups of mediators to be considered jointly, and each of the following items identifies the column numbers of the mediators in x for eac
biny
if TRUE, the outcome variable is binary. The default value of biny is TRUE.
family1
define the conditional distribution of y given x, and the linkage function that links the mean of y with the system component in generalized linear model. The default value of family1 is binomial(link = "logit"). If y is continuous, family1 can be define
binpred
if TRUE, the predictor is binary. The default value of binpred is TRUE.
predref
if binpred is TRUE, identify the reference group of the binary predictor.
alpha
the significance level at which to test if the potential mediators (identified by contmed, binmed, and catmed) can be used as a covariate or mediator in estimating y when all variables in x are included in the model. The default value is alpha=0.1
alpha2
the significant level at which to test if a potential mediator is related with the predictor. The default value is alpha2=0.1.

Value

  • data.org returns a list with the organized data and identifiers of the potential mediators in the organized data set.
  • xthe organized data frame that include all potential mediators and covariates that should be used to estimate the outcome.
  • dirxthe column number of x that locates the predictor.
  • contmthe column numbers of x that locate the potential continuous mediators.
  • binmwhen the predictor is continuous, binm gives the column numbers of x that locate the potential binary mediators.
  • catmwhen the predictor is binary, catm gives the column numbers of x that locate the potential binary or categorical mediators; when the predictor is continuous, catm gives a list where the first item is the number of potential categorical mediators, and the following items give the column numbers of each binarized categorical mediator in x.
  • jointma list where the first item is the number of groups of joint mediators, and each of the following items identifies the column numbers of the mediators in the newly organized x for each group of joint mediators.

References

Baron, R.M., and Kenny, D.A. (1986). The moderator-mediator variable distinction in social psychological research: conceptual, strategic, and statistical considerations. J. Pers Soc Psychol, 51(6), 1173-1182.

See Also

"data.org" that does not consider joint mediators, which can be added freely in the mediation analysis functions later.

Examples

Run this code
data("weight_behavior")
#binary x
 #binary y
 x=weight_behavior[,2:14]
 y=weight_behavior[,15]
 data.b.b.2<-data.org2(x,y,pred=2,contmed=c(8:10,12:13),binmed=c(7,11),
   binref=c(1,1),catmed=6,catref=1,jointm=list(n=1,j1=c(6,8,10)),predref="M",
   alpha=0.4,alpha2=0.4)
 
 #continuous y
 x=weight_behavior[,2:14]
 y=weight_behavior[,1]
 data.b.c.2<-data.org2(x,y,pred=2,contmed=c(8:10,12:13),binmed=c(7,11),
   binref=c(1,1),catmed=6,catref=1,jointm=list(n=1,j1=8:10),biny=FALSE, 
   family1=gaussian(link="identity"),predref="M",alpha=0.4,alpha2=0.4)
 
#continuous x
 #binary y
 x=weight_behavior[,2:14]
 y=weight_behavior[,15]
 data.c.b.2<-data.org2(x,y,pred=1,contmed=c(8:10,12:13),binmed=c(7,11),
   binref=c(1,1),catmed=6,catref=1,jointm=list(n=2,j1=8:10,j2=c(6,8)),
   binpred=FALSE,alpha=0.4,alpha2=0.4)
 
 #continuous y
 x=weight_behavior[,2:14]
 y=weight_behavior[,1]
 data.c.c.2<-data.org2(x,y,pred=1,contmed=c(8:10,12:13),binmed=c(7,11),
   binref=c(1,1),catmed=6,catref=1,jointm=list(n=2,j1=8:10,j2=c(6,8)),
   binpred=FALSE,family1=gaussian(link="identity"),alpha=0.4,alpha2=0.4)

Run the code above in your browser using DataLab