我的原始数据集看起来像这样。它来自重复测量设计:
df <- read.table(text = 'participant_nr condition value
01 B 13
01 C 20
01 A 60
01 D 11
01 E 17
02 C 18
02 A 7
02 B 12
02 D 11
02 E 15', header = T)
然后我创建了一个新的子集,其中条件中带有 ,,A" 的所有值都被删除。我还根据条件中的值添加了两个阶乘变量。我使用了以下代码:
library(dplyr)
df_02 <- df %>%
filter(!condition == "A") %>%
mutate(new_factor_01 = case_when(
condition %in% c("B", "C") ~ "low",
condition %in% c("D", "E") ~ "high") %>%
mutate(new_factor_02 = case_when(
condition %in% c("B", "D") ~ "left",
condition %in% c("C", "E") ~ "right"))
然后我尝试运行重复测量方差分析,以测试 2 个新阶乘变量对 ,,value 的影响。作为代码,我使用了以下代码:
#Turn new_factor_01 & new_factor_02 into factors
is.factor(df_02$new_factor_01) #FALSE
is.factor(df_02$new_factor_02) #FALSE
df_factor <- df_02 %>%
convert_as_factor(new_factor_01, new_factor_02)
is.factor(df_factor$new_factor_01) #TRUE
is.factor(df_factor$new_factor_02) #TRUE
res.aov_omnibus <- anova_test(
data = df_factor, dv = value, wid = participant,
within = c(new_factor_01, new_factor_02)
)
但是当我运行方差分析时,我只收到一条非常奇怪的错误消息:
Error: Each row of output must be identified by a unique combination of keys.
Keys are shared for 396 rows:
我不明白这里有什么问题。有人可以向我解释一下它以及如何解决它吗?
提前谢谢您!