| choice_data | R Documentation |
The choice_data object defines the choice data, it is a combination of
choice_responses and choice_covariates.
choice_data(
data_frame,
format = "wide",
column_choice = "choice",
column_decider = "deciderID",
column_occasion = NULL,
column_alternative = NULL,
column_ac_covariates = NULL,
column_as_covariates = NULL,
delimiter = "_",
cross_section = is.null(column_occasion),
choice_type = c("discrete", "ordered", "ranked")
)
generate_choice_data(
choice_effects,
choice_identifiers = generate_choice_identifiers(N = 100),
choice_covariates = NULL,
choice_parameters = NULL,
choice_preferences = NULL,
column_choice = "choice",
choice_type = c("auto", "discrete", "ordered", "ranked")
)
long_to_wide(
data_frame,
column_ac_covariates = NULL,
column_as_covariates = NULL,
column_choice = "choice",
column_alternative = "alternative",
column_decider = "deciderID",
column_occasion = NULL,
alternatives = unique(data_frame[[column_alternative]]),
delimiter = "_",
choice_type = c("discrete", "ordered", "ranked")
)
wide_to_long(
data_frame,
column_choice = "choice",
column_alternative = "alternative",
alternatives = NULL,
delimiter = "_",
choice_type = c("discrete", "ordered", "ranked")
)
data_frame |
[ |
format |
[ |
column_choice |
[ |
column_decider |
[ |
column_occasion |
[ |
column_alternative |
[ |
column_ac_covariates |
[ |
column_as_covariates |
[ |
delimiter |
[ |
cross_section |
[ |
choice_type |
[ |
choice_effects |
[ |
choice_identifiers |
[ |
choice_covariates |
[ |
choice_parameters |
[ |
choice_preferences |
[ |
alternatives |
[ |
choice_data() acts as the main entry point for observed data. It accepts
either long or wide layouts and performs validation before
returning a tidy tibble with consistent identifiers. Columns that refer to
the same alternative are aligned using delimiter so that downstream helpers
can detect them automatically. When used with ranked or ordered choices the
function checks that rankings are complete and warns about inconsistencies.
Internally the helper converts long inputs to wide format. This guarantees that subsequent steps (such as computing probabilities) receive the same structure regardless of the original layout and keeps the workflow concise.
generate_choice_data() simulates choice data.
wide_to_long() and long_to_wide() transform to wide and long format.
The generated choice_data object inherits a choice_type attribute for
the requested simulation mode. Ordered alternatives (ordered = TRUE)
yield ordered responses, unordered alternatives default to discrete
multinomial outcomes, and ranked simulations return complete rankings for
every observation.
A tibble that inherits from choice_data.
choice_responses(), choice_covariates(), and choice_identifiers() for
the helper objects that feed into choice_data().
### simulate data from a multinomial probit model
choice_effects <- choice_effects(
choice_formula = choice_formula(
formula = choice ~ A | B, error_term = "probit",
random_effects = c("A" = "cn")
),
choice_alternatives = choice_alternatives(J = 3)
)
generate_choice_data(choice_effects)
### transform between long/wide format
long_to_wide(
data_frame = travel_mode_choice,
column_alternative = "mode",
column_decider = "individual"
)
wide_to_long(
data_frame = train_choice
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.