Calculates the change in predicted counts or optionally the predicted probability of being in the zero-count group, for maximal discrete changes in all covariates holding all other variables constant at typical values.

ziChange(obj, data, typical.dat = NULL, type = "count")

Arguments

obj

A model object of class zeroinfl.

data

Data frame used to fit object.

typical.dat

Data frame with a single row containing values at which to hold variables constant when calculating first differences. These values will be passed to predict, so factors must take on a single value, but have all possible levels as their levels attribute.

type

Character string of either ‘count’ (to obtain changes in predicted counts) or ‘zero’ (to obtain changes in the predicted probability of membership in the zero group).

Value

A list with the following elements:

diffs

A matrix of calculated first differences

minmax

A matrix of values that were used to calculate the predicted changes

Details

The function calculates the changes in predicted counts, or optionally the predicted probability of being in the zero group, for maximal discrete changes in the covariates. This function works with polynomials specified with the poly function. It also works with multiplicative interactions of the covariates by virtue of the fact that it holds all other variables at typical values. By default, typical values are the median for quantitative variables and the mode for factors. The way the function works with factors is a bit different. The function identifies the two most different levels of the factor and calculates the change in predictions for a change from the level with the smallest prediction to the level with the largest prediction.

Examples

library(pscl)
#> Classes and Methods for R developed in the #> Political Science Computational Laboratory #> Department of Political Science #> Stanford University #> Simon Jackman #> hurdle and zeroinfl functions by Achim Zeileis
## Example from the help file for zeroinfl in the pscl package data("bioChemists", package = "pscl") fm_zinb <- zeroinfl(art ~ fem + mar + kid5 + phd + ment | fem + mar + kid5 + phd + ment, data = bioChemists, dist = "negbin") typical.bioChem <- data.frame( kid5 = 2, mar = factor(1, levels=1:2, labels=levels(bioChemists$mar)) ) ziChange(fm_zinb, data=bioChemists, typical.dat=typical.bioChem, type="zero")
#> $diffs #> min max diff #> fem 0.012775166 2.385863e-02 0.011083463 #> mar 0.002880625 1.277517e-02 0.009894541 #> kid5 0.003668676 2.368444e-02 0.020015766 #> phd 0.013965961 1.209451e-02 -0.001871450 #> ment 0.720383498 2.220446e-16 -0.720383498 #> #> $minmax #> fem mar kid5 phd ment #> typical 1 1 2 3.150 6 #> min 1 2 0 0.755 0 #> max 2 1 3 4.620 77 #> #> attr(,"class") #> [1] "change"
ziChange(fm_zinb, data=bioChemists, typical.dat=typical.bioChem, type="count")
#> $diffs #> min max diff #> fem 1.066398 1.296662 0.230264216 #> mar 1.296662 1.429573 0.132911160 #> kid5 1.756386 1.114116 -0.642270403 #> phd 1.298838 1.295328 -0.003509929 #> ment 1.117480 7.535413 6.417933030 #> #> $minmax #> fem mar kid5 phd ment #> typical 1 1 2 3.150 6 #> min 2 1 0 0.755 0 #> max 1 2 3 4.620 77 #> #> attr(,"class") #> [1] "change"