What code should I use for my GLMM, glmer, lmer?

432 Views Asked by At

I Want to use the dependent variable "Herps" (count data) to understand what response variables are important influencing herpetofauna species richness. The response variables include Total_Saplings, Total_Understorey_Vegetation, Mean_Leaf_Litter_Depth, Mean_Canopy_Openess, Tree_Species_Richness, Mean_DBH, Large_Trees, Total_Basal_Area, Aguada_Distance_Category, and I want to include "Year" as a random variable.

I've not used R before, and this is a steep learning curve for myself. I appreciate any help offered. Thanks

Hi. So I've tried using a couple of codes myself but I don't seem to be getting anywhere, some of these codes include:

1)

AllHerpsRichness <- glmulti(Rich_All_Herps ~ Total_Saplings * Total_Understorey_Vegetation * Tree_Species_Richness + 
                                             Mean_DBH * Total_Basal_Area * Mean_Canopy_Openess * 
                                             Mean_Leaf_Litter_Depth * Aguada_Distance_Category * 
                                             Camp * (1|Year), data=Habitat,
                                             level=1, fitfunction=glm, crit="aicc",
                                             confsetsize=256, family="poisson")

but I get the error

Error in Total_Saplings + Total_Understorey_Vegetation + Tree_Species_Richness + :
non-numeric argument to binary operator

AllHerpsRichness <- lmer(Rich_All_Herps ~ Total_Saplings * Total_Understorey_Vegetation * 
                                          Tree_Species_Richness * Mean_DBH + 
                                          Total_Basal_Area * Mean_Canopy_Openess * 
                                          Mean_Leaf_Litter_Depth * Aguada_Distance_Category * Camp *
                                          (1|Year),
                 data=Habitat)

but I receive the error

boundary (singular) fit: see help('isSingular')

AllHerpsRichness <- lmer(Rich_All_Herps ~ Total_Saplings * Total_Understorey_Vegetation * 
                                          Tree_Species_Richness * Mean_DBH + 
                                          Total_Basal_Area * Mean_Canopy_Openess * 
                                          Mean_Leaf_Litter_Depth * Aguada_Distance_Category * 
                                          Camp * (1|Year),
                 data=Habitat)

but the error

boundary (singular) fit: see help('isSingular')
Warning message:
In glmer(Rich_All_Herps ~ Total_Saplings * Total_Understorey_Vegetation * :
calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly

I'm not sure if either one of these codes I've already tried is right, but does anyone know how I can fix one of them to try and get some outputs.

1

There are 1 best solutions below

1
On
  1. I don't think glmulti handles random effects, and 'multiplying' (*) by (1|Year) would break things anyway.
  2. A singular fit is not necessarily a problem, it typically means you might want to simplify your model. Read e.g. the help file at ?lme4::isSingular, or the relevant section in the GLMM FAQ.
  3. Your error message doesn't match your code here, I suspect a transcription error (it's generally best to directly cut-and-paste your code so that what you post matches the code you actually ran directly): you must have specified family = gaussian ?

We would need more details to give you more advice, and the question might be better suited for CrossValidated, but I would suggest:

glmer(Rich_All_Herps ~ Total_Saplings + Total_Understorey_Vegetation + 
       <... more covariates ... > + Camp + (1|Year),
                 data=Habitat,
                 family = poisson)

as a start, because:

  • a Poisson model is a good starting guess for count data (you definitely need to check for overdispersion after fitting the initial model and consider switching to a negative binomial or observation-level random effect (Harrison 2015), see lme4::glmer.nb or switch to glmmTMB)
  • random effects (e.g. (1|Year) are always added, not multiplied by, other covariates in the formula
  • additive effects (+ rather than *) make more sense to start with, unless:
    • you have a very large data set (all-way interactions among n covariates requires 2^n parameters)
    • you're optimistic about your ability to interpret many-way interactions
    • you have particular interactions that are of interest, or perhaps model all 2-way interactions (if mildly optimistic; still requires choose(n, 2) + n + 1 parameters)

Harrison, Xavier A. 2014. “Using Observation-Level Random Effects to Model Overdispersion in Count Data in Ecology and Evolution.” PeerJ 2 (October): e616. https://doi.org/10.7717/peerj.616.