Switches the predict_outliers flag on a model fitted with cogmod_lognormal()
or cogmod_loggamma(), controlling whether posterior_predict() and posterior_epred() describe the
fitted mixture or the decision process alone.
Predictions exclude the outlier component by default, because for almost every downstream use it is a nuisance: it pulls expected values toward its own mean (0.16 s) and adds a spike of implausibly fast draws to posterior predictive samples. It is also a deliberately fixed regularizer rather than a claim about how guesses are distributed, so simulating from it means simulating from something the model does not assert.
with_outliers() restores the mixture. The main reason to want it is
brms::pp_check(): on untrimmed data the decision-only predictive has no fast
spike to match the one in the data, which reads as misfit. Use
pp_check(with_outliers(m)) for a like-for-like check.
The flag is stored on the model rather than passed as an argument, because
brms and the packages built on it (insight, modelbased,
marginaleffects, emmeans) do not forward extra arguments down to a custom
family's prediction methods - posterior_epred() reaches the family method
with prep and nothing else. Carrying it on the object is what makes it work
through all of them. The same flag can be set up front with
cogmod_lognormal(predict_outliers = TRUE).
log_lik() is unaffected and has no equivalent switch: the likelihood is
the mixture, and dropping a component from it would not be a different summary
of the same model but a different model. One consequence worth knowing is that
posterior_predict() and log_lik() do not describe the same distribution by
default. This also desyncs loo_pit(), loo_predict() and bayes_R2() from
loo(), not just hand-rolled checks - anything that compares a simulated
replicate against the likelihood should be run on with_outliers().
Arguments
- object
A
brmsfitfitted withcogmod_lognormal(),cogmod_loggamma()or any other family built on the outlier mixture - see the Supported families section ofcogmod_priors()for the full list, which includes the choice-and-RT families such ascogmod_lnr().
Value
The model, with the flag set. The fit itself is untouched - only how predictions are summarised changes.
Examples
# \donttest{
# Fitting needs cmdstanr, which lives outside CRAN - see the package website.
if (requireNamespace("cmdstanr", quietly = TRUE) &&
!is.null(cmdstanr::cmdstan_version(error_on_NA = FALSE))) {
df <- data.frame(
RT = rcogmod_lognormal(200, ndt = 0.3, poutlier = 0.05),
Condition = rep(c("A", "B"), each = 100)
)
f <- brms::bf(RT ~ Condition, ndt ~ 1, poutlier ~ 1,
family = cogmod_lognormal()
)
m <- brms::brm(f,
data = df, stanvars = cogmod_stanvars(f),
prior = cogmod_priors(f, df), init = cogmod_inits(f, df),
backend = "cmdstanr", chains = 1, iter = 500, refresh = 0
)
# the decision process alone - the default, everywhere downstream
head(brms::posterior_epred(m)[, 1])
# the fitted mixture, e.g. for a like-for-like predictive check
m2 <- with_outliers(m)
head(brms::posterior_epred(m2)[, 1])
without_outliers(m2) # back to the default
}
# }