Repeated Measures

Prof Randi Garcia, SDS 290

2024-11-13

Announcements

  • HW7 due Friday Nov 15 11:59p
  • Office hours
    • Friday 3:00p - 4:00p
  • Where to get HW7 help

Agenda

  1. ANOVA conditions for two-way factorial ANOVA
  2. Levene’s Test
  3. Multiple comparisons
  4. Repeated measures

Two-Way Factorial in R

See Two-Way Factorial code

Try it on the BirdCalcium data

Use the BirdCalcium dataset to:

  1. Test if there are differences in Ca (blood calcium) depending on the bird Sex, Hormone condition, and their interaction using a two-way factorial ANOVA. Interpret the result of your analysis in context.
  2. Check the ANOVA conditions for the residuals (SINZ).
  3. Calculate the effect size (D) for the main effect of Hormone.

Example: Walking Babies

data("WalkingBabies")
ds <- WalkingBabies %>%
  group_by(Group) %>%
  summarize(n = n(),
            mean = mean(Age),
            sd = sd(Age))

ds
# A tibble: 4 × 4
  Group                 n  mean    sd
  <fct>             <int> <dbl> <dbl>
1 exercise control      6  11.4 1.90 
2 final report          6  12.4 0.871
3 special exercises     6  10.1 1.45 
4 weekly report         6  11.6 1.56 

Example: Walking Babies

ds %>%
  summarize(max(sd)/min(sd))
# A tibble: 1 × 1
  `max(sd)/min(sd)`
              <dbl>
1              2.18

So we fail to meet the condition of equal variances? (The S condition)

Levene’s Test

The biggest SD not more than 2 times as large as the smallest SD is only a rule of thumb.

Levene’s test is an ANOVA to test the null hypothesis:

\[H_0 = \sigma^2_1=\sigma^2_2=\sigma^2_3=\sigma^2_4\] \[H_A= not\:all\:variances\:are\:equal\]

Levene’s Test in R

library(car)

leveneTest(Age ~ Group, data = WalkingBabies)
Levene's Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  3  0.3082 0.8191
      20               

Using Levene’s Test for homogeneity of variance, we fail to reject the null hypothesis, that is we fail to find evidence that the S condition is not met, \(F(3, 20)=0.31\), \(p = .819\). We can proceed as if this condition is met.

Levene’s Test for Factorial Data

Let’s try it for the PigFeed data.

data("PigFeed")
leveneTest(WgtGain ~ Antibiotic*B12, data = PigFeed)
Levene's Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  3  1.8089 0.2235
       8               

Using Levene’s Test for homogeneity of variance, we fail to reject the null hypothesis, that is we fail to find evidence that the S condition is not met, \(F(3, 8)=1.81\), \(p = .224\). We can proceed as if this condition is met.

Multiple Tests

data("Leafhoppers")
mod <- lm(Days ~ Diet, data = Leafhoppers)
anova(mod)
Analysis of Variance Table

Response: Days
          Df Sum Sq Mean Sq F value   Pr(>F)   
Diet       3   3.92  1.3067  17.422 0.009248 **
Residuals  4   0.30  0.0750                    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Fisher’s LSD and Bonferroni Correction

library(agricolae)
LSD.test(mod, "Diet", p.adj = "none")$groups
         Days groups
Sucrose   3.8      a
Glucose   2.8      b
Fructose  2.2     bc
Control   2.0      c
LSD.test(mod, "Diet", p.adj = "bonferroni")$groups
         Days groups
Sucrose   3.8      a
Glucose   2.8     ab
Fructose  2.2      b
Control   2.0      b

Tukey’s HSD

mod <- aov(Days ~ Diet, data = Leafhoppers)
TukeyHSD(mod, "Diet")
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = Days ~ Diet, data = Leafhoppers)

$Diet
                 diff        lwr     upr     p adj
Fructose-Control  0.2 -0.9148496 1.31485 0.8805808
Glucose-Control   0.8 -0.3148496 1.91485 0.1337642
Sucrose-Control   1.8  0.6851504 2.91485 0.0095276
Glucose-Fructose  0.6 -0.5148496 1.71485 0.2677272
Sucrose-Fructose  1.6  0.4851504 2.71485 0.0145912
Sucrose-Glucose   1.0 -0.1148496 2.11485 0.0703156

Tuplips

A plant breeder wishes to study the effects of soil drainage and variety of tulip bulbs on flower production. Twelve 3m by 10m experimental sites are available in the test garden–each is a .5m deep trench. You can manipulate soil drainage by changing the ratio of sand to clay for the soil you put in a trench. After talking to your collaborator, you decided that four different levels of soil drainage would suffice. You’ll be testing 15 different types of tulips, and measuring flower production in the spring.