在两因素重复测量方差分析中的误差传播

huangapple go评论99阅读模式
英文:

Spread Error in the two-way repeated measure anova test

问题

我正在使用rstatix包进行双向重复测量的方差分析。以下是代码部分:

  1. library(rstatix)
  2. res.aov <- anova_test(data=kolding, dv=count, wid=id, within=treatment)
  3. get_anova_table(res.aov)

这是数据的样子:

  1. id treatment species count
  2. 1 K1 biohut Goldsinny Wrasse 0
  3. 2 K2 biohut Goldsinny Wrasse 2
  4. 3 K3 biohut Goldsinny Wrasse 1
  5. 4 K4 biohut Goldsinny Wrasse 1
  6. 5 K5 biohut Goldsinny Wrasse 1
  7. 6 K6 biohut Goldsinny Wrasse 0
  8. 7 K1 biohut Atlantic Cod 0
  9. 8 K2 biohut Atlantic Cod 0
  10. 9 K3 biohut Atlantic Cod 1
  11. 10 K4 biohut Atlantic Cod 1
  12. 11 K5 biohut Atlantic Cod 0
  13. ...

我一直在遇到一个“spread”错误,要求输出的每一行必须由唯一的键组合标识,但我不知道该如何处理它。

我尝试使用pivot_wider(),但它没有效果。

英文:

I am working on a two-way repeated measure anova using the rstatix package.

  1. library(rstatix)
  2. res.aov &lt;- anova_test(data=kolding, dv=count, wid=id, within=treatment)
  3. get_anova_table(res.aov)

And here's how the data looks like:

  1. id treatment species count
  2. 1 K1 biohut Goldsinny Wrasse 0
  3. 2 K2 biohut Goldsinny Wrasse 2
  4. 3 K3 biohut Goldsinny Wrasse 1
  5. 4 K4 biohut Goldsinny Wrasse 1
  6. 5 K5 biohut Goldsinny Wrasse 1
  7. 6 K6 biohut Goldsinny Wrasse 0
  8. 7 K1 biohut Atlantic Cod 0
  9. 8 K2 biohut Atlantic Cod 0
  10. 9 K3 biohut Atlantic Cod 1
  11. 10 K4 biohut Atlantic Cod 1
  12. 11 K5 biohut Atlantic Cod 0
  13. ...

I keep getting a spread error that each row of output must be identified by a unique combination of keys, and I don't know how to go about it.

I tried pivot_wider(), but it wouldn't budge.

答案1

得分: 0

问题在于您的id变量用于不同的个体,即金线鳕鱼和大西洋鳕鱼都有K1K2等等。您可以通过使用paste()函数将idspecies合并来创建唯一的标识符。

  1. library(rstatix)
  2. kolding$unique_id <- paste(kolding$id, kolding$species)
  3. res.aov <- anova_test(data=kolding, dv=count, wid=unique_id, within=treatment)
  4. get_anova_table(res.aov)
  1. ANOVA表(III 类型检验)
  2. 效应 DFn DFd F p p<.05 ges
  3. 1 treatment 1 10 0.45 0.518 0.034

示例数据:

原始示例数据出现错误,因为它只包含了一个水平的treatment,所以我添加了另一个水平:

  1. set.seed(13)
  2. kolding <- rbind(
  3. kolding,
  4. transform(
  5. kolding,
  6. treatment = "control",
  7. count = sample(0:2, 11, replace = TRUE)
  8. )
  9. )
英文:

The problem is that your id variable is reused for different individuals — ie, you have K1, K2, etc, for both goldsinny wrasse and Atlantic cod. You can make a unique identifier by paste()ing id and species.

  1. library(rstatix)
  2. kolding$unique_id &lt;- paste(kolding$id, kolding$species)
  3. res.aov &lt;- anova_test(data=kolding, dv=count, wid=unique_id, within=treatment)
  4. get_anova_table(res.aov)
  1. ANOVA Table (type III tests)
  2. Effect DFn DFd F p p&lt;.05 ges
  3. 1 treatment 1 10 0.45 0.518 0.034

Example data:

OP’s sample data initially threw an error because it only includes one level of treatment, so I added another level:

  1. set.seed(13)
  2. kolding &lt;- rbind(
  3. kolding,
  4. transform(
  5. kolding,
  6. treatment = &quot;control&quot;,
  7. count = sample(0:2, 11, replace = TRUE)
  8. )
  9. )

huangapple
  • 本文由 发表于 2023年3月9日 20:26:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定