探索多层级:班级与学校
在上一个练习中,您使用的简单线性模型没有考虑数据的层级结构。学生在班级中学习,而班级隶属于学校,这意味着同一班级内的学生并非独立。一个解决办法是按层级求平均来折叠数据。然而,如何折叠数据很重要,尤其当组别较小或大小不等时。
在本练习中,您将用三种不同方式聚合数学成绩提升(mathgain)。汇总数据后,您将分别在每个层级上拟合线性模型。
本练习是课程的一部分
R 中的分层与混合效应模型
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Summarize the student data at the classroom level
class_data <-
student_data %>%
group_by(classid, schoolid) %>%
summarize(mathgain_class = mean(mathgain),
mathknow_class = mean(mathknow),
n_class = n(), .groups = "keep")
# Model the math gain with the student-level data
lm(___ ~ ___, data = ___)
# Model the math gain with the classroom-level data
lm(___ ~ ___, data = ___)