Created
October 8, 2025 12:33
-
-
Save carlislerainey/a0b5cb6e92ded08d6f70bfc426e6610f to your computer and use it in GitHub Desktop.
Illustrating logistic regression with {brms}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ---- setup ---- | |
| # nice printing | |
| options(digits = 3) | |
| # load packages | |
| library(tidyverse) | |
| library(brms) | |
| # load only the turnout data frame and hard-code rescaled variables | |
| turnout <- ZeligData::turnout |> | |
| mutate(across(age:income, arm::rescale, .names = "rs_{.col}")) |> | |
| glimpse() | |
| # build model frame and design matrices | |
| f <- vote ~ rs_age + rs_educate + rs_income + race | |
| # fit model with brms | |
| fit <- brm(f, data = turnout, family = bernoulli) | |
| # compute qi | |
| comparisons(fit, variables = list(rs_age = c(-0.5, 0.5)), | |
| newdata = datagrid(grid_type = "mean_or_mode")) | |
| # fit model with brms via cmdstan! | |
| fit <- brm(f, data = turnout, family = bernoulli, | |
| backend = "cmdstanr") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment