This repository contains simple examples of fitting random effect models in R. I assume basic familiarity with R, and mixed effect models. This mainly focuses on the tools. These examples were shown in class in SAS. The mixed.R
file aims to replicate many of the SAS results. I included 3 examples:
- One-Way Random Effect CRD
- RCBD with random block
- Split-Plot design with RCBD on whole plots
This is how to fit random models in R, it offers a function called lmer
which functions very similarly to lm
in base R.
This will modify the behavior of R, so that the anova function returns p-values. lme4 by default does not return "p-values" and the reason for this is well documented. After installing the package, you can read about this by running help("pvalues")
This replicates a lot of the functionality of the lsmeans
statement, i.e. comparisons of marginal means between different groups.
- Click the green "Clone or download" -> Download zip. Or clone the respository if you have git installed.
- Download the appropriate libraries above with the command
install.packages(...)
- Open
mixed.R
and read through the comments as you run the code. Note, some assignment (variable <- expression
) commands are wrapped with parentheses just to show you the output when you run it.
This example should give you a good start. If you need more detail in one particula area, here are some places to start.
- Vignettes for emmeans - I suggest starting with "basics" and "comparisons". These are basically mini tutorials that give you an overview of the packages
- Bodo Winter Tutorial - Great conceptual intro to mixed effects
- The definitive overview of lme4 - details of the package and a high level overview. Can be somewhat technical, but the first few sections are worth reading when first starting
- Lecture Notes from Professor Ané - previous course notes have some great R examples