library(logitr)
# Estimate a preference space model
mnl_pref <- logitr(
data = yogurt,
outcome = "choice",
obsID = "obsID",
pars = c("price", "feat", "brand")
)
# Create a set of alternatives for which to simulate probabilities
# (Columns are attributes, rows are alternatives)
data <- data.frame(
altID = c(1, 2, 3, 4),
obsID = c(1, 1, 1, 1),
price = c(8, 6, 7, 10),
feat = c(0, 1, 0, 0),
brand = c('dannon', 'hiland', 'weight', 'yoplait')
)
# Obtain 10,000 draws of parameters from model
coefs <- coef(mnl_pref)
covariance <- vcov(mnl_pref)
coef_draws <- as.data.frame(MASS::mvrnorm(10^4, coefs, covariance))
# Compute the probabilities
sim <- logit_probs(
mnl_pref,
coef_draws = coef_draws,
newdata = data,
obsID = 'obsID',
level = 0.95
)
Run the code above in your browser using DataLab