Zero-Inflation NB - object 'model_count' not found
Asked Answered
K

2

8

I am modeling a mediated zero-inflated negative binomial (ZINB) model. i am following the steps of O'Rourke & Vazquez (2019) --> https://www.sciencedirect.com/science/article/abs/pii/S0306460319301078

A few days ago i was running a different ZINB model which ran perfectly fine. However, today i wrote a different model, same variables, but somehow it doesn't run anymore and gives a strange error. When i try my previous model i suddenly get the same error, namely:

Error in zeroinfl(Y1 ~ X1 + M1 | X1 +  : object 'model_count' not found

The rest of my code:

#loading required packages
library(psych)
library(foreign)
library(ggplot2)
library(MASS)
library(pscl)
library(nonnest2)
library(lmtest)
library(boot)

#Import data
mydata

#Fit a ZINB model
ex1zinb <- zeroinfl(X1 ~ Y1 + M1 | Y1 + M1, data = mydata, dist="negbin", EM= TRUE)

I already checked the assumption for the statistical analyses etc., and it is especially strange that a similar model did run a few days ago and not anymore. I did try to install several packages today but i ran into a non-zero exit status. Following some comments on stackoverflow i installed a package by adding dependencies = TRUE, but it ran stuck. Afterwards the problems started. Maybe there is something wrong with my packages?

When loading the libraries i get the following messages:

> library(psych)
> library(foreign)
> library(ggplot2)
Need help? Try Stackoverflow: https://stackoverflow.com/tags/ggplot2

Attaching package: ‘ggplot2’

The following objects are masked from ‘package:psych’:

    %+%, alpha

> library(MASS)
> 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
> library(nonnest2)
This is nonnest2 0.5-3.
nonnest2 has not been tested with all combinations of model classes.
> library(lmtest)
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric

> library(boot)

Attaching package: ‘boot’

The following object is masked from ‘package:psych’:

    logit

Anyone some suggestions/insights? Thanks in advance!

Edit: i do get a normal output when running a non-zero inflated negative binomial model. The following code runs smooth:

summary(ex1nb <- glm.nb(Y1~ X1 + M1, data = mydata))

So i think my data is fine?

Kiushu answered 22/4, 2020 at 10:45 Comment(10)
The messages you are getting while importing libraries are Ok, and there's no need to worry. But I don't think the code you shared can generate an error regarding model_count. There is no reference to it. An error regarding mydata will be more likely to occur. Can you reproduce it in a new R session?Hypertrophy
It's quite strange because in a new setting the same occurs. When i fit a normal negative binomal GLM, i get normal output. For instance, ``` #3. Since excess zero - fit a NB Poisson modl. summary(ex1nb <- glm.nb(Y1~ X1+ M1, data = mydata)) ``` Would give me a normal output and runs. So i guess my data is fine?Kiushu
can you try just loading pscl and running your model? I suspect some packages clash with itBrawner
Strangely, also with only pscl loaded and running the ZINB i get the object 'model_count' error. i tried to reinstall pscl and received the following error:WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding.' could that affect the package capabilities?Kiushu
I tried to install RTools and reinstall some packages and re-run it. I get the same error. So i guess it has something to do with pscl. Strangely.Kiushu
Had to update the version since pscl was not converging and running for ages for a simple direct relationship. I am now running on R 4.0, the newest PSCL and newest R-Studio but still encounter the error. Anyone some suggestions?Kiushu
I can confirm that it is an update to pscl that is causing the error. I have two environments, one with an older version. Same data runs fine and I get expected values, in the newer environment I had to reload pscl and got the error. I'm not sure if it is in pscl itself or a dependency.Rectal
Thanks for the reply. I already reported an issue on the Github page.Kiushu
Try setting the 'EM = false' as one of the arguments in your functionAuctioneer
@user553480, setting 'EM = false' did the trick when I ran into this same issue. It appears this argument is no longer in the current documentation (rdocumentation.org/packages/pscl/versions/1.5.5/topics/zeroinfl). I assume some others are using the same UCLA guide to zero-inflated negative binomial regression that I am (stats.idre.ucla.edu/r/dae/zinb) which uses a sample model that includes this argument.Marlette
F
6

I got that error too. I used R 4.0 then tried R 3.6. No luck.

I was able to get the error to go away when I removed the EM = TRUE parameter.

I'm not sure if this helps.

Falstaffian answered 16/6, 2020 at 19:1 Comment(0)
O
3

Author of the paper here (O'Rourke) - this was due to a pscl package update where they changed the location of the EM statement. We have updated the code for the paper removing the "EM=TRUE" statements from each relevant section and are in the process of getting it on github so we can flexibly update in accordance with any other package changes. Please feel free to reach out if you have other issues with the code.

Offal answered 15/12, 2022 at 0:41 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.