data(AddHealth)
if(require(dplyr) & require(ggplot2)) {
# find means & std.errors by grade
means <- AddHealth |>
group_by(grade) |>
summarise(
n = n(),
dep_se = sd(depression, na.rm = TRUE) / sqrt(n),
anx_se = sd(anxiety, na.rm = TRUE) / sqrt(n),
depression = mean(depression),
anxiety = mean(anxiety) ) |>
relocate(depression, anxiety, .after = grade) |>
print()
# plot means with std.error bars
ggplot(data = means, aes(x = anxiety, y = depression,
color = grade)) +
geom_point(size = 3) +
geom_errorbarh(aes(xmin = anxiety - anx_se,
xmax = anxiety + anx_se)) +
geom_errorbar(aes(ymin = depression - dep_se,
ymax = depression + dep_se)) +
geom_line(aes(group = 1), linewidth = 1.5) +
geom_label(aes(label = grade),
nudge_x = -0.015, nudge_y = 0.02) +
scale_color_discrete(guide = "none") +
theme_bw(base_size = 15)
}
# fit mlm
AH.mod <- lm(cbind(anxiety, depression) ~ grade, data=AddHealth)
car::Anova(AH.mod)
summary(car::Anova(AH.mod))
heplot(AH.mod, hypotheses="grade.L",
fill=c(TRUE, FALSE),
level = 0.4)
Run the code above in your browser using DataLab