r-Anova_test()错误:变量只有一个级别



我正试图使用ANOVA_test((函数运行一个三元重复测量方差分析。不幸的是,我提示内部因素只有一个级别(请参阅下面的错误代码(,尽管在评估数据帧的结构时,我发现它有多个级别。有人能帮忙吗?

agn.rmanova <- anova_test(
data = df_final, dv = rt, wid = subject,
within = c(sleep, drug, target.type)
)

assertthat_iv_has_enough_levels(.(中出错:可变睡眠只有一个层次。将其从模型中删除

str(df_final)
Classes ‘grouped_df’, ‘tbl_df’, ‘tbl’ and 'data.frame': 321 obs. of  8 variables:
$ id         : num  1 1 1 1 1 1 1 1 1 1 ...
$ supplement : chr  "A" "A" "A" "A" ...
$ condition  : chr  "50" "50" "50" "normal" ...
$ target.type: Factor w/ 4 levels "","negative",..: 2 3 4 2 3 4 2 3 4 2 ...
$ rt         : num  503 647 513 506 587 ...
$ subject    : Factor w/ 18 levels "1","4","7","8",..: 1 1 1 1 1 1 1 1 1 1 ...
$ sleep      : Factor w/ 2 levels "50","normal": 1 1 1 2 2 2 1 1 1 2 ...
$ drug       : Factor w/ 3 levels "A","B","C": 1 1 1 1 1 1 2 2 2 2 ...

我甚至在第一次尝试故障排除时特别指定了级别(见下文(,但都没有成功。

df_final <- summary %>%
filter(id != 2)%>%
filter(id != 6) %>%
mutate(sleep = factor(condition, levels = c("50", "normal")),
drug = factor(supplement, levels = c("A", "B", "C")),
target.type = factor(target.type, levels = c("negative","neutral","positive")),
subject = factor(subject, levels = c("1","4","7","8","14","16","19","20",
"21","23","24","25","27","29","32",
"33","34","35")))

如有任何帮助,我们将不胜感激。谢谢

错误代码

级别

我也遇到了这个问题。我的同事通过将数据帧细分为只包括相关数据来帮助解决了这个问题,我还将非时间变量放在了错误的类别中(应该在内部而不是之间(。不确定是什么解决了这个问题,但我想我会分享,因为这个问题还没有解决!

这是我的原始代码:

rowtotaltr.aov <- anova_test(
data = weedcts_row_cm, dv = cm_RowTotalWeeds.tr, wid = id,
within = c(RowMulch, Date)
)

以下是它之所以有效的原因:

test<-as.data.frame(weedcts_row_cm[,c(1,3:5,12, 13)])
test<-test[,c(1,3:5,12, 13)]
test$Plot<-as.factor(test$Plot) 
t<-anova_test(data = test, dv=cm_RowTotalWeeds.tr, wid=id, between=c(RowMulch), 
within=c(Date))

我也把我的绘图列作为原始代码中的一个因素,这是必要的,因为它只是编号为1-27

相关内容

  • 没有找到相关文章

最新更新