| predict.choicer_mxl | R Documentation |
Computes simulated choice probabilities or aggregate market shares using
deterministic Halton draws, either for the data used at fit time (default)
or for counterfactual newdata.
## S3 method for class 'choicer_mxl'
predict(
object,
type = c("probabilities", "shares"),
newdata = NULL,
weights = NULL,
...
)
object |
A choicer_mxl object. |
type |
Either "probabilities" (per-observation simulated choice probabilities) or "shares" (aggregate simulated market shares). |
newdata |
Optional data for counterfactual prediction. Either:
When |
weights |
Optional numeric vector with one weight per choice situation,
used for |
... |
Additional arguments (ignored). |
For "probabilities": a list with choice_prob and utility
vectors averaged across simulation draws. For "shares": a named numeric
vector of simulated market shares per alternative. With a data.frame
newdata, rows are ordered by id, then by fit-time alternative code
(alt_int in object$alt_mapping).
library(data.table)
set.seed(42)
N <- 50; J <- 3
dt <- data.table(id = rep(1:N, each = J), alt = rep(1:J, N))
dt[, `:=`(x1 = rnorm(.N), w1 = rnorm(.N))]
dt[, choice := 0L]
dt[, choice := sample(c(1L, rep(0L, J - 1))), by = id]
fit <- run_mxlogit(
data = dt, id_col = "id", alt_col = "alt", choice_col = "choice",
covariate_cols = "x1", random_var_cols = "w1", S = 50L
)
predict(fit, type = "shares")
predict(fit, type = "probabilities")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.