library(logitr)
# Estimate a preference space model
mnl_pref <- logitr(
data = yogurt,
outcome = "choice",
obsID = "obsID",
pars = c("price", "feat", "brand")
)
# Predict probabilities and / or outcomes
# Predict probabilities for each alternative in the model data
probs <- predict(mnl_pref)
head(probs)
# Create a set of alternatives for which to make predictions.
# Each row is an alternative and each column an attribute.
data <- subset(
yogurt, obsID %in% c(42, 13),
select = c('obsID', 'alt', 'price', 'feat', 'brand'))
data
# Predict probabilities using the estimated model
predict(mnl_pref, newdata = data, obsID = "obsID")
# Predict probabilities and include a 95% confidence interval
predict(
mnl_pref,
newdata = data,
obsID = "obsID",
interval = "confidence",
level = 0.95
)
# Predict outcomes
predict(mnl_pref, newdata = data, obsID = "obsID", type = "outcome")
# Predict outcomes and probabilities
predict(mnl_pref, newdata = data, obsID = "obsID", type = c("prob", "outcome"))
Run the code above in your browser using DataLab