To make a mixed effects model in R with two fixed effects and one random effect, we can use either the lme4
or nlme
package.
Assuming we have a data frame with the response variable y
, and two fixed effects x1
and x2
, and one random effect group
, the model formula for lme4
would be:
main.r76 chars3 lines
Here, (1|group)
specifies a random intercept for each level of group
.
For nlme
, we can use:
main.r82 chars3 lines
Here, random = ~1|group
specifies a random intercept for each level of group
.
Once we have fit our model, we can use various methods to summarize and visualize our results:
main.r355 chars16 lines
gistlibby LogSnag