Session Ready
Exercise

Intercepts

Intercepts are an important part of regression models, including hierarchical models, and allow the modeling of discrete groups. Without other coefficients, a single intercept is the global mean of the data. Similarly, multiple intercepts allow you to estimate the mean for each group as long as other coefficients are not estimated.

During this exercise, you will learn about intercepts and see their relationship to means. You will look at a subset of the school data that only includes student data from the school with the id code of 3. This data has been loaded for you as school_3_data.

Instructions 1/4
undefined XP
  • 1
    • Use a linear model to estimate a global intercept for all student math gains mathgain. Recall that a global intercept is ~ 1 in R.
    • Use mean() to calculate the mean for all student math gains using summarize().
    • 2
      • Try to estimate an intercept for each classroom with the formula mathgain ~ classid using lm()
      • Notice R treats classid as a continuous variable.
    • 3
      • mutate() classid to be a factor.
      • Rerun the model you fit in the previous step.
    • 4
      • Calculate the means for each classroom using group_by(classid)
      • Estimate an intercept for each class using ~ classid - 1 in the lm() formula.