Skip to content

Commit

Permalink
Updates "random effect" language.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkshaw committed Nov 14, 2024
1 parent 72ffdd1 commit d410ede
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ _bookdown_files/
.RData
.Ruserdata
.DS_Store
data/mathmot*
10 changes: 5 additions & 5 deletions 04-module-4.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ The intercepts and slopes vary widely! For example, school 4 has an intercept ar

### Fixed vs Random Effects

Multilevel models have two main ingredients: fixed and random effects. For our purposes of executing and interpreting MLMs, a fixed effect is an average effect across all clusters and a random effect is a variance that describes how much an effect differs across clusters. Generally, fixed effects in MLMs capture the mean of an effect and the random effect captures the variance of an effect. For example, we might have a fixed effect for the intercept that describes average math achievement across all schools. Then we have a random effect that describes how intercepts for math achievement vary across schools. Together, the fixed and random effect describe math achievement scores across schools.
Multilevel models have two main ingredients: fixed and random effects. For our purposes of executing and interpreting MLMs, a fixed effect is an average effect across all clusters and a random effect describes how an effect for a given cluster differs from the average. We are usually interested less in individual random effects, and more in the random effects variances that describe how effects vary across all clusters. For example, we might have a fixed effect for the intercept that describes average math achievement across all schools. Then we have a random effect variance that describes how intercepts for math achievement vary across schools. Together, the fixed effect and random effect variance describe math achievement scores across schools.

### The Null Model

In the simplest MLM we can run, we let intercepts vary between clusters by estimating random effects for the intercepts in addition to a fixed effect. The random effect allows the intercepts to randomly vary about the fixed effect, the grand mean of the intercepts. As a result, this model is called the "random intercept only model," also known as the "null model." For our example, math achievement is our outcome variable, and the equations for the null model look like this:
In the simplest MLM we can run, we let intercepts vary between clusters by estimating random effects for the intercepts in addition to a fixed effect. The random effect allows the intercepts to deviate from the fixed effect, the grand mean of the intercepts. As a result, this model is called the "random intercept only model," also known as the "null model." For our example, math achievement is our outcome variable, and the equations for the null model look like this:

| Level | Equation |
|:-------|:---------|
Expand All @@ -100,13 +100,13 @@ The key output to interpret is:

* Number of parameters
* Estimates of fixed effects
* Estimates of variances, which are the random effects
* Estimates of random effects variances

As indicated in our combined equation, we are estimating three parameters:

1. $\gamma_{00}$: the fixed effect for the intercept;
2. $\tau_0^2$: a random effect for the intercept capturing the variance of schools around the intercept. Each $U_{0j}$ is the residual of a school around the intercept; that is, it describes how the school's mean math achievement at the intercept deviates from the intercept for the entire sample. Every school has a $U_{0j}$, and the variance of all of the $U_{0j}$s is $\tau_0^2$;
3. $\sigma^2$: a random effect capturing the variance of students around their school mean math achievement. Each student has a residual, $R_{ij}$, and the variance of all the $R_{ij}$s is $\sigma^2$.
2. $\tau_0^2$: a variance for the random effects of the intercept, capturing the variance of schools around the intercept. Each $U_{0j}$ is the residual of a school around the intercept; that is, it describes how the school's mean math achievement at the intercept deviates from the intercept for the entire sample. Every school has a $U_{0j}$, and the variance of all of the $U_{0j}$s is $\tau_0^2$;
3. $\sigma^2$: a random effect variance capturing the variance of students around their school mean math achievement. Each student has a residual, $R_{ij}$, and the variance of all the $R_{ij}$s is $\sigma^2$.

We can double-check we've counted parameters correctly using the `logLik` function from the `stats` package.

Expand Down
12 changes: 6 additions & 6 deletions 05-module-5.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ We'll be estimating four parameters:

1. $\gamma_{00}$: the fixed effect for the intercept, controlling for `ses`;
2. $\gamma_{10}$: the fixed effect for the slope of `ses`;
3. $\tau_0^2$: a random effect for the intercept capturing the variance of schools around the intercept, controlling for `ses`;
4. $\sigma^2$: a random effect capturing the variance of students around their school mean math achievement, controlling for `ses`.
3. $\tau_0^2$: a random effect variance for the intercept capturing the variance of schools around the intercept, controlling for `ses`;
4. $\sigma^2$: a random effect variance capturing the variance of students around their school mean math achievement, controlling for `ses`.

Notice that the parameters are now conditional on `ses`. The intercept is no longer interpreted as the intercept across all schools; it's the intercept across all schools *conditional on `ses` being equal to 0*, or at the mean `ses` level for the sample given that `ses` is z-scored in these data. Additionally, note that there is no $U_j$ term associated with the coefficient for `ses`; that's because we're only adding a fixed effect for `ses` right now. This implies that the relationship between `ses` and math achievement is the same across all schools (i.e., the slope is fixed, not randomly varying). We'll look at adding random slope effects in the next chapter. For now, let's run our model.

Expand All @@ -86,7 +86,7 @@ l1 <- sigma(ses_l1)^2

So we reduced about 5.6% of level-1 variance by adding `ses` as a level-1 predictor. Another way of stating this is that we reduced the unexplained within school variance by 5.6%.

Another option is to calculate the conditional ICC, or the proportion of variance explained by clustering after we account for `ses`. Recall from last chapter that the adjusted ICC accounts only for random effects, while the conditional ICC accounts for both random effects and fixed effects. With the null model, the adjusted and conditional ICC values from `performance` are the same because there are no predictors in the model, but with a fixed level-1 predictor in the model, we should reference the conditional ICC.
Another option is to calculate the conditional ICC, or the proportion of variance explained by clustering after we account for `ses`. Recall from last chapter that the adjusted ICC accounts only for random effect variances, while the conditional ICC accounts for both variance of both random effects and fixed effects. With the null model, the adjusted and conditional ICC values from `performance` are the same because there are no predictors in the model, but with a fixed level-1 predictor in the model, we should reference the conditional ICC.

```{r}
performance::icc(ses_l1)
Expand Down Expand Up @@ -148,8 +148,8 @@ We'll be estimating five parameters:
1. $\gamma_{00}$: the fixed effect for the intercept, controlling for `ses` and `public`;
2. $\gamma_{01}$: the fixed effect for the slope of `public` controlling for `ses`
3. $\gamma_{10}$: the fixed effect for the slope of `ses` controlling for `public`;
4. $\tau_0^2$: a random effect for the intercept capturing the variance of schools around the intercept, controlling for `ses` and `public`;
5. $\sigma^2$: a random effect capturing the variance of students around their school mean math achievement, controlling for `ses` and `public`.
4. $\tau_0^2$: a random effect variance for the intercept capturing the variance of schools around the intercept, controlling for `ses` and `public`;
5. $\sigma^2$: a random effect variance capturing the variance of students around their school mean math achievement, controlling for `ses` and `public`.

Notice that the parameters are conditional on both `ses` and on `public` now. Let's run our model.

Expand All @@ -160,7 +160,7 @@ summary(ses_l1_public_l2)

Let's look at our fixed effects, which describes the conditional mean effect of a variable on the outcome, across all schools. Per the intercept, the average math achievement across all private schools (`public` = 0) at mean SES (`ses` = 0) is 57.70. A one-standard-deviation increase in `ses` across all private schools is associated with a 3.87-point increase in math achievement. Public schools at mean `ses` have a -0.14-point decrease on average in math achievement relative to private schools.

From our random effects, the variance term describing how schools vary around the intercept (at mean SES at private schools) is 3.48, and the variance term describing how students vary around their school means is 62.81.
From our random effect variances, the variance term describing how schools vary around the intercept (at mean SES at private schools) is 3.48, and the variance term describing how students vary around their school means is 62.81.

Let's calculate variance reduced at level 1 and level 2 by adding school type as a predictor.

Expand Down
Loading

0 comments on commit d410ede

Please sign in to comment.