Issue with GLMM in glmmTMB - r

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

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

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.

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 message in lme4::glmer: " 'what' must be a character string or a function"

I am running a multi-level model. I use the following commands with validatedRS6 as the outcome, random as the predictor and clustno as the random effects variable.
new<-as.data.frame(read.delim("BABEX.dat", header=TRUE))
install.packages("lme4")
library(lme4)
model1<- glmer(validatedRS6 ~ random + (1|clustno), data=new, family=binomial("logit"), nAGQ = 1L)
However, I get the following error
Error in do.call(new, c(list(Class = "glmResp", family = family), ll[setdiff(names(ll), :
'what' must be a character string or a function
I have absolutely no idea what has gone wrong and have searched the internet. I am sorry but I cannot provide the data as it is from an intervention which has yet to be published.
(expanded from comment).
Congratulations, you found a bug in lme4! This is fixed now:
https://github.com/lme4/lme4/commit/9c12f002821f9567d5454e2ce3b78076dabffb54
It is caused by having a variable called new in the global environment (deep in the guts of the code, lme4 uses do.call(new,...) and finds your variable new rather than the built-in function new).
You can install a patched version from Github using devtools::install_github() (but you'll need compilation tools etc.). Alternately, there is a very simple workaround -- just call your variable anything other than new (you can't just copy it, i.e. new2 <- new -- you also have to make sure the old version is removed (rm("new"))).

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