Get startedGet started for free

Exploring multiple-levels: Classrooms and schools

In the last exercise, the simple linear model you used did not account for the structure of the data. Students learn within classrooms and classrooms exist within schools, which means students within the same classroom are not independent. One solution is to collapse the data by taking a mean for each level. However, the method used to collapse the data can be important, especially for small or unequal-sized groups.

In this exercise, you will aggregate the gains in math scores (mathgain) three different ways. After summarizing the data, you will examine a linear model of the data at each level.

This exercise is part of the course

Hierarchical and Mixed Effects Models in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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 = ___)
Edit and Run Code