r descr_models("linear_reg", "stan_glmer")
This model has no tuning parameters.
Some relevant arguments that can be passed to set_engine()
:
chains
: A positive integer specifying the number of Markov chains. The default is 4.iter
: A positive integer specifying the number of iterations for each chain (including warmup). The default is 2000.seed
: The seed for random number generation. cores
: Number of cores to use when executing the chains in parallel.prior
: The prior distribution for the (non-hierarchical) regression coefficients. prior_intercept
: The prior distribution for the intercept (after centering all predictors). See ?rstanarm::stan_glmer
and ?rstan::sampling
for more information.
r uses_extension("linear_reg", "stan_glmer", "regression")
library(multilevelmod) linear_reg() %>% set_engine("stan_glmer") %>% set_mode("regression") %>% translate()
There are no specific preprocessing needs. However, it is helpful to keep the clustering/subject identifier column as factor or character (instead of making them into dummy variables). See the examples in the next section.
The model can accept case weights.
With parsnip, we suggest using the formula method when fitting:
library(tidymodels) data("riesby") linear_reg() %>% set_engine("stan_glmer") %>% fit(depr_score ~ week + (1|subject), data = riesby)
When using tidymodels infrastructure, it may be better to use a workflow. In this case, you can add the appropriate columns using add_variables()
then supply the typical formula when adding the model:
library(tidymodels) glmer_spec <- linear_reg() %>% set_engine("stan_glmer") glmer_wflow <- workflow() %>% # The data are included as-is using: add_variables(outcomes = depr_score, predictors = c(week, subject)) %>% add_model(glmer_spec, formula = depr_score ~ week + (1|subject)) fit(glmer_wflow, data = riesby)
For prediction, the "stan_glmer"
engine can compute posterior intervals analogous to confidence and prediction intervals. In these instances, the units are the original outcome. When std_error = TRUE
, the standard deviation of the posterior distribution (or posterior predictive distribution as appropriate) is returned.
McElreath, R. 2020 Statistical Rethinking. CRC Press.
Sorensen, T, Vasishth, S. 2016. Bayesian linear mixed models using Stan: A tutorial for psychologists, linguists, and cognitive scientists, arXiv:1506.06201.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.