I am running a zero-inflated negative binomial regression model using the function zeroinfl
from the pscl
package.
I need to exclude NA's from the model in order to be able to plot the residuals against the dependent variable later in the analysis.
Therefore, I want to set na.action="na.exclude"
. I can do this without any problem for a non-zero-inflated negative binomial regression model (using glm.nb
from the glm
package), eg.
fm_nbin <- glm.nb(DV ~ factor(IDV) + contr1
+contr2 + contr3, data=df,
subset=(df$var<500), na.action="na.exclude")
fm_nbin.res = resid(fm_nbin)
plot(fm_nbin.res~df$var)
works fine. However, when I do the same for a zero-inflated model, it does not work:
zinfl <- zeroinfl(DV ~ factor(IDV) + contr1
+contr2 + contr3 | factor(IDV) + contr1
+contr2 + contr3, data=df,
subset=(df$var<500), na.action="na.exclude")
zinfl.res = resid(zinfl)
plot(zinfl.res~df$var)
gives the error
Error in function (formula, data = NULL, subset = NULL, na.action = na.fail, :
variable lengths differ (found for 'df$var')
Is there any other command I should use to exclude NA's from my regression?
Edit: This is the nearest of an answer I could find. Can it in some way be applied to my problem?
Also, can naresid
in some way be applied?