I am working through the 2023 version of the Statistical Rethinking course, and I have gotten stuck embarrassingly early in my attempt to use brms.
In lecture “bonus” material, McElreath asks how we could model the proportion of water on the globe but with a twist. The twist is that for x
proportion of the time, the outsome is misclassified. He codes this as
sim_globe <- function(p = 0.7, N = 9, x = 0.1) {
true_sample <- sample(c("W", "L"), size = N, prob = c(p, 1 - p), replace = TRUE)
obs_sample <- ifelse(runif(N) < x,
ifelse(true_sample == "W", "L", "W"), # error
true_sample)
return(obs_sample)
}
sim_globe()
#> [1] "W" "W" "L" "L" "L" "W" "W" "W" "W"
My question is: how could in model this with brms?
Here is a brms model without incorporating measurement error taken from Kurz’s brms translation of Statistical Rethinking:
library(brms)
b2.1 <-
brm(
w | trials(n) ~ 0 + Intercept,
data = data. Frame(w = 24, n = 36),
family = binomial(link = "identity"),
prior = prior(beta(1, 1), class = b, lb = 0, ub = 1)
)
My initial thought was to do something like this, but here’s what I get:
b2.2 <-
brm(
w | mi() + trials(n) ~ 0 + Intercept,
data = data.frame(w = 24, n = 36),
family = binomial(link = "identity"),
prior = prior(beta(1, 1), class = b, lb = 0, ub = 1),
seed = 2
)
#> Error: Argument 'mi' is not supported for family 'binomial(identity)'.
Is there a way to properly specify measurement error with a binomial model with brms?
Session info:
- R version 4.2.2 (2022-10-31)
- Platform: aarch64-apple-darwin20 (64-bit)
- Running under: macOS Ventura 13.0.1
- brms Version: 2.18