Stat 209 Week 2, Mediating variables numerical example > dim(ssdat) [1] 137 12 > summary(ssdat) grade gender schoolgrades Min. :6.000 Min. :1.000 Min. :1.000 1st Qu.:6.000 1st Qu.:1.000 1st Qu.:4.000 Median :7.000 Median :2.000 Median :6.000 Mean :6.993 Mean :1.526 Mean :5.762 3rd Qu.:8.000 3rd Qu.:2.000 3rd Qu.:8.000 Max. :8.000 Max. :2.000 Max. :9.000 NA's :7 belong depress master Min. :32.00 Min. :10.00 Min. : 7.00 1st Qu.:52.00 1st Qu.:14.00 1st Qu.:40.00 Median :61.00 Median :20.00 Median :54.00 Mean :61.77 Mean :19.68 Mean :50.79 3rd Qu.:72.00 3rd Qu.:25.00 3rd Qu.:61.00 Max. :89.00 Max. :37.00 Max. :80.00 NA's :1 > cor(ssdat, use = "pairwise.complete.obs") schoolgrades belong depress master schoolgrades 1.00000000 0.32461877 -0.23805195 0.25281286 belong 0.32461877 1.00000000 -0.50984362 0.59237433 depress -0.23805195 -0.50984362 1.00000000 -0.46763766 master 0.25281286 0.59237433 -0.46763766 1.00000000 X = Belong; M = mastery; Y= Depress Y on X regression; is M a mediator? > reg1 = lm(depress ~ belong) > summary(reg1) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 35.59112 2.36527 15.047 < 2e-16 *** belong -0.25715 0.03748 -6.861 2.3e-10 *** Residual standard error: 5.386 on 134 degrees of freedom (1 observation deleted due to missingness) Multiple R-squared: 0.2599, Adjusted R-squared: 0.2544 > library(multilevel) > ?sobel > sobel(belong, master, depress) $`Mod1: Y~X` Estimate Std. Error t value Pr(>|t|) (Intercept) 35.5911156 2.36526995 15.047380 1.400184e-30 pred -0.2571453 0.03748198 -6.860505 2.303242e-10 $`Mod2: Y~X+M` Estimate Std. Error t value Pr(>|t|) (Intercept) 36.4998362 2.32596622 15.692333 4.665379e-32 pred -0.1810422 0.04516544 -4.008423 1.013040e-04 med -0.1103938 0.03855989 -2.862917 4.878432e-03 $`Mod3: M~X` Estimate Std. Error t value Pr(>|t|) (Intercept) 8.2316307 5.1621818 1.594603 1.131570e-01 pred 0.6893784 0.0818041 8.427187 4.875161e-14 $Indirect.Effect [1] -0.07610307 $SE [1] 0.02807444 $z.value [1] -2.71076 $N [1] 136 > #master was a better choice than schoolgrades, it shows up -------------------------------------------------------------------- > install.packages("MBESS") > library(MBESS) > mediation(belong, master, depress) $Y.on.X $Y.on.X$Regression.Table Estimate Std. Error t value p(>|t|) Low Conf Limit Up Conf Limit Intercept.Y_X NA 2.36100648 NA NA NA NA c (Regressor) -0.2571453 0.03748198 -6.860505 2.303242e-10 -0.3312781 -0.1830125 $M.on.X $M.on.X$Regression.Table Estimate Std. Error t value p(>|t|) Low Conf Limit Up Conf Limit Intercept.M_X 8.2028494 5.1528768 1.591897 1.137642e-01 -1.9886431 18.3943419 a (Regressor) 0.6893784 0.0818041 8.427187 4.875161e-14 0.5275842 0.8511727 $Y.on.X.and.M $Y.on.X.and.M$Regression.Table Estimate Std. Error t value p(>|t|) Low Conf Limit Up Conf Limit Intercept.Y_XM NA 2.32170030 NA NA NA NA c.prime (Regressor) -0.1810422 0.04516544 -4.008423 0.000101304 -0.2703777 -0.09170670 b (Mediator) -0.1103938 0.03855989 -2.862917 0.004878432 -0.1866637 -0.03412379 $Effect.Sizes Estimate Indirect.Effect -0.07610307 $Bootstrap.Results Estimate CI.Lower_Percentile CI.Upper_Percentile Indirect.Effect -0.07610307 -0.135213084 -0.02573436 CI.Lower_BCa CI.Upper_BCa -0.135215775 -0.025764195