Skip to content

lioumens/mixed_model_examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Examples of Mixed Models in R

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

Libraries for R

lme4

This is how to fit random models in R, it offers a function called lmer which functions very similarly to lm in base R.

lmerTest

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")

emmeans

This replicates a lot of the functionality of the lsmeans statement, i.e. comparisons of marginal means between different groups.

Getting started

  1. Click the green "Clone or download" -> Download zip. Or clone the respository if you have git installed.
  2. Download the appropriate libraries above with the command install.packages(...)
  3. 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.

Other Resources

This example should give you a good start. If you need more detail in one particula area, here are some places to start.

About

Examples of Mixed Models in R

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages