ppc_shares: Posterior-predictive share check for hierarchical Bayes fits

View source: R/hb_diagnostics.R

ppc_sharesR Documentation

Posterior-predictive share check for hierarchical Bayes fits

Description

Compares each alternative's observed take rate (share of choice situations in which it was chosen, including the outside option) with its posterior-predictive share from predict.choicer_hb(). Large systematic gaps indicate model misfit — e.g. a missing covariate or an outside-option share the delta level cannot rationalize.

Usage

ppc_shares(object, n_draws = 200L)

Arguments

object

A choicer_hmnl or choicer_hmnp fit (with keep_data = TRUE).

n_draws

Posterior draws to integrate over (default 200).

Value

A data.table with columns alternative, observed, predicted, lower, upper (95% posterior-predictive interval), and covered (is the observed share inside the interval).

Examples


sim <- simulate_hmnl_data(N = 100, T = 3, J = 4, seed = 42)
fit <- suppressWarnings(run_hmnlogit(sim$data, "task", "alt", "choice", c("x1", "x2"),
                    person_col = "pid",
                    mcmc = list(R = 500, burn = 200)))
ppc_shares(fit)


choicer documentation built on Sept. 5, 2026, 1:07 a.m.