首页 文章

跨栏模型标准误差预测 - 错误“$运算符对原子向量无效”

提问于
浏览
0

我试图绘制我的Hurdle模型的预测 .

模型:

mm14C<-hurdle(littersize1~X1+mont|mont,dist = "poisson", zero = "bin", data=data,weights=w)

预测函数适用于预测值:

stripchart(data$X1~data$littersize1,ylab="Litter size",font.lab = 1, family = "serif", cex.lab = 1.5, method="jitter",xlim=c(-1.9,1),col="grey", xlab="Connectivity to Males",jitter=0.3, pch=18)
xk<-seq(from=-2, to=2, length=1000)
x2<-seq(from=1, to=12, length=1000)
my.data<-data.frame(X1=xk, mont=x2)
pred.vals<-predict(mm14C, newdata=my.data,weights = w, type="response") 
lines(pred.vals~xk,lty=1, col="black

然而,它给SE的预测带来了误差

G<-predict(mm14C, newdata=my.data, se.fit=TRUE,weights = w, type="response")
f<-G$fit 
fseup<-(G$fit +1.96*G$se.fit)
fselow<-(G$fit-1.96*G$se.fit)
lines(fseup~xk-1,lty=3, col="green")
lines(fselow~xk,lty=3, col="green")

错误:G $ fit中的错误:$ operator对原子向量无效我试过在模型中只留下一个变量(X1),只做一个Poisson glm来测试问题是否是模型 . 但我总是得到同样的错误 .

1 回答

  • 0

    假设您正在使用 pscl 包中的 hurdle() ,那么 predict.hurdle() 方法没有 se.fit 参数:

    ## S3 method for class 'hurdle'
     predict(object, newdata,
       type = c("response", "prob", "count", "zero"), na.action = na.pass,
       at = NULL, ...)
    

    因此,该函数仅返回预测值的向量 . 如果你想要预测值的标准误差,你需要对链接函数的规模进行预测,计算那里的标准误差(根据 predict.glm() 做,但记住你有来自模型的两个部分的贡献!!)然后应用链接函数的反转将所有内容转换回响应的比例 . 这听起来并不重要......

相关问题