knitr::opts_chunk$set( collapse = TRUE, comment = NA, fig.path = "man/figures/README-", out.width = "100%" )
This package provides extended functionality for mixed models. The goal of mixedup
is to solve little problems I have had that slip through the cracks from the various modeling packages and others in trying to get presentable output. Basically the idea is to create (tidy) objects that are easy to use and essentially ready for presentation, as well as consistent across packages and across functions. Such objects would be things like variance components and random effects. I use several of these packages (including mgcv) for mixed models, and typically have to do some notable post processing to get some viable output even with broom::tidy
, and this effort often isn't applicable if I switch to another package for the same type of model. These functions attempt to address this issue.
For more details and examples see https://m-clark.github.io/mixedup/.
You can install mixedup from GitHub with remotes
. Use the second approach if you don't already have rstanarm
or brms
(they aren't required to use in general).
remotes::install_github('m-clark/mixedup') # if you don't already have rstanarm and/or brms withr::with_envvar(c(R_REMOTES_NO_ERRORS_FROM_WARNINGS = "true"), remotes::install_github('m-clark/mixedup') )
lme4
glmmTMB
nlme
mgcv
rstanarm
brms
Not all features are available to the various modeling packages (e.g. autocorrelation for lme4
), and some functionality may just not be supported for this package, but most functions are applicable to the packages listed.
In the following I suppress the package startup and other information that isn't necessary for demo.
brm_model <- mixedup:::brms_model rstanarm_model <- mixedup:::rstanarm_model
library(lme4) lmer_model <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy) library(glmmTMB) tmb_model <- glmmTMB(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy) library(nlme) nlme_model <- nlme( height ~ SSasymp(age, Asym, R0, lrc), data = Loblolly, fixed = Asym + R0 + lrc ~ 1, random = Asym ~ 1, start = c(Asym = 103, R0 = -8.5, lrc = -3.3) ) library(brms) # brm_model = brm( # Reaction ~ Days + (1 + Days | Subject), # data = sleepstudy, # refresh = -1, # verbose = FALSE, # open_progress = FALSE, # cores = 4, # iter = 1000 # ) library(rstanarm) # rstanarm_model = stan_glmer( # Reaction ~ Days + (1 + Days | Subject), # data = sleepstudy, # refresh = -1, # verbose = FALSE, # show_messages = FALSE, # open_progress = FALSE, # cores = 4, # iter = 1000 # ) library(mgcv) gam_model = gam( Reaction ~ Days + s(Subject, bs = 're') + s(Days, Subject, bs = 're'), data = lme4::sleepstudy, method = 'REML' )
library(mixedup) extract_random_effects(tmb_model) extract_fixed_effects(nlme_model) extract_random_coefs(lmer_model) extract_vc(brm_model, ci_level = .8) summarize_model(lmer_model, cor_re = TRUE, digits = 1) find_typical(gam_model, probs = c(.25, .50, .75))
mods = list( tmb = tmb_model, lmer = lmer_model, brm = brm_model, stan = rstanarm_model, gam = gam_model ) purrr::map_df(mods, extract_vc, .id = 'model')
Please note that the 'mixedup' project is released with a Contributor Code of Conduct.
By contributing to this project, you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.