predict.logitr | R Documentation |
This method is used for computing predicted probabilities and / or outcomes for either the data used for model estimation or a new data set consisting of a single or multiple sets of alternatives.
## S3 method for class 'logitr'
predict(
object,
newdata = NULL,
obsID = NULL,
type = "prob",
returnData = FALSE,
interval = "none",
level = 0.95,
numDrawsCI = 10^4,
pars = NULL,
scalePar = NULL,
randPars = NULL,
randScale = NULL,
ci,
...
)
object |
is an object of class |
newdata |
a |
obsID |
The name of the column that identifies each set of
alternatives in the data. Required if newdata != NULL. Defaults to |
type |
A character vector defining what to predict: |
returnData |
If |
interval |
Type of interval calculation: "none" (default) or "confidence". Future versions will include "prediction" intervals as well. |
level |
Tolerance / confidence interval. Defaults to 0.95. |
numDrawsCI |
The number of draws to use in simulating uncertainty for the computed CI. Defaults to 10^4. |
pars |
The names of the parameters to be estimated in the model.
Must be the same as the column names in the |
scalePar |
The name of the column that identifies the scale variable,
which is typically "price" for WTP space models, but could be any
continuous variable, such as "time". Defaults to |
randPars |
A named vector whose names are the random parameters and
values the distribution: |
randScale |
The random distribution for the scale parameter: |
ci |
No longer used as of v1.1.0 - if provided, this is passed
to the |
... |
further arguments. |
A data frame of predicted probabilities and / or outcomes.
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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.