[英]Interpreting 95% CI for model estimated difference between two level factor in linear mixed-effects model
[英]Factor/level error in mixed model
我在類似於此數據的某事上運行混合模型:
df<-data.frame(stage=c("a","a","a","a","b","b","b","b","c","c","c","c"),
nematode=c("fn","fn","bn","bn","fn","fn","bn","bn","fn","fn","bn","bn"),
id2=c(1,2,3,4,1,2,3,4,1,2,3,4),
value=c(1,0,0,2,3,1,1,2,0,0,0,2))
我要擬合的模型是:
stage.id <- function(x) round(summary(glmer(value ~ stage + (1 | id2),family="poisson", data = x))$coefficients[2, c(1, 2, 4)], 3)
models.id0 <- ddply(tree2, .(stage, nematode), stage.id)
但是,運行此命令時,我不斷收到錯誤消息:
contrasts<-
誤差contrasts<-
(*tmp*
,value = contr.funs [1 + isOF [nn]]):對比只能應用於具有2個或更多水平的因子
鑒於我對每個因子(df $ stage和df $ nematode)都使用了nlevels()命令,它們分別為3和2,這對我來說沒有意義。 任何感覺可能會出錯嗎?
您已經將stage
作為模型中的固定效果,但是您正在嘗試針對stage
和nematode
每種組合( ddply(tree2, .(stage, nematode), ...)
)擬合模型。 因此,在數據的每個塊中,只有一個stage
值,這會導致錯誤。
你可以:
nematode
值,即ddply(tree2,.(nematode), ...)
stage
移出模型,即擬合模型value ~ 1 + (1 | id2)
根據您的評論(“我的目標是比較每種線蟲的階段。也就是說,對於每種線蟲(例如bn
),階段都不同”),您想要前一種解決方案(僅適用於nematode
值)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.