Get startedGet started for free

The Random Intercept Model

The previous model assumes independence of the repeated measures of weight, and this assumption is highly unlikely. So, now we will move on to consider both some more appropriate graphics and appropriate models.

To begin the more formal analysis of the rat growth data, we will first fit the random intercept model for the same two explanatory variables: Time and Group. Fitting a random intercept model allows the linear regression fit for each rat to differ in intercept from other rats.

We will use the lme4 package which offers efficient tools for fitting linear and generalized linear mixed-effects models. The first argument is the formula object describing both the fixed-effects and random effects part of the model, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. Note the random-effects terms distinguished by vertical bars (|).

This exercise is part of the course

Helsinki Open Data Science

View Course

Exercise instructions

  • Access the lme4 package
  • Fit the random intercept model with the rat ID as the random effect
  • Print out the summary of the model
  • Pay attention to variability (standard deviation) of the rat ID

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# dplyr, tidyr, RATS and RATSL are available

# access library lme4
library(lme4)

# Create a random intercept model
RATS_ref <- lmer(Weight ~ Time + Group + (1 | ID), data = RATSL, REML = FALSE)

# Print the summary of the model

Edit and Run Code