`check_predictions()` fails for brms models with `dec()` (Wiener and RT-choice families)
I maintainer di solito rispondono entro 2 giorni
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Problem
check_predictions() errors on brms models whose response is
rt | dec(choice), i.e. the native wiener() family and custom choice-RT
families such as cogmod::cogmod_ddm():
Error in str2lang(insight::find_response(model)) :
argument must be a character string
There are two problems, and fixing the first alone exposes the second:
- For
rt | dec(resp),insight::find_response()returns
c("rt", "resp")andinsight::get_response()returns a data frame of
both. Sostr2lang()receives a length-2 vector. modelbased::estimate_prediction()returns 2N rows for these models,
anrtblock and aresponseblock distinguished by aComponentcolumn.
So the simulations would not line up with the N observed RTs in
out$y <- response.
Reprex
library(brms)
options(wiener_backend = "rtdists") # for posterior_predict(); RWiener works too
set.seed(1)
sim <- rbind(
rtdists::rdiffusion(150, a = 1.5, v = 0.5, t0 = 0.3, z = 0.75),
rtdists::rdiffusion(150, a = 1.5, v = 1.5, t0 = 0.3, z = 0.75)
)
d <- data.frame(
x = rep(c("a", "b"), each = 150),
rt = sim$rt,
resp = as.integer(sim$response == "upper")
)
m <- brm(bf(rt | dec(resp) ~ x), data = d, family = wiener(),
chains = 1, iter = 400, refresh = 0, seed = 1)
performance::check_predictions(m)
#> Error in str2lang(insight::find_response(model)) :
#> argument must be a character string
insight::find_response(m)
#> [1] "rt" "resp"
p <- modelbased::estimate_prediction(m, iterations = 5, keep_iterations = TRUE)
nrow(p) # 600, for 300 observations
table(p$Component)
#> response rt
#> 300 300
Cause
check_predictions.stanreg(), which check_predictions.brmsfit() is an alias
of (R/check_predictions.R, L248-253 on main):
response <- insight::get_response(model)
if (is.data.frame(response)) {
response <- eval(
str2lang(insight::find_response(model)),
envir = insight::get_response(model)
)
}
Suggested fix
Check the RT part of the model: keep the rt block of the predictions, and
the RT column of the response.
out <- modelbased::estimate_prediction(model, iterations = iterations,
keep_iterations = TRUE, re_formula = re_formula,
verbose = verbose, ...)
# Wiener / RT-choice models predict two components; check the RTs
is_rt_model <- isTRUE(minfo$is_wiener) || isTRUE(minfo$is_rtchoice)
if (is_rt_model && "Component" %in% colnames(out)) {
out <- out[out$Component == "rt", , drop = FALSE]
}
# ... unchanged ...
response <- insight::get_response(model)
if (is.data.frame(response)) {
if (is_rt_model) {
response <- response[[insight::find_response(model)[1]]]
} else {
response <- eval(str2lang(insight::find_response(model)), envir = response)
}
}
Tested on the model above: 300 x 50 simulations against 300 observed RTs, with
rows aligned with the data. A later option could check the choice proportions
too, from the Component == "response" block, but checking the RTs alone is
already what brms's pp_check() does for these models.
Versions
R 4.5.3, brms 2.23.1, insight 1.5.4.2, modelbased 0.17.0.6, performance
0.18.2. The code above is unchanged on main (0.18.2.16).
- Lingua principale
- R
- Stelle
- 1.2k
- Fork
- 108
- Merge medio
- 1g 3h
- PR unite (30g)
- 21
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di easystats/performance
-
Enhancement :boom:
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
easystats/performance#908 · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
[Proposal] Support for glmtoolbox glmgee objects (glmgee or gnmgee models) / interim warningsApertaDocs :books: Enhancement :boom:
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
easystats/performance#901 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
-
Enhancement :boom:
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
easystats/performance#891 ·
I maintainer di solito rispondono entro 2 giorni
-
3 investigators :grey_question::question: Enhancement :boom:
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
easystats/performance#849 · 9 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Enhancement :boom:
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
easystats/performance#825 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di easystats/performance
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
stan-dev/priorsense#150 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
bennettoxford/opencodecounts#170 ·
-
complexity::1-low effort::1-hours priority::3-could
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
jumpingrivers/audit.workbench#43 ·
I maintainer di solito rispondono entro 1 giorno
-
complexity::1-low effort::1-hours priority::3-could
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
jumpingrivers/audit.connect#71 ·
I maintainer di solito rispondono entro 1 giorno