3
$\begingroup$

I am using buildglmmTMB to build a model for several different taxa. I have 700 ish taxa and ~10 effects. I have a script that loops through all the taxa and applies buildglmmTMB to each taxon individually. I have two random effects that need to remain across all models. The default of buildglmmTMB is backwards stepwise elimination so it removes the least effective predictors first.

My question is, does buildglmmTMB remove random effects? I can't compare across taxa if one family had one random effect and another had two random effects in the model. I have looked into the documentation and it seems to imply that random effects are left untouched if "backward" and "order" are the specified direction (default). Is there a way to protect the random effects from elimination?

$\endgroup$
1
  • $\begingroup$ should the title say "retaining random effects" rather than "retaining fixed effects" ? $\endgroup$ Commented May 10 at 21:44

1 Answer 1

2
$\begingroup$

Reading ?buildmer::buildmerControl, it seems like include is what you're looking for:

include: A one-sided formula or character vector of terms that will be included in the model at all times and are not subject to testing for elimination. These do not need to be specified separately in the ‘formula’ argument. Useful for e.g. passing correlation structures in ‘glmmTMB’ models.

e.g.

set.seed(101)
dd <- data.frame(x = rnorm(1000), y = rnorm(1000),
                 f = factor(sample(1:20, size = 1000,  replace = TRUE)),
                 g = factor(sample(1:20, size = 1000,  replace = TRUE)),
                 h = factor(sample(1:20, size = 1000,  replace = TRUE)))

library(glmmTMB)
library(buildmer)

b0 <- buildglmmTMB(y ~ x + (1|f) + (1|g) + (1|h),
             data = dd,
             family = gaussian)
## eliminates everything, ends with y ~ 1

bmc <- buildmerControl(include = ~ (1|f) + (1|g) + (1|h))
b1 <- buildglmmTMB(y ~ x,
                   buildmerControl = bmc,
                   data = dd,
                   family = gaussian)
## ends with y ~ 1 + (1 | f) + (1 | g) + (1 | h)

This issue might be relevant, although the problems mentioned there didn't seem to affect my example ...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.