Get startedGet started for free

Slippery slopes: Random Intercept and Random Slope Model

Now we can move on to fit the random intercept and random slope model to the rat growth data. Fitting a random intercept and random slope model allows the linear regression fits for each individual to differ in intercept but also in slope. This way it is possible to account for the individual differences in the rats' growth profiles, but also the effect of time.

This exercise is part of the course

Helsinki Open Data Science

View Course

Exercise instructions

  • Fit the random intercept and slope model with Time and ID as the random effects
  • Print the summary of the model
  • Compute the analysis of variance tables of the models RATS_ref and RATS_ref1
  • Pay attention to the chi-squared statistics and p-value of the likelihood ratio test between RATS_ref1 and RATS_ref. The lower the value the better the fit against the comparison model.

Hands-on interactive exercise

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

# dplyr, tidyr, lme4, ggplot2, RATS and RATSL are available

# create a random intercept and random slope model
RATS_ref1 <- lmer(Weight ~ Time + Group + (Time | ID), data = RATSL, REML = FALSE)

# print a summary of the model


# perform an ANOVA test on the two models
anova(RATS_ref1, RATS_ref)
Edit and Run Code