Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`check_predictions()` fails for brms models with `dec()` (Wiener and RT-choice families)

Chiusa
#971 0 commenti 1 reazione 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@DominiqueMakowski ci sta già lavorando.

Dal 14/10/2026.

  • #972 di @copilot-swe-agent — aperta

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:

  1. For rt | dec(resp), insight::find_response() returns
    c("rt", "resp") and insight::get_response() returns a data frame of
    both. So str2lang() receives a length-2 vector.
  2. modelbased::estimate_prediction() returns 2N rows for these models,
    an rt block and a response block distinguished by a Component column.
    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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di easystats/performance

Tutte le issue di easystats/performance

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.