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

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

Related

Why am getting the following error when adjusting a glmm with the "glmmTMB" function and I try to obtain the confidence intervals?

I am trying to run the following model:
Mm3znb<-glmmTMB(total~ Geopolitical-1 + offset(logha) + YearCollected + tmn + (tmn|Site/Plot), ziformula = ~1, data = mc3m, family="nbinom2")
but when I try to obtain the confidence intervals am getting this error:
Error in dimnames(x) <- dn :
length of 'dimnames' [2] not equal to array extent
Does anyone know what this issue might be?
This is a problem that has been fixed very recently (June 2022) in the development version (confint wasn't working in models with more than one random effect; (tmn|Site/Plot) is implicitly two random effects, as it gets expanded to (tmn|Site) + (tmn|Site:Plot) internally).
If you can (you will need to install development tools - e.g. Xcode if you're on MacOS, Rtools if you're on Windows), install the development version via
remotes::install_github("glmmTMB/glmmTMB/glmmTMB")
The pkgdown page has a little more information about installing (if all else fails, contact the developers to see if they can make a recent binary package available).

Issue with GLMM in glmmTMB

I am trying to run the following model:
MP1 <- glmmTMB(Abundance ~ All_predator + Year + Location + Depth +
(1 | Site/Site.Transect),
data = plandat,
family = "poisson")
but am getting this error:
Error in .Call("getParameterOrder", data, parameters, new.env(),
PACKAGE = DLL) :
Incorrect number of arguments (3), expecting 4 for
'getParameterOrder'
Does anyone know what this issue might be?
This is a binary-incompatibility problem as documented here. You should probably have seen a "Package version inconsistency detected" message telling you to re-install glmmTMB from source. Depending on the release sequence of TMB and glmmTMB on CRAN, updating from CRAN as usual might work; otherwise you need to re-install from source (see ?glmmTMB::reinstalling).

Index error when running maxnet function (maxnet package)

I use the maxnet function (maxnet package) as one of the model algorithms in an ensemble model. Sometimes, the code executes without an error. Other times, it gives me the error message you see below. I am working on a windows 10 Pro (R version 3.6.1, Rstudio version 1.2.5042).
Code:
dm.Maxent <- maxnet(p = train$species, data = train[-train$species],
maxnet.formula(p = train$species,
data = train[-train$species],
classes = "default"))
Error:
Error in intI(j, n = x#Dim[2], dn[[2]], give.dn = FALSE) :
index larger than maximal 185
train is a dataframe with 621 rows (one row for every occurrence/absence point), and 29 columns (28 columns containing variables and 1 column "species" that indicates presence or absence of the species (0/1)).
I am having the same issue. It is unpredictable, since for several species it ran fine, then out of a sudden it stopped.
I found a response on this link: https://github.com/jamiemkass/ENMeval/issues/62
In the new version of maxnet (check the Github repo, as it looks like the CRAN version gas not been updated yet), there is a new argument "addsamplestobackground". When set to TRUE, it solves some of these errors. Currently, you will have to use install_github to reinstall maxnet to use this argument. Once you do, install_github to get the dev branch version of ENMeval (v2), which will implement this by default. Hopefully that fixes these problems.
I reinstalled maxnet from github :
install.packages("remotes")
remotes::install_github("mrmaxent/maxnet")
and set addsamplestobackground = T Maybe this would help you.

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.)

stargazer() with Zelig regression output

I'm working with the R package stargazer. I have a Zelig model that I can't get stargazer to create Latex code for.
logit9.1 <- zelig(winner ~ treatment + count_parties + resp_OECD24 + DirExp + IndExp,
data = outcome, model = "logit" ,robust = TRUE)
stargazer(logit9.1)
Error in if (zelig.object$family$family == "gaussian") { :
argument is of length zero
If I change model="normal", I get the same error message. model="gaussian" is not a supported model in zelig(). The stargazer documentation says that it works with zelig objects.
stargazer v. 2.0 is now available on CRAN. The package has been updated to reflect changes made to Zelig objects, and has a bunch of other new features. Zelig has not always been perfect about backward compatibility of the object it creates, so the old version of stargazer() might have trouble. Perhaps you should try running your code with the latest version, and see if it works.

Resources