Hello,
Any advice or pointers for implementing Sobel's test for mediation in
2-level model setting? For fitting the hierarchical models, I am using
"lme4" but could also revert to "nlme" since it is a
relatively simple
varying intercept model and they yield identical estimates. I apologize for
this is an R question with an embedded statistical question.
I noticed that a previously existing implementation, the function
"sobel.lme," was removed from package "multilevel" - perhaps
the procedure
is inherently problematic? I dug out the code from the package's archive
(pasted below) - it is simple and straightforward, pulls out coefficient
estimates and standard errors from the nlme object. I can follow the same
procedure with "lme4" (even though it uses S4 classes) but am not sure
whether this violates any assumptions made by the Sobel test. Also, I wish
to include a matrix of predictors as opposed to a single vector "pred"
-
trivial to implement but is it kosher?
sobel.lme<-function (pred, med, out, grpid)
{
NEWDAT <- data.frame(pred = pred, med = med, out = out, grpid=grpid)
NEWDAT <- na.exclude(NEWDAT)
model1 <- lme(out ~ pred, random=~1|grpid,data = NEWDAT)
model2 <- lme(out ~ pred + med, random=~1|grpid, data = NEWDAT)
model3 <- lme(med ~ pred, random=~1|grpid, data = NEWDAT)
mod1.out <- summary(model1)$tTable
mod2.out <- summary(model2)$tTable
mod3.out <- summary(model3)$tTable
indir <- mod3.out[2, 1] * mod2.out[3, 1]
effvar <- (mod3.out[2, 1])^2 * (mod2.out[3, 2])^2 + (mod2.out[3,
1])^2 * (mod3.out[2, 2])^2
serr <- sqrt(effvar)
zvalue = indir/serr
out <- list(Model.1 = mod1.out, Model.2 = mod2.out, Model.3 = mod3.out,
Indirect.Effect = indir, SE = serr, z.value = zvalue,
N = nrow(NEWDAT),n.grps=length(unique(NEWDAT$grpid)))
return(out)
}
Any help much appreciated!
Best,
Gavril
--
Gavril Bilev, PhD
Department of Political Science
Brown University
Providence, RI 02906
[[alternative HTML version deleted]]
Hello,
Any advice or pointers for implementing Sobel's test for mediation in
2-level model setting? For fitting the hierarchical models, I am using
"lme4" but could also revert to "nlme" since it is a
relatively simple
varying intercept model and the two yield identical estimates. I apologize
for this is an R question with an embedded statistical question.
I noticed that a previously existing implementation, the function
"sobel.lme," was removed from package "multilevel" - perhaps
the procedure
is inherently problematic? I dug out the code from the package's archive
(pasted below) - it is simple and straightforward, pulls out coefficient
estimates and standard errors from the nlme object. I can follow the same
procedure with "lme4" (even though it uses S4 classes) but am not sure
whether this violates any assumptions made by the Sobel test. Also, I wish
to include a matrix of predictors as opposed to a single vector "pred"
-
trivial to implement but is it kosher?
sobel.lme<-function (pred, med, out, grpid)
{
NEWDAT <- data.frame(pred = pred, med = med, out = out, grpid=grpid)
NEWDAT <- na.exclude(NEWDAT)
model1 <- lme(out ~ pred, random=~1|grpid,data = NEWDAT)
model2 <- lme(out ~ pred + med, random=~1|grpid, data = NEWDAT)
model3 <- lme(med ~ pred, random=~1|grpid, data = NEWDAT)
mod1.out <- summary(model1)$tTable
mod2.out <- summary(model2)$tTable
mod3.out <- summary(model3)$tTable
indir <- mod3.out[2, 1] * mod2.out[3, 1]
effvar <- (mod3.out[2, 1])^2 * (mod2.out[3, 2])^2 + (mod2.out[3,
1])^2 * (mod3.out[2, 2])^2
serr <- sqrt(effvar)
zvalue = indir/serr
out <- list(Model.1 = mod1.out, Model.2 = mod2.out, Model.3 = mod3.out,
Indirect.Effect = indir, SE = serr, z.value = zvalue,
N = nrow(NEWDAT),n.grps=length(unique(NEWDAT$grpid)))
return(out)
}
Any help much appreciated!
Best,
Gavril
--
Gavril Bilev, PhD
Department of Political Science
Brown University
Providence, RI 02906
[[alternative HTML version deleted]]
Hello,
Any advice or pointers for implementing Sobel's test for mediation in
2-level model setting? For fitting the hierarchical models, I am using
"lme4" but could also revert to "nlme" since it is a
relatively simple
varying intercept model and they yield identical estimates. I apologize for
this is an R question with an embedded statistical question.
I noticed that a previously existing implementation, the function
"sobel.lme," was removed from package "multilevel" - perhaps
the procedure
is inherently problematic? I dug out the code from the package's archive
(pasted below) - it is simple and straightforward, pulls out coefficient
estimates and standard errors from the nlme object. I can follow the same
procedure with "lme4" (even though it uses S4 classes) but am not sure
whether this violates any assumptions made by the Sobel test. Also, I wish
to include a matrix of predictors as opposed to a single vector "pred"
-
trivial to implement but is it kosher?
sobel.lme<-function (pred, med, out, grpid)
{
NEWDAT <- data.frame(pred = pred, med = med, out = out, grpid=grpid)
NEWDAT <- na.exclude(NEWDAT)
model1 <- lme(out ~ pred, random=~1|grpid,data = NEWDAT)
model2 <- lme(out ~ pred + med, random=~1|grpid, data = NEWDAT)
model3 <- lme(med ~ pred, random=~1|grpid, data = NEWDAT)
mod1.out <- summary(model1)$tTable
mod2.out <- summary(model2)$tTable
mod3.out <- summary(model3)$tTable
indir <- mod3.out[2, 1] * mod2.out[3, 1]
effvar <- (mod3.out[2, 1])^2 * (mod2.out[3, 2])^2 + (mod2.out[3,
1])^2 * (mod3.out[2, 2])^2
serr <- sqrt(effvar)
zvalue = indir/serr
out <- list(Model.1 = mod1.out, Model.2 = mod2.out, Model.3 = mod3.out,
Indirect.Effect = indir, SE = serr, z.value = zvalue,
N = nrow(NEWDAT),n.grps=length(unique(NEWDAT$grpid)))
return(out)
}
Any help much appreciated!
Best,
Gavril
--
Gavril Bilev, PhD
Department of Political Science
Brown University
Providence, RI 02906
[[alternative HTML version deleted]]
Why posting the same message three times? Ozgur -- View this message in context: http://r.789695.n4.nabble.com/Sobel-s-test-for-mediation-and-lme4-nlme-tp4632586p4632625.html Sent from the R help mailing list archive at Nabble.com.