我想在R中使用glmmadmb()来拟合零膨胀负二项式随机效应模型。这些模型在使用包中的数据时是可重现的。
尝试1:
om1 <- glmmadmb(SiblingNegotiation~FoodTreatment*SexParent+offset(log(BroodSize)),
random=(1|Nest),
zeroInflation=TRUE,family="nbinom",data=Owls)
给出错误:
Error in process_randformula(formula, random, data = data) :
object 'Nest' not found
尝试2:
om2 <- glmmadmb(SiblingNegotiation~FoodTreatment*SexParent+offset(log(BroodSize)),
random="~1|Nest",
zeroInflation=TRUE,family="nbinom",data=Owls)
给出错误:
Error in `colnames<-`(`*tmp*`, value = character(0)) :
attempt to set 'colnames' on an object with less than two dimensions
如何使用random
参数成功执行此函数调用?
答案 0 :(得分:2)
为了使此模型适合random
参数,请尝试从尝试2代码中删除引号:
om3 <- glmmadmb(SiblingNegotiation~FoodTreatment*SexParent+offset(log(BroodSize)),
random=~1|Nest,
zeroInflation=TRUE,family="nbinom",data=Owls)
或使用as.formula和引号:
om4 <- glmmadmb(SiblingNegotiation~FoodTreatment*SexParent+offset(log(BroodSize)),
random=as.formula("~1|Nest"),
zeroInflation=TRUE,family="nbinom",data=Owls)
这相当于glmmadmb()帮助页面上给出的示例,它不使用random
参数:
om5 <- glmmadmb(SiblingNegotiation~FoodTreatment*SexParent+
(1|Nest)+offset(log(BroodSize)),
zeroInflation=TRUE,family="nbinom",data=Owls)
> identical(om3$fitted, om5$fitted)
[1] TRUE
> identical(om4$fitted, om5$fitted)
[1] TRUE
> identical(om3$fitted, om4$fitted)
[1] TRUE