Introduction

Overview

Mixed models are an extremely useful modeling tool for situations in which there is some dependency among observations in the data, where the correlation typically arises from the observations being clustered in some way. For example, it is quite common to have data in which we have repeated measurements for the units of observation, or in which the units of observation are otherwise grouped together (e.g. students within school, cities within geographic region). While there are different ways to approach such a situation, mixed models are a very common and powerful tool to do so. In addition, they have ties to other statistical approaches that further expand their applicability.

Goals

This document serves as the basis for a workshop. The goal of the workshop is primarily to provide a sense of when one would use mixed models and a variety of standard techniques to implement them. Additionally, we’ll have exercises to practice.

Prerequisites

The document is for the most part very applied in nature, and only assumes a basic understanding of standard regression models. Use of R for regression modeling is also assumed, though there will be some review. Demonstrations will be done almost entirely with the lme4 package.

Note the following color coding used in this document:

  • emphasis
  • package
  • function
  • object/class
  • link

Initial Steps

  1. Download the zip file at https://github.com/m-clark/mixed-models-with-R/raw/master/mem_workshop.zip. Be mindful of where you put it.
  2. Unzip it. Be mindful of where you put the resulting folder.
  3. Open RStudio.
  4. File/Open Project and click on the blue icon (mem_workshop.Rproj) in the folder you just created.
  5. File/Open Click on the ReadMe file and do what it says.

Key packages

To run the code in this document you’ll really only need the following:

  • lme4
  • tidyverse (for data processing)
  • merTools (optional)
  • modelr (optional)
  • nlme (part of base R, no need for install)