| predict.choicer_hb | R Documentation |
Computes counterfactual choice probabilities, integrating over the
posterior draws and (at the population level) over the random-coefficient
distribution: for each kept draw (b_r, W_r, \delta_r, \ldots) one
\beta \sim N(b_r, W_r) is drawn and the model probabilities are
averaged. Alternatives in newdata that were not in the estimation
sample receive a posterior-predictive
\delta_{new} \sim N(z_{new}'\theta_r, \sigma_{d,r}^2) — the entry
counterfactual unlocked by the random-effects \delta. Price or
subsidy counterfactuals are just modified covariate columns in newdata.
## S3 method for class 'choicer_hb'
predict(
object,
newdata = NULL,
level = c("population", "individual"),
n_draws = 200L,
aggregate = TRUE,
...
)
object |
A |
newdata |
Data frame with the estimation columns (choice column not
required). |
level |
|
n_draws |
Number of posterior draws to integrate over (thinned evenly from the kept draws; default 200). |
aggregate |
If |
... |
Ignored. |
HMNL probabilities are closed-form logit; HMNP probabilities use the
1-D Gauss-Hermite representation of the iid-probit integral
P(j) = \int \phi(u) \prod_{k \ne j} \Phi(V_j - V_k + u) du.
With aggregate = TRUE, a data.table with columns
alternative, share (posterior mean), sd, lower, upper (95%
equal-tailed interval); the posterior share draws are attached as
attr(, "draws"). With aggregate = FALSE, a numeric vector of
posterior-mean choice probabilities, one per prediction row.
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", alt_covariate_cols = "z1",
mcmc = list(R = 500, burn = 200)))
predict(fit) # posterior shares, estimation data
cf <- sim$data
cf$x1 <- cf$x1 + 0.5 # a counterfactual attribute change
predict(fit, newdata = cf)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.