Skip to content

Instantly share code, notes, and snippets.

@dsquintana
Last active July 24, 2019 12:45
Show Gist options
  • Save dsquintana/8e49ca4581492ee0232e1944a498ef63 to your computer and use it in GitHub Desktop.
Save dsquintana/8e49ca4581492ee0232e1944a498ef63 to your computer and use it in GitHub Desktop.
> m1 = lm(happy_o ~ 1 + drugcond + emocond,
data = h_dat) # Model 1 with main effects only
> m2 = lm(happy_o ~ 1 + drugcond + emocond +
drugcond:emocond, data = h_dat) # Model with main effects and interaction
> summary(m2) # Summary of model 2 (with same p-value as original ANOVA for the interaction)
Call:
lm(formula = happy_o ~ 1 + drugcond + emocond + drugcond:emocond,
data = h_dat)
Residuals:
Min 1Q Median 3Q Max
-2.66667 -0.80208 0.04545 0.35714 3.04545
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.9545 0.2318 8.434 6.23e-12 ***
drugcond -0.3117 0.3716 -0.839 0.40480
emocond 0.9830 0.3572 2.752 0.00772 **
drugcond:emocond 1.0409 0.5392 1.930 0.05806 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.087 on 63 degrees of freedom
(49 observations deleted due to missingness)
Multiple R-squared: 0.3513, Adjusted R-squared: 0.3204
F-statistic: 11.37 on 3 and 63 DF, p-value: 4.693e-06
> anova(m1, m2) # A comparison of model 1 and model 2 to calculate the F statistic, which is the same as the original ANOVA
Analysis of Variance Table
Model 1: happy_o ~ 1 + drugcond + emocond
Model 2: happy_o ~ 1 + drugcond + emocond + drugcond:emocond
Res.Df RSS Df Sum of Sq F Pr(>F)
1 64 78.843
2 63 74.440 1 4.4031 3.7264 0.05806 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment