
Examples using the supported estimation methods
Source:vignettes/articles/estimation_methods.Rmd
estimation_methods.RmdThe currently supported estimation methods are:
- covariance-based SEM estimated with the lavaan package
- PLS-SEM estimated using cSEM or plssem
- Bayesian SEM estimated using blavaan
Lavaan
Example 1 (lavaan)
library(lavaan)
library(rmedsem)
mod.txt <- "
read ~ math
science ~ read + math
"
mod <- lavaan::sem(mod.txt, data=rmedsem::hsbdemo)
out <- rmedsem(mod, indep="math", med="read", dep="science",
standardized=T, mcreps=5000,
approach = c("bk","zlc"))
print(out)
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'lavaan'
#> Mediation effect: 'math' -> 'read' -> 'science'
#>
#> Sobel Delta Monte-Carlo
#> Indirect effect 0.251 0.251 0.251
#> Std. Err. 0.046 0.046 0.045
#> z-value 5.501 5.446 5.516
#> p-value 3.79e-08 5.15e-08 3.46e-08
#> CI [0.161, 0.340] [0.160, 0.341] [0.163, 0.341]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'math' -> 'read' (X -> M) with B=0.662 and p<0.001
#> STEP 2 - 'read' -> 'science' (M -> Y) with B=0.378 and p<0.001
#> STEP 3 - 'math' -> 'science' (X -> Y) with B=0.380 and p<0.001
#> As STEP 1, STEP 2 and STEP 3 as well as the Sobel's test above
#> are significant the mediation is partial.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Monte-Carlo
#> STEP 1 - 'math' -> 'science' (X -> Y) with B=0.380 and p<0.001
#> As the Monte-Carlo test above is significant, STEP 1 is
#> significant and their coefficients point in same direction,
#> there is complementary mediation (partial mediation).
#>
#> Effect sizes
#> RIT = (Indirect effect / Total effect)
#> (0.251/0.631) = 0.397
#> Meaning that about 40% of the effect of 'math'
#> on 'science' is mediated by 'read'
#> RID = (Indirect effect / Direct effect)
#> (0.251/0.380) = 0.659
#> That is, the mediated effect is about 0.7 times as
#> large as the direct effect of 'math' on 'science'
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.063, v(adj) = 0.061Example 2 (lavaan)
model02 <- "
# measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
# regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
"
mod <- sem(model02, data=lavaan::PoliticalDemocracy)
out <- rmedsem(mod, indep="ind60", med="dem60", dep="dem65",
standardized=T, mcreps=5000,
approach = c("bk","zlc"))
print(out)
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'lavaan'
#> Mediation effect: 'ind60' -> 'dem60' -> 'dem65'
#>
#> Sobel Delta Monte-Carlo
#> Indirect effect 0.409 0.409 0.409
#> Std. Err. 0.096 0.095 0.095
#> z-value 4.282 4.325 4.292
#> p-value 1.85e-05 1.53e-05 1.77e-05
#> CI [0.222, 0.596] [0.224, 0.595] [0.226, 0.596]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'ind60' -> 'dem60' (X -> M) with B=0.448 and p<0.001
#> STEP 2 - 'dem60' -> 'dem65' (M -> Y) with B=0.913 and p<0.001
#> STEP 3 - 'ind60' -> 'dem65' (X -> Y) with B=0.146 and p=0.038
#> As STEP 1, STEP 2 and STEP 3 as well as the Sobel's test above
#> are significant the mediation is partial.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Monte-Carlo
#> STEP 1 - 'ind60' -> 'dem65' (X -> Y) with B=0.146 and p=0.038
#> As the Monte-Carlo test above is significant, STEP 1 is
#> significant and their coefficients point in same direction,
#> there is complementary mediation (partial mediation).
#>
#> Effect sizes
#> RIT = (Indirect effect / Total effect)
#> (0.409/0.555) = 0.738
#> Meaning that about 74% of the effect of 'ind60'
#> on 'dem65' is mediated by 'dem60'
#> RID = (Indirect effect / Direct effect)
#> (0.409/0.146) = 2.811
#> That is, the mediated effect is about 2.8 times as
#> large as the direct effect of 'ind60' on 'dem65'
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.167, v(adj) = 0.158Example 3 (lavaan)
model03 <- "
Attractive =~ face + sexy
Appearance =~ body + appear + attract
Muscle =~ muscle + strength + endur
Weight =~ lweight + calories + cweight
Appearance ~ Attractive + age
Muscle ~ Appearance + Attractive + age
Weight ~ Appearance + Attractive + age
"
mod <- sem(model03, data=rmedsem::workout)
rmedsem(mod, indep="Attractive", med="Appearance", dep="Muscle",
standardized=T, mcreps=5000,
approach = c("bk","zlc"))
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'lavaan'
#> Mediation effect: 'Attractive' -> 'Appearance' -> 'Muscle'
#>
#> Sobel Delta Monte-Carlo
#> Indirect effect 0.065 0.065 0.065
#> Std. Err. 0.033 0.033 0.034
#> z-value 1.975 1.954 1.949
#> p-value 0.0483 0.0507 0.0513
#> CI [0.000, 0.130] [-0.000, 0.131] [0.004, 0.137]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'Attractive' -> 'Appearance' (X -> M) with B=0.158 and p=0.033
#> STEP 2 - 'Appearance' -> 'Muscle' (M -> Y) with B=0.414 and p<0.001
#> STEP 3 - 'Attractive' -> 'Muscle' (X -> Y) with B=-0.014 and p=0.850
#> As STEP 1, STEP 2 and the Sobel's test above are significant
#> and STEP 3 is not significant the mediation is complete.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Monte-Carlo
#> STEP 1 - 'Attractive' -> 'Muscle' (X -> Y) with B=-0.014 and p=0.850
#> As the Monte-Carlo test above is not significant and STEP 1 is
#> not significant there is no effect nonmediation (no mediation).
#>
#> Effect sizes
#> WARNING: Total effect is smaller than indirect effect!
#> Effect sizes should not be interpreted.
#> RIT = (Indirect effect / Total effect)
#> RIT is not reported: total effect 0.052 is too small (< 0.2)
#> RID = (Indirect effect / Direct effect)
#> RID is not reported: direct effect 0.014 is not significant (p = 0.850)
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.004, v(adj) = 0.003
rmedsem(mod, indep="Attractive", med="Appearance", dep="Weight",
standardized=T, mcreps=5000,
approach = c("bk","zlc"))
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'lavaan'
#> Mediation effect: 'Attractive' -> 'Appearance' -> 'Weight'
#>
#> Sobel Delta Monte-Carlo
#> Indirect effect 0.098 0.098 0.098
#> Std. Err. 0.047 0.048 0.048
#> z-value 2.081 2.027 2.032
#> p-value 0.0374 0.0427 0.0422
#> CI [0.006, 0.190] [0.003, 0.193] [0.006, 0.196]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'Attractive' -> 'Appearance' (X -> M) with B=0.158 and p=0.033
#> STEP 2 - 'Appearance' -> 'Weight' (M -> Y) with B=0.619 and p<0.001
#> STEP 3 - 'Attractive' -> 'Weight' (X -> Y) with B=-0.125 and p=0.073
#> As STEP 1, STEP 2 and the Sobel's test above are significant
#> and STEP 3 is not significant the mediation is complete.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Monte-Carlo
#> STEP 1 - 'Attractive' -> 'Weight' (X -> Y) with B=-0.125 and p=0.073
#> As the Monte-Carlo test above is significant and STEP 1 is not
#> significant there is indirect-only mediation (full mediation).
#>
#> Effect sizes
#> WARNING: Total effect is smaller than indirect effect!
#> Effect sizes should not be interpreted.
#> RIT = (Indirect effect / Total effect)
#> RIT is not reported: total effect 0.027 is too small (< 0.2)
#> RID = (Indirect effect / Direct effect)
#> RID is not reported: direct effect 0.125 is not significant (p = 0.073)
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.010, v(adj) = 0.007
rmedsem(mod, indep="age", med="Appearance", dep="Muscle",
standardized=T, mcreps=5000,
approach = c("bk","zlc"))
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'lavaan'
#> Mediation effect: 'age' -> 'Appearance' -> 'Muscle'
#>
#> Sobel Delta Monte-Carlo
#> Indirect effect -0.160 -0.160 -0.160
#> Std. Err. 0.040 0.040 0.040
#> z-value -4.039 -3.956 -3.972
#> p-value 5.37e-05 7.61e-05 7.13e-05
#> CI [-0.238, -0.082] [-0.240, -0.081] [-0.245, -0.087]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'age' -> 'Appearance' (X -> M) with B=-0.387 and p<0.001
#> STEP 2 - 'Appearance' -> 'Muscle' (M -> Y) with B=0.414 and p<0.001
#> STEP 3 - 'age' -> 'Muscle' (X -> Y) with B=-0.147 and p=0.065
#> As STEP 1, STEP 2 and the Sobel's test above are significant
#> and STEP 3 is not significant the mediation is complete.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Monte-Carlo
#> STEP 1 - 'age' -> 'Muscle' (X -> Y) with B=-0.147 and p=0.065
#> As the Monte-Carlo test above is significant and STEP 1 is not
#> significant there is indirect-only mediation (full mediation).
#>
#> Effect sizes
#> RIT = (Indirect effect / Total effect)
#> (0.160/0.307) = 0.521
#> Meaning that about 52% of the effect of 'age'
#> on 'Muscle' is mediated by 'Appearance'
#> RID = (Indirect effect / Direct effect)
#> RID is not reported: direct effect 0.147 is not significant (p = 0.065)
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.026, v(adj) = 0.024
rmedsem(mod, indep="age", med="Appearance", dep="Weight",
standardized=T, mcreps=5000,
approach = c("bk","zlc"))
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'lavaan'
#> Mediation effect: 'age' -> 'Appearance' -> 'Weight'
#>
#> Sobel Delta Monte-Carlo
#> Indirect effect -0.240 -0.240 -0.240
#> Std. Err. 0.045 0.050 0.049
#> z-value -5.287 -4.836 -4.873
#> p-value 1.25e-07 1.33e-06 1.10e-06
#> CI [-0.329, -0.151] [-0.337, -0.143] [-0.346, -0.150]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'age' -> 'Appearance' (X -> M) with B=-0.387 and p<0.001
#> STEP 2 - 'Appearance' -> 'Weight' (M -> Y) with B=0.619 and p<0.001
#> STEP 3 - 'age' -> 'Weight' (X -> Y) with B=0.341 and p<0.001
#> As STEP 1, STEP 2 and STEP 3 as well as the Sobel's test above
#> are significant the mediation is partial.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Monte-Carlo
#> STEP 1 - 'age' -> 'Weight' (X -> Y) with B=0.341 and p<0.001
#> As the Monte-Carlo test above is significant, STEP 1 is
#> significant and their coefficients point in opposite
#> direction, there is competitive mediation (partial mediation).
#>
#> Effect sizes
#> WARNING: Total effect is smaller than indirect effect!
#> Effect sizes should not be interpreted.
#> RIT = (Indirect effect / Total effect)
#> RIT is not reported: total effect 0.101 is too small (< 0.2)
#> RID = (Indirect effect / Direct effect)
#> (0.240/0.341) = 0.704
#> That is, the mediated effect is about 0.7 times as
#> large as the direct effect of 'age' on 'Weight'
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.057, v(adj) = 0.055cSEM
Example 1 (cSEM)
library(cSEM)
library(rmedsem)
mod.txt <- "
# need to use single-item measurement models for PLS-SEM
Read =~ read
Math =~ math
Science =~ science
# the actual path model
Read ~ Math
Science ~ Read + Math
"
mod <- cSEM::csem(.model=mod.txt, .data=rmedsem::hsbdemo,
.resample_method = "bootstrap", .R = 200)
rmedsem(mod, indep="Math", med="Read", dep="Science",
approach = c("bk", "zlc"))
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'cSEM'
#> Mediation effect: 'Math' -> 'Read' -> 'Science'
#>
#> Sobel Delta Bootstrap
#> Indirect effect 0.251 0.251 0.251
#> Std. Err. 0.051 0.049 0.050
#> z-value 4.873 5.069 5.048
#> p-value 1.10e-06 4.01e-07 4.47e-07
#> CI [0.150, 0.351] [0.154, 0.348] [0.152, 0.349]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'Math' -> 'Read' (X -> M) with B=0.662 and p<0.001
#> STEP 2 - 'Read' -> 'Science' (M -> Y) with B=0.378 and p<0.001
#> STEP 3 - 'Math' -> 'Science' (X -> Y) with B=0.380 and p<0.001
#> As STEP 1, STEP 2 and STEP 3 as well as the Sobel's test above
#> are significant the mediation is partial.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Bootstrap
#> STEP 1 - 'Math' -> 'Science' (X -> Y) with B=0.380 and p<0.001
#> As the Bootstrap test above is significant, STEP 1 is
#> significant and their coefficients point in same direction,
#> there is complementary mediation (partial mediation).
#>
#> Effect sizes
#> RIT = (Indirect effect / Total effect)
#> (0.251/0.631) = 0.397
#> Meaning that about 40% of the effect of 'Math'
#> on 'Science' is mediated by 'Read'
#> RID = (Indirect effect / Direct effect)
#> (0.251/0.380) = 0.659
#> That is, the mediated effect is about 0.7 times as
#> large as the direct effect of 'Math' on 'Science'
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.063, v(adj) = 0.060Example 2 (cSEM)
model02 <- "
# measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
# regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
"
mod <- cSEM::csem(.model=model02, .data=lavaan::PoliticalDemocracy,
.resample_method = "bootstrap", .R = 200)
rmedsem(mod, indep="ind60", med="dem60", dep="dem65",
approach = c("bk","zlc"))
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'cSEM'
#> Mediation effect: 'ind60' -> 'dem60' -> 'dem65'
#>
#> Sobel Delta Bootstrap
#> Indirect effect 0.399 0.399 0.399
#> Std. Err. 0.098 0.091 0.089
#> z-value 4.062 4.389 4.497
#> p-value 4.86e-05 1.14e-05 6.88e-06
#> CI [0.206, 0.591] [0.221, 0.577] [0.247, 0.584]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'ind60' -> 'dem60' (X -> M) with B=0.439 and p<0.001
#> STEP 2 - 'dem60' -> 'dem65' (M -> Y) with B=0.909 and p<0.001
#> STEP 3 - 'ind60' -> 'dem65' (X -> Y) with B=0.159 and p=0.009
#> As STEP 1, STEP 2 and STEP 3 as well as the Sobel's test above
#> are significant the mediation is partial.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Bootstrap
#> STEP 1 - 'ind60' -> 'dem65' (X -> Y) with B=0.159 and p=0.009
#> As the Bootstrap test above is significant, STEP 1 is
#> significant and their coefficients point in same direction,
#> there is complementary mediation (partial mediation).
#>
#> Effect sizes
#> RIT = (Indirect effect / Total effect)
#> (0.399/0.557) = 0.715
#> Meaning that about 72% of the effect of 'ind60'
#> on 'dem65' is mediated by 'dem60'
#> RID = (Indirect effect / Direct effect)
#> (0.399/0.159) = 2.514
#> That is, the mediated effect is about 2.5 times as
#> large as the direct effect of 'ind60' on 'dem65'
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.159, v(adj) = 0.149Example 3 (cSEM)
model03 <- "
Attractive =~ face + sexy
Appearance =~ body + appear + attract
Muscle =~ muscle + strength + endur
Weight =~ lweight + calories + cweight
Age =~ age ## need single-indicator LV for cSEM
Appearance ~ Attractive + Age
Muscle ~ Appearance + Attractive + Age
Weight ~ Appearance + Attractive + Age
"
mod <- cSEM::csem(.model=model03, .data=na.omit(rmedsem::workout),
.resample_method = "bootstrap", .R = 200)
rmedsem(mod, indep="Attractive", med="Appearance", dep="Muscle",
approach = c("bk","zlc"))
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'cSEM'
#> Mediation effect: 'Attractive' -> 'Appearance' -> 'Muscle'
#>
#> Sobel Delta Bootstrap
#> Indirect effect 0.112 0.112 0.112
#> Std. Err. 0.041 0.041 0.043
#> z-value 2.713 2.766 2.640
#> p-value 0.00667 0.00568 0.00829
#> CI [0.031, 0.194] [0.033, 0.192] [0.044, 0.209]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'Attractive' -> 'Appearance' (X -> M) with B=0.236 and p=0.002
#> STEP 2 - 'Appearance' -> 'Muscle' (M -> Y) with B=0.475 and p<0.001
#> STEP 3 - 'Attractive' -> 'Muscle' (X -> Y) with B=-0.010 and p=0.898
#> As STEP 1, STEP 2 and the Sobel's test above are significant
#> and STEP 3 is not significant the mediation is complete.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Bootstrap
#> STEP 1 - 'Attractive' -> 'Muscle' (X -> Y) with B=-0.010 and p=0.898
#> As the Bootstrap test above is significant and STEP 1 is not
#> significant there is indirect-only mediation (full mediation).
#>
#> Effect sizes
#> WARNING: Total effect is smaller than indirect effect!
#> Effect sizes should not be interpreted.
#> RIT = (Indirect effect / Total effect)
#> RIT is not reported: total effect 0.102 is too small (< 0.2)
#> RID = (Indirect effect / Direct effect)
#> RID is not reported: direct effect 0.010 is not significant (p = 0.898)
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.013, v(adj) = 0.011plssem
Models estimated with plssem (PLS-SEM and
consistent PLSc-SEM, also with interaction terms and ordinal indicators)
must be fitted with bootstrap = TRUE. The indirect effect
is tested with the Sobel, Delta and bootstrap methods, where the
bootstrap test uses the bootstrap samples of plssem. The number of
bootstrap samples is set with boot.R, and
boot.iseed makes the results reproducible.
Example 1 (plssem)
library(plssem)
model.pls <- "
OwnLook =~ smv_attr_face + smv_attr_body + smv_sexy
SelfEst =~ ses_satis + ses_qualities + ses_able_todo
MentWell =~ mwb_optimistic + mwb_useful + mwb_energy
SelfEst ~ OwnLook
MentWell ~ OwnLook + SelfEst
"
fit <- pls(model.pls, data = rmedsem::mchoice, bootstrap = TRUE,
boot.R = 500, boot.iseed = 2025)
rmedsem(fit, indep = "OwnLook", med = "SelfEst", dep = "MentWell")
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'plssem'
#> Mediation effect: 'OwnLook' -> 'SelfEst' -> 'MentWell'
#>
#> Sobel Delta Bootstrap
#> Indirect effect 0.316 0.316 0.316
#> Std. Err. 0.031 0.031 0.031
#> z-value 10.280 10.316 10.272
#> p-value <2e-16 <2e-16 <2e-16
#> CI [0.255, 0.376] [0.256, 0.376] [0.260, 0.376]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'OwnLook' -> 'SelfEst' (X -> M) with B=0.578 and p<0.001
#> STEP 2 - 'SelfEst' -> 'MentWell' (M -> Y) with B=0.546 and p<0.001
#> STEP 3 - 'OwnLook' -> 'MentWell' (X -> Y) with B=0.088 and p=0.054
#> As STEP 1, STEP 2 and the Sobel's test above are significant
#> and STEP 3 is not significant the mediation is complete.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Bootstrap
#> STEP 1 - 'OwnLook' -> 'MentWell' (X -> Y) with B=0.088 and p=0.054
#> As the Bootstrap test above is significant and STEP 1 is not
#> significant there is indirect-only mediation (full mediation).
#>
#> Effect sizes
#> RIT = (Indirect effect / Total effect)
#> (0.316/0.404) = 0.781
#> Meaning that about 78% of the effect of 'OwnLook'
#> on 'MentWell' is mediated by 'SelfEst'
#> RID = (Indirect effect / Direct effect)
#> RID is not reported: direct effect 0.088 is not significant (p = 0.054)
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.100, v(adj) = 0.099Example 2 (plssem, mediated moderation)
The interaction term of a latent interaction model can be used as the independent variable:
model.int <- "
OwnLook =~ smv_attr_face + smv_attr_body + smv_sexy
OwnPers =~ smv_kind + smv_caring + smv_understanding +
smv_make_laughh + smv_funny + smv_sociable
SelfEst =~ ses_satis + ses_qualities + ses_able_todo
MentWell =~ mwb_optimistic + mwb_useful + mwb_energy
SelfEst ~ OwnLook + OwnPers + OwnPers:OwnLook
MentWell ~ OwnLook + SelfEst + OwnPers + OwnPers:OwnLook
"
fit.int <- pls(model.int, data = rmedsem::mchoice, bootstrap = TRUE,
boot.R = 500, boot.iseed = 2025)
rmedsem(fit.int, indep = "OwnPers:OwnLook", med = "SelfEst", dep = "MentWell")
#> Significance testing of indirect effect (standardized)
#> Model estimated with package 'plssem'
#> Mediation effect: 'OwnPers:OwnLook' -> 'SelfEst' -> 'MentWell'
#>
#> Sobel Delta Bootstrap
#> Indirect effect -0.052 -0.052 -0.052
#> Std. Err. 0.016 0.016 0.017
#> z-value -3.252 -3.169 -3.120
#> p-value 0.00115 0.00153 0.00181
#> CI [-0.083, -0.021] [-0.084, -0.020] [-0.090, -0.025]
#>
#> Baron and Kenny approach to testing mediation
#> STEP 1 - 'OwnPers:OwnLook' -> 'SelfEst' (X -> M) with B=-0.104 and p<0.001
#> STEP 2 - 'SelfEst' -> 'MentWell' (M -> Y) with B=0.496 and p<0.001
#> STEP 3 - 'OwnPers:OwnLook' -> 'MentWell' (X -> Y) with B=-0.016 and p=0.642
#> As STEP 1, STEP 2 and the Sobel's test above are significant
#> and STEP 3 is not significant the mediation is complete.
#>
#> Zhao, Lynch & Chen's approach to testing mediation
#> Based on p-value estimated using Bootstrap
#> STEP 1 - 'OwnPers:OwnLook' -> 'MentWell' (X -> Y) with B=-0.016 and p=0.642
#> As the Bootstrap test above is significant and STEP 1 is not
#> significant there is indirect-only mediation (full mediation).
#>
#> Effect sizes
#> RIT = (Indirect effect / Total effect)
#> RIT is not reported: total effect 0.068 is too small (< 0.2)
#> RID = (Indirect effect / Direct effect)
#> RID is not reported: direct effect 0.016 is not significant (p = 0.642)
#> Upsilon (v) = Variance in Y explained indirectly by X through M
#> v(unadj) = 0.003, v(adj) = 0.002blavaan
Example 1 (blavaan)
library(blavaan)
library(rmedsem)
mod.txt <- "
read ~ math
science ~ read + math
"
mod <- bsem(mod.txt, data=rmedsem::hsbdemo,
n.chains=3, burnin=500, sample=500,
bcontrol = list(cores = 3))
out <- rmedsem(mod, indep="math", med="read", dep="science",
approach = c("bk","zlc"))
print(out)By default, the credible intervals are equal-tailed intervals.
Highest density intervals (HDI) can be requested with
hdi = TRUE (requires the HDInterval
package):
out.hdi <- rmedsem(mod, indep="math", med="read", dep="science", hdi=TRUE)
summary(out.hdi)
#> Mediation analysis: 'math' -> 'read' -> 'science'
#> Estimated with 'blavaan' (standardized), N = 200
#>
#> Effects (95% HDI):
#> Estimate Std. Err. z-value p-value Lower Upper
#> Indirect (Bayes) 0.251 0.046 5.499 0.000 0.166 0.341
#> Direct 0.376 0.065 0.000 0.237 0.491
#> Total 0.627 0.039 0.546 0.698
#> For Bayesian estimates, 'p-value' is the posterior probability of
#> the opposite sign.
#>
#>
#> Effect sizes:
#> RIT = 0.400
#> RID = 0.666
#> Upsilon = 0.061
#> Upsilon (unadj.) = 0.063Example 2 (blavaan)
model02 <- "
# measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
# regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
"
mod <- bsem(model02, data=lavaan::PoliticalDemocracy, std.lv=T,
meanstructure=T, n.chains=3,
save.lvs=T, burnin=1000, sample=1000, bcontrol = list(cores = 3))
rmedsem(mod, indep="ind60", med="dem60", dep="dem65")