Is there any difference between model residuals and modelobject residuals in the pscl package?

I am trying to create some models using Poisson's zero multiplication regression using the pscl package, and after I processed the output object, which becomes zeroinfl , I believe that executing residuals(fm_zip) not equal to fm_zip$residuals .

The following is an example of what I'm saying:

 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 know, the results are not equal. I would say that both paths are equivalent, but it seems that this is not so. Could you explain to me what's wrong with that? According to the remnants of R help, these two alternatives should return the difference (observed - fitted) . In contrast, I did the same with a simple linear regression of vanilla, and they are equal.

My version of R:

 sessionInfo() R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)... 

and the package version pscl_1.04.4

Any help is appreciated.

+4
source share
1 answer

To get an equal result, you should set type to response (default is pearson)

  all.equal(fm_zip$residuals,residuals(fm_zip,'response')) [1] TRUE 

From ?residuals.zeroinfl :

The residual method can calculate the raw residuals (observed - established) and Pearson residues (raw residues scaled by the square root of the variance function).

perason deviation perason defined as:

 mu <- predict(fm_zip, type = "count") phi <- predict(fm_zip, type = "zero") theta1 <- switch(fm_zip$dist, poisson = 0, geometric = 1, negbin = 1/object$theta) variance <- fm_zip$fitted.values * (1 + (phi + theta1) * mu) 

EDIT Feel free to read the code behind, it is usually the source of learning, and you can also avoid many confusions. To get the code for the S3 method residuals.zeroinfl , you can use something like this:

 getS3method('residuals','zeroinfl') 
+3
source

Source: https://habr.com/ru/post/1492759/


All Articles