0

I am trying to run a repeated measures ANOVA on a dataset and I keep getting the following error:

Error in `spread()`:
! Each row of output must be identified by a unique combination of keys.
ℹ Keys are shared for 12 rows
• 7, 9, 11
• 8, 10, 12
• 1, 3, 5
• 2, 4, 6

I've constructed a minimal mock dataset which reproduces the error that I am experiencing where "measure" is my dependent variable, "sample" indicates the sample number, "drug" is the treatment condition.

library(tidyverse)
library(rstatix)

time<-c("pre", "pre", "pre", "pre", "1h", "1h", "1h", "1h", "24h", "24h", "24h", "24h")
measure<-c(3,4,5,6,1,1,1,2,8,7,9,6)
sample<-c(1,2,3,4,1,2,3,4,1,2,3,4)
drug<-c("yes","no","yes","no","yes","no","yes","no","yes","no","yes","no")
seq<-c(1,2,3,4,5,6,7,8,9,10,11,12)
SMN<-data.frame(time,measure,drug,sample, seq)

SMN$sample<-as.factor(SMN$sample)
SMN$drug<-as.factor(SMN$drug)
SMN$time<-as.factor(SMN$time)
SMN$seq<-as.factor(SMN$seq)

one.way2 <- SMN %>%
  #group_by(time) %>%
  anova_test(dv = measure, wid = sample, within = drug) %>%
  get_anova_table()

I keep getting the error above and I am not sure why. I have tried several iterations of this code. I've also tried to use the base R aov() function with no luck.

In this similar example the respondent suggests using a unique identifier, however isn't the point of the ID variable that the IDs of each sample are carried through each of the timepoints?

When I swap "sample" to "seq" as below:

one.way2 <- SMN %>%
  #group_by(time) %>%
  anova_test(dv = measure, wid = sample, within = drug) %>%
  get_anova_table()

I get the following error:

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

I suspect I am not understanding something about how to input data into an ANOVA in R. Your help is appreciated!

nlojek
  • 1

0 Answers0