Zero-Inflation NB - object 'model_count' not found - r

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?

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.

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.

Related

R question: How to solve lme4 "Error in .empty.factors(e1) : object 'R_empty_factors' not found"

I have an R script that has worked fine up until today, but now I cannot run any lme4 models. If, for example, I try to run the model from the lme4 example data:
library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
I get the following error:
Error in .empty.factors(e1) : object 'R_empty_factors' not found
This happens for any lme4 model that I try to fit. The package loads fine. I've also tried re-installing lme4, but this didn't solve it. Other packages in R seem to work fine (e.g., dplyr)
I've also tried Googling this particular error and haven't found anything. Any ideas how to resolve this?

Package MuMIn: function "r.rsquaredGLMM" does not work anymore

I frequently used extracted marginal and conditional R^2 from mixed models using r.rsquaredGLMM(mod) from package MuMIn. Since today this doesn't work any more and I get the following error:
Error in r.rsquaredGLMM(mod) : could not find function "r.rsquaredGLMM"
Does anyone have a solution for this issue?
Thanks, Katharina
Below a code example:
library(MuMIn)
mod <- lmer(Reaction~Subject + (1|Days), data=sleepstudy)
r.rsquaredGLMM(mod)
```

Mixed Logit Model in Zelig (R) -- not running -- not available anymore?

I am interested in getting first differences from a mixed logit model using the Zelig package. However, I am not able to run a mixed logit model in Zelig. I updated the Zelig package as instructed by the Zelig website.
I ran the mixed logit mode but I got the following error: Error: logit.mixed is not a supported model type.
I tried to run the model from the vignette and got the same error:
library(Zelig)
data(voteincome)
z.out1 <- zelig(vote ~ education + age + female +tag(1 | state), data=voteincome, model="logit.mixed")
I get the following error:
Error: logit.mixed is not a supported model type.
Is "logit.mixed" no longer available on Zelig? I am currently using R version 3.5.1 if that makes a difference.
Replying to this older post in case anyone else is doing this as well. Looks like the instructions here to use the remotes package to download ZeligMultilevel currently work better than devtools::install_github(); I ran into the same dependency problem as the previous user.
Instead, users can use this code, available here:
install.packages("remotes")
remotes::install_github("IQSS/ZeligMultilevel")
Just remember to accept the remotes package's suggestion to update all packages. Then everything works fine.
It seems like logit.mixed is no longer supported by the zelig-package.
It was implemented in Zelig 4: http://zeligdev.github.io/ , but I can not find it in the currently supported models.
There is, however, a deprecated version of a package called ZeligMultilevel up on github available here.
You can try:
devtools::install_github("IQSS/ZeligMultilevel")
and then, followed by the demo, you can:
library(ZeligMultilevel)
data(voteincome)
z5 <- zlogitmixed$new()
z5
z5$zelig(vote ~ education + age + female + (1 | state),
data = voteincome)
z5

Error: could not find function "makeLearner" using h2o package

I'm using h2o package and trying to create a learner using the below given code
install.packages("h2o")
library("h2o")
h2o.learner <- makeLearner("regr.h2o.deeplearning",predict.type = "response")
But I'm getting this error
> h2o.learner <- makeLearner("regr.h2o.deeplearning",predict.type = "response")
Error: could not find function "makeLearner"
Note: Few months back I used this code without any problem.
Any idea what could be possible thing for this error?
The correct code for this is simply
library(mlr)
h2o.learner = makeLearner("regr.h2o.deeplearning")
The makeLearner() is not part of H2O. It appears to be part of the mlr package. It also seems that mlr does have h2o support, so it might be as simple as adding a library(mlr) to the top of your script? (Making sure that the mlr package has been installed, already, of course.)

Are there known compatibility issues with R package mgcv? Are there general rules for compatibility?

I use R version 2.15.1 (2012-06-22) and mgcv version 1.7-22
I load the following set of packages in R:
library(sqldf)
library(timeDate)
library(forecast)
library(xts)
library(tseries)
library(MASS)
library(mgcv)
It happens that I can not run a simple model (I omit the code). Even the sample code taken from the help pages:
dat = gamSim(1,n=400,dist="normal",scale=2)
b = gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)
gives an error:
Error in qr.qty(qrc, sm$S[[l]]) :
NA/NaN/Inf in foreign function call (arg 5)
In addition: Warning message:
In smoothCon(split$smooth.spec[[i]], data, knots, absorb.cons, scale.penalty = scale.penalty, :
number of items to replace is not a multiple of replacement length
Note that everything works fine, if I just load the package mgcv and then use the sample code right away. It also works if I just load all the packages and run the sample code. It just does not work if I
load all packages
do some file reading, sqldf statements, ts operations and some models from package forecast.
if I then apply GAM, it does not work anymore.
Apparently the variable definitions in the general environment mess up the functioning of the package.
Are there any known issues? Are there general rules that I have to obey if I load various packages? Can I write code that "disturbed" the package mgcv?
# Richard there are 2 GAM related packages: gam and mgcv. Loading both libraries at the same time usually causes a conflict.
Loading mgcv as the first package solved my problem ... strange but true.

Resources