r descr_models("logistic_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("logistic_reg", "stan_glmer", "classification")
library(multilevelmod) logistic_reg() %>% set_engine("stan_glmer") %>% 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("toenail", package = "HSAUR3") logistic_reg() %>% set_engine("stan_glmer") %>% fit(outcome ~ treatment * visit + (1 | patientID), data = toenail)
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 <- logistic_reg() %>% set_engine("stan_glmer") glmer_wflow <- workflow() %>% # The data are included as-is using: add_variables(outcomes = outcome, predictors = c(treatment, visit, patientID)) %>% add_model(glmer_spec, formula = outcome ~ treatment * visit + (1 | patientID)) fit(glmer_wflow, data = toenail)
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.