ranova

P-value is not given in summary of repeated measures ANOVA


For the ww data below I need to do a repeat measures anova for each day to check group significance. This is my code below but in my summary I cannot find a p value. What is going wrong?Any other more aprropriate method?

ww<-structure(list(Group = structure(c(2L, 3L, 1L), levels = c("Cycling", 
"OVX", "SHAM"), class = "factor"), `9` = c(19.6166666666667, 
18.9666666666667, 19.4225), `10` = c(21.5916666666667, 19.2916666666667, 
19.7025), `11` = c(22.2666666666667, 19.3666666666667, 19.7225
), `12` = c(22.25, 19.2166666666667, 19.5775), `13` = c(22.4, 
19.8583333333333, 20.1275), `14` = c(23.2, 19.8083333333333, 
20.1325), `15` = c(23.6166666666667, 20.525, 20.29), `16` = c(24.6166666666667, 
21.3416666666667, 21.065), `17` = c(26.3583333333333, 21.5333333333333, 
21.5325), `18` = c(27.025, 21.5583333333333, 21.4375), `19` = c(27.9833333333333, 
21.8666666666667, 21.63), `20` = c(28.7916666666667, 22.0916666666667, 
21.6175), `21` = c(28.975, 22.0416666666667, 21.875)), row.names = c(NA, 
-3L), class = c("tbl_df", "tbl", "data.frame"))

# Load the required libraries
library(tidyverse)

# Convert 'Average Wt' to a factor to indicate groups
ww$Group <- as.factor(ww$Group)

# Reshape data for repeated measures ANOVA
ww_long <- ww %>%
  pivot_longer(cols = -Group, names_to = "Day", values_to = "Weight")

# Perform repeated measures ANOVA
aov_results <- aov(Weight ~ Group + Error(Group/Day), data = ww_long)
summary(aov_results)

Error: Group
      Df Sum Sq Mean Sq
Group  2  132.8   66.42

Error: Group:Day
          Df Sum Sq Mean Sq F value Pr(>F)
Residuals 36  136.9   3.804    

Solution

  • By using Error(Group/Day), where Group/Day expands to Group + Group:Day ("group and day nested within group"), you are (presumably incorrect/unintendedly) including Group in both the fixed effects and the error terms.

    Instead

    aov_results <- aov(Weight ~ Group + Error(Group:Day), data = ww_long)
    summary(aov_results)
    

    will give you p-values, but also a warning that "Error() model is singular". This is because this is not actually a repeated-measures design, although it looks like it, because you don't have multiple subjects/clusters within groups. I think in this case a simple lm(Weight ~ Group, ...) (or possibly Weight ~ Group + Day: trying to fit the interaction model Group*Day will run into the same kinds of identifiability problems (there's only one observation per group/day combination).