我首先上传表格。该表包含9行,其中6行是因子,剩下的3行是152个个体(n01,n02,n03)增长率的离散度量。然后指定因素:
`r$feed <- factor (r$feed)`
`r$ph <- factor (r$ph)`
`r$aq <- factor (r$aq)`
`r$ind <- factor (r$ind)`
`r$wc <- factor (r$wc)`
`r$p0<- factor (r$p0)`
接下来,我执行将数据框与我感兴趣的因素融合到新表“ r2”中,并使用na.omit函数删除NA值。
`r2 <- data.table::melt(r,id.vars=c("feed","ph","aq","wc"),
measure=c("n01","n12","n23"),
variable.name="time",value.name="G")`
`r2<-na.omit(r2)`
r2看起来像这样:
data.frame(
G = c(0.184, 0.087, 1.747, 0.11, 0.39, 0.062, 0.08, 0.189, 0.068,
0.262, 0.048, 0.029, 0, 0.229, 0.175),
feed = as.factor(c("HF", "HF", "HF", "HF", "HF", "HF", "HF", "HF",
"HF", "HF", "HF", "HF", "HF", "HF", "HF")),
ph = as.factor(c("8.1", "8.1", "8.1", "8.1", "8.1", "8.1", "8.1",
"8.1", "8.1", "8.1", "8.1", "8.1", "8.1", "8.1",
"8.1")),
aq = as.factor(c("1", "1", "1", "1", "1", "1", "2", "2", "2", "2",
"2", "2", "2", "3", "3")),
wc = as.factor(c("3", "3", "2", "3", "2", "4", "3", "4", "2", "2",
"3", "3", "1", "4", "3")),
time = as.factor(c("n01", "n01", "n01", "n01", "n01", "n01", "n01",
"n01", "n01", "n01", "n01", "n01", "n01", "n01",
"n01"))
)
之后,我设置了固定的方差,然后应用并执行2 gls模型,如下所示:
`vfix3 <- varIdent(form=~1|time*factor(aq))
mix1 <- gls(G ~ ph+feed, weights=vfix3,data=r2)
mix3 <- gls(G ~ ph+feed+wc+time, weights=vfix3,data=r2)`
这些模型似乎可以正常工作,因为我可以得到它们的摘要和方差分析。然后,我尝试使用emmeans包中的lsmeans函数运行事后成对比较,如下所示:
print(lsmeans(mix1, list(pairwise~ph|feed), adjust="tukey"))
lsmeans似乎可以与2因子模型mix1配合使用。但是,在模型mix3上执行lsmeans时,会弹出此错误:
crossprod(x,y)中的错误:需要数字/复杂矩阵/矢量参数
我试图将模型转换为矩阵,但是对于lsmeans
函数来说,它不是正确的对象。我也尝试过不设置因子并将列保留为数字,但会弹出相同的错误。当阅读有关lsmeans函数的信息时,我找不到与之相关的任何crossprod函数。