I'm trying to build some models using Zero-Inflated Poisson regression using pscl
package and after having manipulated the output object which turns to be zeroinfl
, I find that doing residuals(fm_zip)
is not equal to fm_zip$residuals
.
The following is an example of what I'm talking about:
library("pscl")
data("bioChemists", package = "pscl")
fm_zip <- zeroinfl(art ~ . | 1, data = bioChemists)
names(fm_zip)
fm_zip$residuals
residuals(fm_zip)
all.equal(fm_zip$residuals,residuals(fm_zip))
qplot(fm_zip$residuals,residuals(fm_zip))
As you might realize, the results are not equal. I would say that both ways are equivalent but it seems like they're not. Could you explain me what is wrong with this? According to residuals R help, those two alternatives are supposed to return the difference (observed - fitted)
. By contrast, I did the same with a plain vanilla linear regression and they are equal.
My R version is:
sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)...
and the package verion is pscl_1.04.4
Any help is appreciated.
To get equal result you should set
type
toresponse
( pearson by default)From the
?residuals.zeroinfl
:The
perason
variance is defined as:EDIT Don't hesitate to read the code behind, it is generally a source of learning and you can also avoid many confusions. To get the code behind the
S3 method
residuals.zeroinfl
, you can use something like this :