I am currently looking into mixed effect models and I am trying to understand the difference between adding a random effect and adding a covariate to a linear model. Consider this example:

library(lme4)
df <- na.omit(df)
# only look at some states, otherwise to messy
df <- df %>%
filter(State %in% c("SC","CT","CA"))
model1 <- lmer(BirthRate ~ AverageAgeofMother + (1|State), df)

ggplot(df, aes(x = AverageAgeofMother, y = BirthRate, colour = State)) +
geom_point(size=3) +
geom_line(aes(y = predict(model1)),size=1)


As you can see, I am trying to predict the BirthRate using the AverageAgeofMother. I see that there are differences depending on the state (different intercepts).

If I now use model1 to predict new data, does the model account for these differences in state? If so, how is the done on a mathematical level (if possible, please explain it rather simple). Using a very simple linear model gives a different intercept and slope, so I guess something more complex than just averaging the intercepts/slope is going on.

Lastly, can somebody point out to me what the difference is between using a mixed model like I did and using multiple regression (lm(BirthRate ~ AverageAgeofMother + State). If I am not mistaken, in this case I am also considering the effect the State has on the BirthRate

Any insights are appreciated!

Cheers!

• Thank you for your explanation. If I understood it correctly, depending on the State the woman I am looking at, I am simply adding the intercept which is predicted for the corresponding state from my "global" regression equation. Is that in essence correct? In this case State would simply be a matrix of 0 and 1. Jun 10 '21 at 12:12