R: Maximal First Differences for Zero-Inflated Models
ziChange
R Documentation
Maximal First Differences for Zero-Inflated Models
Description
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.
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).
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.
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
Author(s)
Dave Armstrong (UW-Milwaukee, Department of Political Science)
Examples
library(pscl)
## 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")
ziChange(fm_zinb, data=bioChemists, typical.dat=typical.bioChem, type="count")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(DAMisc)
Loading required package: car
Loading required package: effects
Attaching package: 'effects'
The following object is masked from 'package:car':
Prestige
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DAMisc/ziChange.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ziChange
> ### Title: Maximal First Differences for Zero-Inflated Models
> ### Aliases: ziChange
>
> ### ** Examples
>
> library(pscl)
Loading required package: MASS
Loading required package: lattice
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.417933027
$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"
>
>
>
>
>
> dev.off()
null device
1
>