1

我正在尝试绘制我的跨栏模型的预测。

模型:

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

Predict 函数可以很好地预测值:

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 中的错误:$ 运算符对原子向量无效我曾尝试在模型中仅保留一个变量 (X1),并仅使用 Poisson glm 来测试问题是否出在模型上。但我总是遇到同样的错误。

4

1 回答 1

1

假设您使用hurdle()的是pscl包,则se.fit该方法没有参数predict.hurdle()

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

因此,该函数只返回一个预测值向量。如果您想要预测值的标准误差,您需要使用链接函数规模的预测,计算那里的标准误差(按照predict.glm()但记住您有来自模型的两个部分的贡献!!)和然后应用链接函数的逆函数将所有内容转换回响应的规模。这听起来不简单……

于 2014-02-14T16:48:32.093 回答