Topic 9B: Repeated measures analysis with R


These are the solutions for the Topic 9B Computer Lab.

1 Repeated Measures ANOVA

1.1

No solution required.

1.2

No solution required.

1.3

No solution required.

1.4

No solution required.

1.5

No solution required.

1.6

We can use the following code:

## Warning: package 'datarium' was built under R version 4.1.2
## Warning: package 'tidyr' was built under R version 4.1.2
boxplot(selfesteem.long$score ~ selfesteem.long$time,
        col = c("cornflowerblue", "brown2", "darkgoldenrod1"),
        ylab = "Self-esteem score", xlab = "Time-point")

1.7

  1. The dependent (response) variable is score
  2. The independent variable is time

1.8

We can use the following code:

anova.selfesteem <- aov(score ~ time + Error(id), data = selfesteem.long)

summary(anova.selfesteem)
## 
## Error: id
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals  9   4.57  0.5078               
## 
## Error: Within
##           Df Sum Sq Mean Sq F value   Pr(>F)    
## time       2 102.46   51.23   55.47 2.01e-08 ***
## Residuals 18  16.62    0.92                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

1.9

  1. Yes. Since we have we have \(p < .001\), we enough evidence to conclude that there is a statistically significant difference in self-esteem scores across time.
  2. \(d_1 = r - 1 = 3 - 1 = 2\). We could read from the ANOVA output, from the Df column, time row.
  3. \(d_2 = (n - 1)(r - 1) = (10 - 1)(3 - 1) = 9\times 2 = 18\). We could read from the ANOVA output, from the Df column, Residuals row.
  4. There was a significant difference in mean self-esteem score [\(F(2, 18) = 55.47\), \(p < .001\)] across time.

1.10

pairwise.t.test(selfesteem.long$score, selfesteem.long$time, paired = TRUE, 
                p.adjust.method = "bonferroni")
## 
##  Pairwise comparisons using paired t tests 
## 
## data:  selfesteem.long$score and selfesteem.long$time 
## 
##    t1     t2    
## t2 0.0023 -     
## t3 1e-06  0.0027
## 
## P value adjustment method: bonferroni

Based on the output, there was a statistically significant difference in mean self-esteem scores between all pairs of time-points. In particular:

  • There was a statistically significant difference between time-point 1 and time-point 2 (\(p = 0.0023\))
  • There was a statistically significant difference between time-point 1 and time-point 3 (\(p < .001\))
  • There was a statistically significant difference between time-point 2 and time-point 3 (\(p = 0.0027\))

2 Linear Mixed Effects Models

2.1

No solution required.

2.2

No solution required.

2.3

The code and required output is:

lme.selfesteem <- lme(score ~ time, random = ~1|id, data = selfesteem.long)

summary(lme.selfesteem)
##                Value Std.Error DF   t-value      p-value
## (Intercept) 3.140122 0.2801731 18 11.207793 1.502987e-09
## timet2      1.793820 0.3962246 18  4.527281 2.608300e-04
## timet3      4.496220 0.3962246 18 11.347655 1.234335e-09

2.4

  1. Yes, since we have \(p < .001\), we have evidence to suggest that the mean self-esteem score at time-point 1 is significantly different from zero.
  2. The estimated mean self-esteem score at time-point 2 is 3.1401 + 1.7938 = 4.9339
  3. Yes, since we have \(p < .001\), we have evidence to suggest that there is a statistically significant difference in the mean self-esteem score between time-points 1 and 2.
  4. The estimated mean self-esteem score at time-point 3 is 3.1401 + 4.4962 = 7.6363
  5. Yes, since we have \(p < .001\), we have evidence to suggest that there is a statistically significant difference in the mean self-esteem score between time-points 1 and 3.

References


These notes have been prepared by Amanda Shaker. The copyright for the material in these notes resides with the authors named above, with the Department of Mathematics and Statistics and with La Trobe University. Copyright in this work is vested in La Trobe University including all La Trobe University branding and naming. Unless otherwise stated, material within this work is licensed under a Creative Commons Attribution-Non Commercial-Non Derivatives License BY-NC-ND.