In my data, each observation has three count variables, with the second being a subtotal of the first, and the third one being a sub-subtotal. One thing I’d like to estimate is
(total - subtotal) / (total - subsubtotal), but currently
posterior_predict() is giving me seemingly absurd values:
N <- 100 set.seed(1) total <- rpois(N, 10) subtotal <- rbinom(N, total, 0.5) subsubtotal <- rbinom(N, subtotal, 0.5) d <- data.frame(total, subtotal, subsubtotal) bf1 <- brmsformula(subtotal | trials(total) ~ 1) bf2 <- brmsformula(subsubtotal | trials(subtotal) ~ 1) m <- brm(bf1 + bf2, d, binomial) pp <- posterior_predict(m) stopifnot(all(pp[, , "subtotal"] >= pp[, , "subsubtotal"])) # error
I hoped the posterior predictions would take in consideration that
subtotal is both the outcome in the first formula and the number of trials in the second formula. However, sometimes the predicted subsubtotal is larger than the predicted subtotal. Did I miss something?
I guess I could work around this issue by expanding the data into
total rows per old observation with an ordinal outcome (levels: “not within subtotal”, “within subtotal but not subsubtotal” and “within subtotal”). Is there a better way?
Of course I could create a model with
(total - subtotal) / (total - subsubtotal) as the outcome, but I’d like to stick to something like the first model, because when I add predictor variables it provides me odds ratios I’m interested in.
- Operating System: Windows
- brms Version: 2.10.0