Exercise

# Building a lmer model with random effects

In the video, you learned about the county-level birth rate data. Counties exist within states and perhaps states contribute to variability. During these exercises, you'll build a series of mixed-effects models using this data.

In this exercise, you'll build a hierarchical model with a global intercept (fixed-effect) and random-effect for state. You will then look at the `summary()`

of the model and the `plot()`

of the residuals. Like other types of regression analysis, examining residuals can help you see if anything is wrong with the model.

With `lmer()`

, there are two methods for doing this: `y ~ 1 + (1 | randomEffect)`

or the shortcut, `y ~ (1 | randomEffect)`

. Use the shortcut in this exercise so that your answer passes the DataCamp test.

When building mixed-effect models, starting with simple models such as the global intercept model can check to see if problems exist with either the data or code.
A *global intercept* assumes a single intercept can describe all of the variability in the data.
One way to view a global intercept is that you cannot do any better modeling that data than to only model mean without including any other predictor variables.

Instructions 1/3

**undefined XP**

- Fit a
`lmer()`

model to the`countyBirthsData`

data. Include`State`

as a random-effect that predicts`BirthRate`

.