我正在使用 rstatix 包进行双向重复测量方差分析。
library(rstatix)
res.aov <- anova_test(data=kolding, dv=count, wid=id, within=treatment)
get_anova_table(res.aov)
这是数据的样子:
id treatment species count
1 K1 biohut Goldsinny Wrasse 0
2 K2 biohut Goldsinny Wrasse 2
3 K3 biohut Goldsinny Wrasse 1
4 K4 biohut Goldsinny Wrasse 1
5 K5 biohut Goldsinny Wrasse 1
6 K6 biohut Goldsinny Wrasse 0
7 K1 biohut Atlantic Cod 0
8 K2 biohut Atlantic Cod 0
9 K3 biohut Atlantic Cod 1
10 K4 biohut Atlantic Cod 1
11 K5 biohut Atlantic Cod 0
...
我不断收到一个传播错误,即每一行输出都必须由唯一的键组合来标识,我不知道该怎么做。
我试过 pivot_wider(),但它不动。
问题是您的
id
变量被不同的个体重复使用——即,对于 goldsinny wrasse 和大西洋鳕鱼,您有 K1
、K2
等。您可以通过 paste()
ing id
和 species
来创建唯一标识符。
library(rstatix)
kolding$unique_id <- paste(kolding$id, kolding$species)
res.aov <- anova_test(data=kolding, dv=count, wid=unique_id, within=treatment)
get_anova_table(res.aov)
ANOVA Table (type III tests)
Effect DFn DFd F p p<.05 ges
1 treatment 1 10 0.45 0.518 0.034
示例数据:
OP的示例数据一开始报错,因为它只包含了
treatment
的一层,所以我又加了一层:
set.seed(13)
kolding <- rbind(
kolding,
transform(
kolding,
treatment = "control",
count = sample(0:2, 11, replace = TRUE)
)
)