Repeated measures anova in R studio error

80 Views Asked by At

everybody! I have a data in the following format

df <- data.frame(id  = c(1, 1, 2, 2), 
            time = c("pre", "post", "pre", "post"),
            type = rep(c("ctrl", "exp"), each =2),
            values = c(61.39881, 49.01473, 31.69452, 32.19900))

And I am not able to run an Sphericity test for my ANOVA repeated measures analysis with the following code

library(rstatix) res.aov <- anova_test(data = df, dv = values, wid = id, within = c(type, time))

The error I get is Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases But I have no NA and a total of 848 subjects

Can someone help me, please? Thanks!

1

There are 1 best solutions below

1
William Wong On

I believe the type variable should be a between-sample variable rather than within-sample. Unless you get the sample individual for both the control and experimental intervention.

Therefore, you should do:

res.aov <- anova_test(data = df, dv = values, wid = id, within = time,  between = type)

If you really perform both interventions to the same individual, then it should not get you an error:

df2 <- rbind(df, df) %>%
  rowwise() %>%
  mutate(values = values + rnorm(1)) %>%
  ungroup() %>%
  mutate(id = c(1, 1, 1, 1, 2, 2, 2, 2))
res.aov <- anova_test(data = df2, dv = values, wid = id, within = c(type, time))