Logistic regression in brms
Bayesian workshop - STEP 2023
Scott James Perry
University of Alberta
By the end of this lesson you will be able to…
- set priors in the logit space
- fit models to trial-level binary data
Wide priors lead to strange assumptions
- Weakly-informative priors in logit space is weirdly informative in probability space
\(Intercept \sim Normal(0, 3)\)
Wide priors lead to strange assumptions
- Weakly-informative priors in logit space is weirdly informative in probability space
\(Intercept \sim Normal(0, 3)\)
The rule of threes
- Most of probability space is between logits -3 and 3
- Try to keep priors within these bounds (especially on the intercept)
Think about the task, is 50% guessing?
If guessing leads to 50% ‘right’, does it make sense to:
- center our Intercept on log-odds of 0 (probability of 0.5)
- put too much probability mass below guessing?
Think about the task, is 50% guessing?
If guessing leads to 50% ‘right’, does it make sense to:
- center our Intercept on log-odds of 0 (probability of 0.5)
- put too much probability mass below guessing?
I’m not giving specific recommendations here, other than you think critically about your model and your priors
A change is (still) not constant
- As with lognormal model, we have non-linear transformation
- Remember that changes in log-odds are not linear with probability
Fitting trial-level data with Bernoulli distribution
Bernoulli special case of binomial distribution when n=1
model_fit <- brm(...,
family = bernoulli(link = "logit"),
...)
What does our model look like written out?
Model:
\(acc_i \sim Binomial(n, p_i)\)
\(logit(p_i) = Intercept + \beta_1 group\_sumcoded + \beta_2 scaled\_Freq\)
Priors:
\(Intercept \sim Normal(?, ?)\)
\(\beta_1 \sim Normal(?, ?)\)
\(\beta_2 \sim Normal(?, ?)\)
What does our model look like written out?
Model:
\(acc_i \sim Bernoulli(p_i)\)
\(logit(p_i) = Intercept + \beta_1 group\_sumcoded + \beta_2 scaled\_Freq\)
Priors:
\(Intercept \sim Normal(?, ?)\)
\(\beta_1 \sim Normal(?, ?)\)
\(\beta_2 \sim Normal(?, ?)\)
Let’s go practice logistic regression in base R and brms
We are going to start with the script S5_E1_logit_priors.R