Learn R Programming

pscl (version 0.5)

predict.zeroinfl: Generate predictions from zero-inflated regression count models

Description

Generate predicted counts from zero-inflated regression models for count data, fit with the zeroinfl function, producing objects of class zeroinfl.

Usage

## S3 method for class 'zeroinfl':
predict(object, newdata, se.fit = FALSE, conf = 0.95,
              MC = 1000, type = c("response", "prob"),
              na.action = na.pass, ...)

Arguments

object
an object of class zeroinfl
newdata
optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used.
se.fit
logical switch indicating if standard errors on predicted values are to be computed
conf
a proportion, width of confidence intervals computed if se.fit=TRUE, defaults to .95
MC
number of Monte Carlo iterates for computing standard errors and confidence intervals around predicted values
type
the type of prediction required. The default is "response", generating predictions on the scale of the observed counts. Choosing type="prob" generates a matrix of predicted probabilities over the range of counts obser
na.action
function determining what should be done with missing values in newdata. The default is to predict NA.
...
further arguments passed to or from other methods.

Value

  • a list, with components
  • yhata vector of predicted counts
  • mupredictions from the count part of the model, on the scale of the counts
  • phipredicted probabilities from the zero-inflated component of the model, the probability of zero count
  • seif se.fit=T, the standard errors of the predicted counts
  • lower,uppperif se.fit=T, the lower/upper bounds of confidence intervals of content conf
  • probif type="prob", a matrix of predicted probabilities, with each row containing predicted probabilities over the range of counts observed in the data, i.e., ncol(prob) = length(min(y):max(y))

Details

Monte Carlo methods are used to generate standard errors and confidence intervals as follows: MC samples are drawn from a multivariate normal distribution centered on the MLEs of the parameters and variance-covariance matrix equal to the MLE's variance-covariance matrix. With sampled set of parameter values, predicted values are generated. The standard deviation of the predicted values is returned as se.fit along with the lower and upper quantiles corresponding to confidence level conf.

See Also

zeroinfl, predict.glm, predprob.zeroinfl

Examples

Run this code
data(bioChemists)
zip <- zeroinfl(count=art ~ .,
                x = ~ fem + mar + kid5 + phd + ment,
                z = ~ fem + mar + kid5 + phd + ment,
                data=bioChemists,trace=TRUE)

newdata <- expand.grid(list(fem="Men",
                            mar="Married",
                            kid5=1,
                            phd=3.103,
                            ment=0:77))

yhat <- predict(zip,newdata=newdata,
                se.fit=TRUE,MC=2500)

plot(x=newdata$ment,
     y=yhat$yhat,
     xlab="Mentor Articles",
     ylab="Predicted Counts",
     ylim=range(zip$y),
     type="n")
polygon(x=c(newdata$ment,rev(newdata$ment)),
        y=c(yhat$lower,rev(yhat$upper)),
        border=FALSE,
        col=gray(.75))
lines(x=newdata$ment,
      y=yhat$yhat,
      lwd=2)
rug(quantile(bioChemists$ment,c(.05,.50,.95)))
title("Predicted Counts and 95

Run the code above in your browser using DataLab