我需要使用emmeans来计算营养水平和食物网处理的每个组合的估计边际平均值(即H+ A,H+ G,H+ P,L+ A,L+ G,L+ P)。
然后,我需要定义对比来测试(1)在H处理中G是否与A不同,(2) G在L处理中是否与A不同,以及(3) G是否不同于A,在L和H处理中取平均值。
这就是我所拥有的:
library(emmeans)
library(magrittr)
contmod=emmeans(modlog, specs = ~ NutrientLevel + FoodWeb)
contmod
HA = c(1,0,0,0,0,0)
LA = c(0,1,0,0,0,0)
HG = c(0,0,1,0,0,0)
LG = c(0,0,0,1,0,0)
HP = c(0,0,0,0,1,0)
LP = c(0,0,0,0,0,1)
cont=contrast(contmod, method = list("HG - HA", "LG - LA"))但是,我收到的错误是:
Error in contrast.emmGrid(contmod, method = list("HG - HA", "LG - LA"))
: Nonconforming number of contrast coefficients我不知道如何设置第三个对比度。
以下是我的数据示例:
NutrientLevel ShadeCloth FoodWeb Tank Zoop_Chao1 Phyto#taxa Phyto_Chao1 Block
H N A 15 0 9 9 1
H N A 115 0 8 11 4
H Y G 30 11 14 17 1
H Y G 60 18 12 18 2
H Y P 76 9 10 11 2
H Y P 88 13 8 9.5 3
L N A 16 0 15 15 1
L N A 24 0 8 8 2
L N G 10 8 17 17 1
L N G 82 10 18 20 3发布于 2021-10-13 17:42:18
这不是emmeans定义对比的方式。您还提供了一个字符串,而不是您创建的变量。
fit <- lm(mpg ~ factor(cyl), data = mtcars)
means <- emmeans(fit, specs = ~ cyl)
contr <- list("6 vs 4" = c(1, -1, 0),
"8 vs 4" = c(1, 0, -1))
contrast(means, method = contr)
contrast estimate SE df t.ratio p.value
6 vs 4 6.92 1.56 29 4.441 0.0001
8 vs 4 11.56 1.30 29 8.905 <.0001 https://stackoverflow.com/questions/69559071
复制相似问题