我先上传表格。该表包含 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 函数。