View source: R/choice_likelihood.R
| choice_likelihood | R Documentation |
These functions prepare and evaluate the likelihood contribution of observed choices for a given choice model.
choice_likelihood() pre-computes the design matrices and choice indices
implied by choice_data and choice_effects. The returned object stores
these quantities so that repeated likelihood evaluations during maximum
likelihood estimation avoid redundant work.
compute_choice_likelihood() evaluates the (log-)likelihood for given
choice_parameters. It can either take the original choice objects or a
pre-computed choice_likelihood object.
choice_likelihood(
choice_data,
choice_effects,
choice_identifiers = extract_choice_identifiers(choice_data),
input_checks = TRUE,
lower_bound = 1e-10,
...
)
compute_choice_likelihood(
choice_parameters,
choice_data,
choice_effects,
logarithm = TRUE,
negative = FALSE,
lower_bound = 1e-10,
input_checks = TRUE,
...
)
choice_data |
[ |
choice_effects |
[ |
choice_identifiers |
[ |
input_checks |
[ |
lower_bound |
[ |
... |
Additional arguments passed to |
choice_parameters |
[ |
logarithm |
[ |
negative |
[ |
choice_likelihood() returns an object of class choice_likelihood, which
is a list containing the design matrices, the choice indices, and the
identifiers. compute_choice_likelihood() returns a single numeric value
with the (negative) log-likelihood or likelihood, depending on logarithm
and negative.
data(train_choice)
choice_effects <- choice_effects(
choice_formula = choice_formula(
formula = choice ~ price | time,
error_term = "probit"
),
choice_alternatives = choice_alternatives(
J = 2, alternatives = c("A", "B")
)
)
choice_data <- choice_data(
data_frame = train_choice,
format = "wide",
column_choice = "choice",
column_decider = "deciderID",
column_occasion = "occasionID"
)
likelihood <- choice_likelihood(
choice_data = choice_data,
choice_effects = choice_effects
)
choice_parameters <- generate_choice_parameters(choice_effects)
compute_choice_likelihood(
choice_parameters = choice_parameters,
choice_data = likelihood,
choice_effects = choice_effects,
logarithm = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.