简体   繁体   中英

Hurdle model standard error prediction - error “$ operator is invalid for atomic vectors”

I am trying to plot the prediction of my Hurdle model.

Model:

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

Predict function works fine for the prediction of the values:

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

However it gives error for the prediction of the 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")

Error: Error in G$fit : $ operator is invalid for atomic vectors I have tried leaving just one variable (X1) in the model, and doing just a Poisson glm to test if the problem was the model. But I always got the same error.

Assuming you are using hurdle() from the pscl package, then there is no se.fit argument for the predict.hurdle() method:

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

As such the function just returns a vector of predicted values. If you want standard errors on the predicted values, you'll need to work with predictions on the scale of the link function, compute the standard errors there (doing as per predict.glm() but remembering you have contributions from two parts of the model!!) and then apply the inverse of the link function to transform everything back onto the scale of the response. This doesn't sound trivial...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM