glmmadmb help: multiple errors when running models - r

I'm trying to run a mixed effects model that includes three fixed effects with interaction and a random intercept and slope. The model I'm trying to specify in glmmadmb is:
> fit_zipoiss_ambig<-glmmadmb(AmbigCount~Posn.c*mood.c*Valence.c + offset(InputAmbig) + (1+Valence.c|mood.c/Chain), data = Data, zeroInflation = TRUE, family="poisson")
First I received this error message:
Error in Droplevels(eval(parse(text = x), data)) :
all grouping variables in random effects must be factors
So I used (as an example) fPosn.c=as.factor(Data$Posn.c)to convert all my predictors to factors. Then I ran this model:
> fit_zipoiss_ambig<-glmmadmb(AmbigCount~fPosn.c*fmood.c*fValence.c + offset(InputAmbig) + (1+fValence.c|fmood.c/Chain), data = Data, zeroInflation = TRUE, family="poisson")
Then I got this error:
Error in glmmadmb(AmbigCount ~ fPosn.c * fmood.c * fValence.c + offset(InputAmbig) + :
The function maximizer failed (couldn't find STD file) Troubleshooting steps include (1) run with 'save.dir' set and inspect output files; (2) change run parameters: see '?admbControl'
In addition: Warning message:
running command 'C:\Windows\system32\cmd.exe /c "C:/Program Files/R/R-3.2.2/library/glmmADMB/bin/windows64/glmmadmb.exe" -maxfn 500 -maxph 5 -noinit -shess' had status 1
I tried to follow the troubleshooting advice so included , admb.opts=admbControl(shess=FALSE,noinit=FALSE)) at the end of my model. Now I am receiving this error:
Error in glmmadmb(AmbigCount ~ fPosn.c * fmood.c * fValence.c + offset(InputAmbig) + :
rank of X = 106 < ncol(X) = 107
I have no idea what this error means. I'm hoping someone can help me work out how to specify my model in glmmadmb or failing that, some other package that will allow me to test a poisson or negative binomial distribution.

Without being able to run it myself, what jumps out at me is:
As far as your first error message, it is saying that the variables in your nested random-effects formula need to be factors.
Then, in your code: fPosn.c=as.factor(Data$Posn.c)
you are not creating "fPosn.c" within your data frame. To do that you need to run:
Data$fPosn.c = as.factor(Data$Posn.c)

Related

glm package glm.nb() "Error: no valid set of coefficients has been found: please supply starting values"

I am running a negative binomial regression on my dataset using the glm.nb() function.
My model looks something like this:
m_nb= glm.nb(Error_Count ~ TotalWL + Auto_frac +PHONE+JUSTIF_weight + MESSAGE_OTHER_count + Hour+
I(Auto_frac^2)+I(TotalWL^2), data = df)
When I ran it with a dataset of 10,000, the model is able to run, however, when I ran it with a larger dataset (60,000), I got this error:
`Error: no valid set of coefficients has been found: please supply starting values`
I then tried to give it some start values, but still throw the same error
m_nb= glm.nb(Error_Count ~ TotalWL + Auto_frac +PHONE+JUSTIF_weight + MESSAGE_OTHER_count + Hour+
I(Auto_frac^2)+I(TotalWL^2), data = df, start = c(0.02, 0.3,0.2,3,43, 4,13,0.04, 100))
Error: cannot find valid starting values: please specify some
But the model still doesn't converge. How should I set the starting value?
I also tried the same model with the fenebin() function in the fixest pacakage and the model works. However, I need the glm package, since the fixest package does not provide the standard error (S.E.) in the predict().
Thank you.

ggcoef_model error when two random intercepts

When trying to graph the conditional fixed effects of a glmmTMB model with two random intercepts in GGally I get the error:
There was an error calling "tidy_fun()". Most likely, this is because the
function supplied in "tidy_fun=" was misspelled, does not exist, is not
compatible with your object, or was missing necessary arguments (e.g. "conf.level=" or "conf.int="). See error message below.
Error: Error in "stop_vctrs()":
! Can't recycle "..1" (size 3) to match "..2" (size 2).`
I have tinkered with figuring out the issue and it seems to be related to the two random intercepts included in the model. I have also tried extracting the coefficient and standard error information separately through broom.mixed::tidy and then feeding the data frame into GGally:ggcoef() with no avail. Any suggestions?
# Example with built-in randu data set
data(randu)
randu$A <- factor(rep(c(1,2), 200))
randu$B <- factor(rep(c(1,2,3,4), 100))
# Model
test <- glmmTMB(y ~ x + z + (0 +x|A) + (1|B), family="gaussian", data=randu)
# A few of my attempts at graphing--works fine when only one random effects term is in model
ggcoef_model(test)
ggcoef_model(test, tidy_fun = broom.mixed::tidy)
ggcoef_model(test, tidy_fun = broom.mixed::tidy, conf.int = T, intercept=F)
ggcoef_model(test, tidy_fun = broom.mixed::tidy(test, effects="fixed", component = "cond", conf.int = TRUE))
There are some (old!) bugs that have recently been fixed (here, here) that would make confidence interval reporting on RE parameters break for any model with multiple random terms (I think). I believe that if you are able to install updated versions of both glmmTMB and broom.mixed:
remotes::install_github("glmmTMB/glmmTMB/glmmTMB#ci_tweaks")
remotes::install_github("bbolker/broom.mixed")
then ggcoef_model(test) will work.

LME with Random effects R code error message?

I'm trying to create a random mixed effects model with CCT as the outcome and time*behavior as the main predictor interaction term. I'm having a hard time running the model, as this is my code and it keeps saying "unused argument" error message. I'm using the variable ID as the random effects variable, and this is my code. thank you!
model.set$f <- with(model.set, ID)
m <- lmer(CCT ~ time*behavior, random = ~ 1|f, data = model.set)
The argument causing the error in your command is random: when using the function lme4::lmer, there is no "random" argument, the random effect is part of the main formula. The syntax you are using is specific to the function nlme::lme, which has a "random" argument to define random effects. See here for examples.
The following command should run without error:
m <- lmer(CCT ~ time * behavior + (1|f), data = model.set)

How to fix error in MuMIn package, dredge() function?

I am trying to run the Dredge function of the MuMIn package and keep getting an error, saying "result is empty". I don't know why and cannot find information on the meaning of this error message.
As far as my study of this function and package, the below code "should" be correct. Basically, I have a General Linear Mixed Model being run and I want to use the dredge function to run a model selection procedure based on AICc.
options(na.action = "na.fail") # Require for dredge to run
glmm1 <- lmer(cpue_diff ~ year + p.afraid + s.frequency.monitoring + (1 | f1.name ), data = dat, REML=FALSE)
summary(glmm1)
model_dredge <- dredge(glmm1, beta = FALSE, evaluate = TRUE, rank = "AICc")
options(na.action = "na.omit") # set back to default
The error message is:
"Fixed term is "(Intercept)" Error in dredge(glmm1, beta = FALSE,
evaluate = TRUE, rank = "AICc") : result is empty"
Any ideas anyone what this message means and how to correct it?
Much appreciated!
Check the the dimensions of your data frame. I had the same error message and when I checked out my data frame, there was more than a thousand "extra rows" full of NAs.
After subsetting the data frame to include only the true rows, everything worked well with the dredge function.

Error in model selection (gamm4) dredge function (MuMIn R package): family not recognised, model skipped

I am trying to do model selection for generalized additive mixed models (made using gamm4 using the MuMIn package in R.
I am essentially trying to follow this piece of literature for model selection with MuMIn and gamm4.
I am creating a model with 9 variables, and a random individual effect - which looks likes this:
library(gamm4)
library(MuMIn)
SouthFull = gamm4(OtoWidth ~ s(Ages) +
LagFinFSLdat_AnnEsts +
FSL_months_Feb +
LagFSLdat_Annual +
LagFSLdat_Spring +
LagFSL_months_Oct+
FinFSLdat_SummerDat +
FinFSLdat_AutumnDat +
LagFSL_months_Nov , random = ~(1|FishName), data = South)
But when I try to use the dredge function, it fails with the error message:
(dd <- dredge(global.model=SouthFull))
Error in dredge(global.model = SouthFull) : result is empty
In addition: There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In gamm4::gamm4(...) : family not recognized (model 1 skipped)
...
50: In gamm4::gamm4(...) : family not recognized (model 50 skipped)
Is this due to a problem with MuMIn not recognizing the gamm4 model family?
Full code & data can be found at my GitHub repository and the specific issue is in the code gamm_analysis.R, with the specific warnings found at line 81.
Thank you in advance
I think that there is something wrong with the package. I have the same error. Then, I tried to run the example available in the help of the function dredge of the MumIn package to see what I am doing differently and I get the same error even using the example below:
fm1 <- lm(y ~ ., data = Cement)
dd <- dredge(fm1)
The error message is:
Error in nobs.default(global.model) : no 'nobs' method is available

Resources