rstanarm
Misc
Linear Regression
Interaction: continuous x categorical
<- stan_glm(log_gdp_std ~ rugged_std_c * cid, stan_mod data = dd, family = gaussian(link = "identity"), seed = 12345)
- Linear models still use
stan_glm
but with a gaussian distribution family
- Linear models still use
Interaction: categorical x categorical
<- stan_glm( rstan_mod1 ~ gender*dept, admitted data = ucb_01, family = binomial )
Discrete Distribution Models
Binomial (SR, Ch. 11)
<- stan_glm( tot_mod cbind(admit, reject) ~ 0 + applicant.gender, prior = normal(0,1), data = ucb, family = binomial )
Can also use a logistic model, but need case-level data (e.g. 0/1)
- Deaggregate count data into 0/1 case-level data
data(UCBadmit, package = "rethinking") <- UCBadmit %>% ucb mutate(applicant.gender = relevel(applicant.gender, ref = "male")) # deaggregate to 1/0 <- function(x, y) { deagg_ucb %>% UCBadmit select(-applications) %>% group_by(dept, applicant.gender) %>% ::uncount(weights = !!sym(x)) %>% tidyrmutate(admitted = y) %>% select(dept, gender = applicant.gender, admitted) } <- purrr::map2_dfr(c("admit", "reject"), ucb_01 c(1, 0), ~ disagg_ucb(.x, .y) )
Logistic
<- stan_glm( rstan_mod1 ~ gender*dept, admitted data = ucb_01, family = binomial )