Exercise

# Random-effect intercepts

Linear models in R estimate *fixed-effect* parameters.
These parameters are considered to be *fixed*, or non-random values.
In contrast, *random-effect* parameters assume data share a common error distribution.
These parameters are considered to be *random* values drawn from a common error distribution.
For situations with small amounts of data or outliers, random-effect models can produce different estimates.

The `lme4`

package fits mixed-effect models (models with both fixed- and random-effects) with `lmer()`

.
`lmer()`

uses formula, similar to `lm()`

.
But, random-effect intercepts use special syntax: `lmer(y ~ x + (1|randomEffect), data = myData)`

.

After fitting the model and examining the results, extract and plot the results.
We provide this code because it uses advanced data wrangling.
This data wrangling is required because random-effects are usually not plotted.
Furthermore, ggplot2 does not include nice plot options for mixed-effect models.
In this plot, notice how the **dashed** lines from random-effect slopes compare to the **solid** lines from the fixed-effect slopes.

Instructions 1/2

**undefined XP**

Use

`lmer()`

from`lme4`

to fit a random-effects intercept model. Use the`data.frame`

`multIntDemo`

to examine how`response`

can be predicted by a fixed-effect slope variable,`x`

, and a random intercept,`group`

.Examine both the default

`summary()`

output and the`tidy`

output. Notice how both differ from a normal linear model. Later, you'll learn about interpreting the results.