1 Assessment

This session is assessed using MCQs (questions highlighted below). The actual MCQs can be found on the BS2004 Blackboard site under Assessments and Feedback/Data analysis MCQs. The deadline is listed there and on the front page of the BS2004 blackboard site. This assessment contributes about 4% of module marks. You will receive feedback on this assessment after the submission deadline.

2 Introduction

The package lme4 contains a dataset sleepstudy. In this study, 18 people (Subject) were deprived of sleep over 9 Days. On day 0, the subjects had their normal amount of sleep. Starting that night they were restricted to 3 hours of sleep per night. Their reaction time was measured each day in milliseconds (Reaction). The study (and we) want to know what effect does days of sleep deprivation have on reaction times. We might expect that as the subjects become more sleep deprived (increasing number of Days), we might see them reaction more slowing (increasing Reaction). You can read the paper here if you wish.

3 Doing the wrong thing first: a general linear model

Lets have a look at what is going on.

ggplot(aes(Days, Reaction), data = sleepstudy) + 
  geom_point() +
  geom_smooth(method = "lm")+
  facet_wrap(~ Subject) +
  xlab("Days of sleep deprivation") + 
  ylab("Reaction time (ms)")

First off run a general linear model (lm) on this data with Reaction as the response variable and Days, Subject and their interaction as predictors.

Blackboard MCQ: Using Anova command from the car package, report the statistics correctly showing if the interaction (Days:Subject) was significant.

Blackboard MCQ: Why is carrying out this general linear model incorrect here?

4 A mixed effect model

Subjects are repeated measured (every day), so this is what is known as a repeated measures design. We will use lme4 package to carry out a mixed effect model to analyse this repeated measures design.

# A repeated measures design analysed by a mixed effect model
library("lme4")
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)

Blackboard MCQ: For every day of sleep deprivation, what change is there in reaction times?

4.1 Getting a p value

In the lecture, we discussed using a reduced model(take out the fixed variable you are interested in) and then comparing it to the first model using anova to obtain a p value for the effect of your fixed effect. Carry this out on this analysis.

fm2 <- lmer(Reaction ~ 1 + (Days | Subject), sleepstudy)

Blackboard MCQ: Using p value based significance testing, does Days have a significant effect on Reaction?

5 Postscript

There is a way of using a linear model to analyse a repeated measures design. You have to use the aov command. This was how I was taught to do it. This is not incorrect, its just that it burns through a lot of degrees of freedom (18 subjects equals 37 parameters (18 subjects x 2 parameters +1) rather than 5 (a and b, look back at lecture)). Its also less forgiving of missing values.

Another interesting point is the difference between the model in the lecture and the one in the practical,

# Mountain as a nuisance random effect
mixed.lmer <- lmer(testScore ~ bodyLength2 + (1|mountainRange), data = dragons)


# A repeated measures design analysed by a mixed effect model (practical)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)

With (1|mountainRange), you are just letting the intercepts vary, that is you are looking at testscore with bodylength as a continous (and therefore fixed) predictor and mountain as a random effect, but no interaction between them.

Whereas (Days|Subject) is allowing the intercepts and the slopes to vary, that is the model is looking at the effects of sleep deprivation (days) on reaction time and allowing this effect to vary between subjects (an interaction).