Moderated and mediated linear regression

TODO

  • link to regression, regressionDiag

Install required packages

mediation, multilevel, rockchalk

Moderated regression

              Estimate Std. Error   t value     Pr(>|t|)
(Intercept) 65.4617132 1.19492420 54.783151 3.154328e-74
X1c          0.6086687 0.19071197  3.191560 1.912979e-03
Mc          -0.3591561 0.15821174 -2.270097 2.543797e-02
X1c:Mc      -0.0377977 0.02323204 -1.626964 1.070227e-01
plot of chunk moderation
plot of chunk moderation
Values of Mc INSIDE this interval:
        lo         hi 
-62.927712   5.172316 
cause the slope of (b1 + b2*Mc)X1c to be statistically significant
plot of chunk moderation
plot of chunk moderation

Mediation analysis

Simulate data


Call:
lm(formula = Y ~ X + M, data = dfMed)

Residuals:
     Min       1Q   Median       3Q      Max 
-12.4088  -3.5870   0.0208   3.5566  12.6895 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) -1.69901   13.52495  -0.126  0.90029   
X            0.05606    0.12139   0.462  0.64525   
M            0.32752    0.11343   2.887  0.00479 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 5.183 on 97 degrees of freedom
Multiple R-squared:  0.2223,    Adjusted R-squared:  0.2063 
F-statistic: 13.86 on 2 and 97 DF,  p-value: 5.066e-06

Sobel test

$`Mod1: Y~X`
              Estimate Std. Error    t value     Pr(>|t|)
(Intercept) -9.8283102 13.7149511 -0.7166129 4.753174e-01
pred         0.3311861  0.0779808  4.2470206 4.933825e-05

$`Mod2: Y~X+M`
               Estimate Std. Error    t value    Pr(>|t|)
(Intercept) -1.69900547 13.5249478 -0.1256201 0.900292638
pred         0.05606161  0.1213932  0.4618182 0.645245742
med          0.32751615  0.1134279  2.8874394 0.004788962

$`Mod3: M~X`
               Estimate  Std. Error   t value     Pr(>|t|)
(Intercept) -24.8210806 11.78103163 -2.106868 3.768266e-02
pred          0.8400333  0.06698488 12.540641 4.315325e-22

$Indirect.Effect
[1] 0.2751245

$SE
[1] 0.09777623

$z.value
[1] 2.813817

$N
[1] 100

Using package mediation

Also useful for much more complicated situations.

Estimation via quasi-Bayesian approximation


Causal Mediation Analysis 

Quasi-Bayesian Confidence Intervals

               Estimate 95% CI Lower 95% CI Upper p-value    
ACME             0.2731       0.0685         0.47   0.008 ** 
ADE              0.0577      -0.1790         0.29   0.669    
Total Effect     0.3307       0.1782         0.49  <2e-16 ***
Prop. Mediated   0.8303       0.1934         1.82   0.008 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Sample Size Used: 100 


Simulations: 999 
plot of chunk rerRegressionModMed01
plot of chunk rerRegressionModMed01

Estimation via nonparametric bootstrap


Causal Mediation Analysis 

Nonparametric Bootstrap Confidence Intervals with the Percentile Method

               Estimate 95% CI Lower 95% CI Upper p-value    
ACME             0.2751       0.0830         0.45   0.006 ** 
ADE              0.0561      -0.1689         0.32   0.637    
Total Effect     0.3312       0.1331         0.51  <2e-16 ***
Prop. Mediated   0.8307       0.2443         1.87   0.006 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Sample Size Used: 100 


Simulations: 999 

Useful packages

More complex structural equation models are supported by packages sem, OpenMx, and lavaan. More packages can be found in CRAN task view Psychometric Models.

Detach (automatically) loaded packages (if possible)

Get the article source from GitHub

R markdown - markdown - R code - all posts