# NOT RUN {
# Run a MNL model in the Preference Space:
library(logitr)
mnl_pref <- logitr(
data = yogurt,
choiceName = "choice",
obsIDName = "obsID",
parNames = c("price", "feat", "brand")
)
# You can predict choices for any set of alternative, such as hold out
# samples or within-sample. For this example I will predict choices on
# the full yogurt data set, which was used to estimate the model.
# Run the simulation using the preference space MNL model:
choices_mnl_pref <- predictChoices(
model = mnl_pref,
alts = yogurt,
obsIDName = "obsID"
)
head(choices_mnl_pref)
# Compute the accuracy
chosen <- subset(choices, choice == 1)
chosen$correct <- chosen$choice == chosen$choice_predict
sum(chosen$correct) / nrow(chosen)
# }
Run the code above in your browser using DataLab