Hi,
I fitted a model with a model with monotonic predictor and came across two problems.
binomial_base_model_fs_mono2 <- brm(
data = success_moduls %>% mutate(SemesterOrd = ordered(Semester)),
n_Prüfungsstatus | trials(n_Prüfungen) ~ 1 + mo(SemesterOrd),
family=binomial(link='logit'),
cores = 4,
sample_prior = TRUE,
file = "models/binomial_base_model_fs_mono2.rds"
)
- lineplot vs catergorial plot
When variable Semester
is numeric the conditional_effects plot shows a linegraph what was not expected:
Queston 1: Is there a easy way to get a categorial plot with errorbars like this?:
I had to refit the model and change the variable type to ordered to get this.
I tried to use the categorical
, ordinal
and re_formula
options from conditional_effect but had no luck.
- Calculation of conditional effects
When I tried to do a plot of this with tidybayes stat_halfeye
style I came across a second problem.
I found this post that links to the paper where the calculation of the monotonic effects is described. When I follow the description I end up with a different plot than the conditional_effects
function gave (D = 5):
The intercept / first category seems to be correct. But afterwards it does not work out well.
When I set D to 1 instead I get this:
The big step between category 5 and 6 is not present in both plots. I wonder if the D parameter has to be variable or if the terms have to be added differently with a logit link function.
Queston 2: Can someone explain me the difference or what I have to change in my calculation for the conditional effects?
I used this transformation:
D <- 5
binomial_base_model_fs_mono2 %>%
spread_draws(b_Intercept, bsp_moSemesterOrd,
simo_moSemesterOrd1[semester]) %>%
pivot_wider(names_from = semester, values_from = simo_moSemesterOrd1) %>%
transmute(
.draw = .draw,
`1` = inv_logit_scaled(b_Intercept),
`2` = inv_logit_scaled(b_Intercept+bsp_moSemesterOrd*D*(`1`)),
`3` = inv_logit_scaled(b_Intercept+bsp_moSemesterOrd*D*(`1`+`2`)),
`4` = inv_logit_scaled(b_Intercept+bsp_moSemesterOrd*D*(`1`+`2`+`3`)),
`5` = inv_logit_scaled(b_Intercept+bsp_moSemesterOrd*D*(`1`+`2`+`3`+`4`)),
`6` = inv_logit_scaled(b_Intercept+bsp_moSemesterOrd*D*(`1`+`2`+`3`+`4`+`5`))
) %>% pivot_longer(-.draw) %>%
# mutate(semester = as.character(semester+1)) %>%
ggplot(aes(y = name, x = value)) +
tidybayes::stat_halfeye() +
xlab("Success probability") +
ylab("Semester") +
coord_flip()
The model summary is:
Family: binomial
Links: mu = logit
Formula: n_Prüfungsstatus | trials(n_Prüfungen) ~ 1 + mo(SemesterOrd)
Data: success_moduls %>% mutate(SemesterOrd = ordered(Se (Number of observations: 4501)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept -0.13 0.01 -0.16 -0.11 1.00 3516 2899
moSemesterOrd 0.31 0.01 0.29 0.33 1.00 3743 2546
Monotonic Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
moSemesterOrd1[1] 0.14 0.01 0.12 0.17 1.00 3433 2681
moSemesterOrd1[2] 0.12 0.01 0.09 0.15 1.00 3431 2421
moSemesterOrd1[3] 0.09 0.01 0.06 0.12 1.00 3677 2481
moSemesterOrd1[4] 0.17 0.03 0.10 0.23 1.00 4290 2386
moSemesterOrd1[5] 0.48 0.03 0.41 0.55 1.00 4142 2636
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).