Once a model has been estimated, it can be used to predict the expected choice probabilities for a set of alternatives. This vignette demonstrates examples of how to so using the predictProbs()
function along with the results of an estimated model.
To predict choice probabilities, you first need to create a set of alternatives where each row is an alternative and each column an attribute. In this example, I use two of the choice observations from the yogurt
dataset (note that if you include more than one set of alternatives you also have to specify an obsID
):
<- subset(
alts %in% c(42, 13),
yogurt, obsID select = c('obsID', 'price', 'feat', 'brand'))
alts#> # A tibble: 8 x 4
#> obsID price feat brand
#> <int> <dbl> <dbl> <chr>
#> 1 13 8.1 0 dannon
#> 2 13 5.00 0 hiland
#> 3 13 8.60 0 weight
#> 4 13 10.8 0 yoplait
#> 5 42 6.30 0 dannon
#> 6 42 6.10 1 hiland
#> 7 42 7.90 0 weight
#> 8 42 11.5 0 yoplait
In the example below, I estimate a preference space MNL model called mnl_pref
. I can then use the predictProbs()
function with the mnl_pref
model to predict the choice probabilities for each set of alternatives in the alts
data frame:
# Estimate the model
<- logitr(
mnl_pref data = yogurt,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('price', 'feat', 'brand')
)
# Predict choice probabilities
<- predictProbs(
probs_mnl_pref model = mnl_pref,
alts = alts,
obsIDName = "obsID",
alpha = 0.025
)
probs_mnl_pref#> obsID prob_mean prob_low prob_high
#> 1 13 0.43684871 0.41564967 0.45746384
#> 2 13 0.03313009 0.02630457 0.04172679
#> 3 13 0.19155738 0.17621753 0.20760195
#> 4 13 0.33846382 0.31891924 0.35883234
#> 5 42 0.60763975 0.57328271 0.64024329
#> 6 42 0.02602079 0.01832816 0.03662558
#> 7 42 0.17803594 0.16244937 0.19462645
#> 8 42 0.18830353 0.16858802 0.20970439
The results show the expected choice probabilities for each alternative. The low and high values show a 95% confidence interval estimated using the Krinsky and Robb parametric bootstrapping method (Krinsky and Robb 1986). You can change the CI level by setting alpha
to a different value (e.g. a 90% CI is obtained with alpha = 0.05
).
You can also use WTP space models to predict choice probabilities. For example, here are the results from an equivalent model but in the WTP space:
# Estimate the model
<- logitr(
mnl_wtp data = yogurt,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('feat', 'brand'),
priceName = 'price',
modelSpace = 'wtp',
options = list(numMultiStarts = 10)
)
# Predict choice probabilities
<- predictProbs(
probs_mnl_wtp model = mnl_wtp,
alts = alts,
obsIDName = "obsID"
)
#> NOTE: Using results from run 8 of 10 multistart runs
#> (the run with the largest log-likelihood value)
probs_mnl_wtp#> obsID prob_mean prob_low prob_high
#> 1 13 0.43686166 0.41506572 0.45761333
#> 2 13 0.03312933 0.02643610 0.04220023
#> 3 13 0.19154885 0.17625793 0.20755838
#> 4 13 0.33846015 0.31885124 0.35911237
#> 5 42 0.60767236 0.57315750 0.63937840
#> 6 42 0.02601763 0.01846952 0.03655337
#> 7 42 0.17802398 0.16233315 0.19459781
#> 8 42 0.18828603 0.16772992 0.20904193
Since these two models are equivalent except in different spaces, the predicted choice probabilities should be the same.
You can also use mixed logit models to predict choice probabilities. Heterogeneity is modeled by simulating draws from the population estimates of the estimated model. Here is an example using a preference space mixed logit model:
# Estimate the model
<- logitr(
mxl_pref data = yogurt,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('price', 'feat', 'brand'),
randPars = c(feat = 'n', brand = 'n'),
options = list(numMultiStarts = 5)
)
# Predict choice probabilities
<- predictProbs(
probs_mxl_pref model = mxl_pref,
alts = alts,
obsIDName = "obsID"
)
probs_mxl_pref#> obsID prob_mean prob_low prob_high
#> 1 13 0.45230084 0.39703786 0.47076409
#> 2 13 0.02782708 0.02264682 0.08857498
#> 3 13 0.21027296 0.18485519 0.22859065
#> 4 13 0.30959912 0.27896091 0.36616171
#> 5 42 0.60391759 0.50214824 0.64955770
#> 6 42 0.06797893 0.02675205 0.14721963
#> 7 42 0.18726035 0.16206753 0.20725423
#> 8 42 0.14084313 0.11351272 0.22501846
Likewise, mixed logit WTP space models can also be used to predict choice probabilities:
# Estimate the model
<- logitr(
mxl_wtp data = yogurt,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('feat', 'brand'),
priceName = 'price',
randPars = c(feat = 'n', brand = 'n'),
modelSpace = 'wtp',
options = list(numMultiStarts = 5)
)
# Predict choice probabilities
<- predictProbs(
probs_mxl_wtp model = mxl_wtp,
alts = alts,
obsIDName = "obsID"
)
probs_mxl_wtp#> obsID prob_mean prob_low prob_high
#> 1 13 0.44040652 0.40372475 0.45646128
#> 2 13 0.02685423 0.02195227 0.06919668
#> 3 13 0.20364898 0.18232507 0.22164466
#> 4 13 0.32909026 0.30601568 0.35808626
#> 5 42 0.58682140 0.52495181 0.62133013
#> 6 42 0.08194992 0.04227496 0.14381618
#> 7 42 0.18187533 0.15878742 0.20195989
#> 8 42 0.14935336 0.12779524 0.19112783
Here is a bar chart comparing the predicted choice probabilities from each model:
library(ggplot2)
library(dplyr)
<- rbind(
probs %>%
probs_mnl_pref, probs_mnl_wtp, probs_mxl_pref, probs_mxl_wtp) mutate(
model = c(rep("mnl_pref", 8), rep("mnl_wtp", 8),
rep("mxl_pref", 8), rep("mxl_wtp", 8)),
alt = rep(c("dannon", "hiland", "weight", "yoplait"), 8),
obs = paste0("Observation ID: ", obsID)
)
ggplot(probs, aes(x = alt, y = prob_mean, fill = model)) +
geom_bar(stat = 'identity', width = 0.7, position = "dodge") +
geom_errorbar(aes(ymin = prob_low, ymax = prob_high),
width = 0.2, position = position_dodge(width = 0.7)) +
facet_wrap(vars(obs)) +
scale_y_continuous(limits = c(0, 1)) +
labs(x = 'Alternative', y = 'Expected Choice Probabilities') +
theme_bw()