choice_probabilities: Define choice probabilities

View source: R/choice_probabilities.R

choice_probabilitiesR Documentation

Define choice probabilities

Description

The choice_probabilities object defines the choice probabilities.

  • compute_choice_probabilities() calculates the choice probabilities based on the choice parameters and the choice data.

Usage

choice_probabilities(
  data_frame,
  choice_only = TRUE,
  column_decider = "deciderID",
  column_occasion = NULL,
  cross_section = FALSE,
  column_probabilities = if (choice_only) "choice_probability"
)

compute_choice_probabilities(
  choice_parameters,
  choice_data,
  choice_effects,
  choice_only = FALSE,
  input_checks = TRUE,
  ...
)

Arguments

data_frame

[data.frame]
Contains the choice probabilities.

choice_only

[logical(1)]
Only the probabilities for the chosen alternatives?

column_decider

[character(1)]
The name of the identifier column for deciders.

column_occasion

[character(1) | NULL]
The name of the identifier column for choice occasions (panel data). Can be NULL for the cross-sectional case.

cross_section

[logical(1)]
Treat choice data as cross-sectional?

column_probabilities

[character()]
The column name of the data_frame with the choice probabilities for all choice alternatives.

If choice_only = TRUE, it is the name of a single column that contains the probabilities for the chosen alternatives.

choice_parameters

[choice_parameters | list]
Either a choice_parameters object or a list in optimization space as returned by switch_parameter_space.

choice_data

[choice_data]
A choice_data object providing responses and covariates.

choice_effects

[choice_effects]
A choice_effects object defining the specification.

input_checks

[logical(1)]
Should additional internal input checks be performed before computing the probabilities?

...

Passed to the underlying probability computation routine.

Value

A choice_probabilities S3 object (a data frame) that stores additional metadata in attributes such as column_probabilities, choice_only, and the identifier columns. These attributes are used by downstream helpers to reconstruct the original structure.

Examples

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_parameters <- generate_choice_parameters(choice_effects)
choice_data <- choice_data(
  data_frame = train_choice,
  format = "wide",
  column_choice = "choice",
  column_decider = "deciderID",
  column_occasion = "occasionID"
)
compute_choice_probabilities(
  choice_parameters = choice_parameters,
  choice_data = choice_data,
  choice_effects = choice_effects,
  choice_only = TRUE
)

choicedata documentation built on Nov. 5, 2025, 5:46 p.m.