prepare: Prepare empirical choice data.

Description Usage Arguments Details Value Examples

View source: R/prepare.R

Description

This function prepares empirical choice data for the RprobitB package.

Usage

1
2
3
4
5
6
7
8
9
prepare(
  form,
  choice_data,
  alternatives = NULL,
  re = NULL,
  id = "id",
  standardize = NULL,
  test_prop = NULL
)

Arguments

form

A formula object that is used to specify the probit model. The structure is choice ~ A | B | C, where

  • A are names of alternative and choice situation specific covariates with a generic coefficient,

  • B are names of choice situation specific covariates with alternative specific coefficients,

  • and C are names of alternative and choice situation specific covariates with alternative specific coefficients.

Separate multiple covariates of one type by a + sign. By default, alternative specific constants (ASCs) are added to the model (for all except for the last alternative). They can be removed by adding +0 in the second spot. See the vignette vignette("data_management", package = "RprobitB") for more details.

choice_data

A data frame of choice data in "wide" format (i.e. each row represents one choice occasion) with the following requirements:

  • It must contain a column named id which contains unique identifier for each decision maker.

  • It can contain a column named choice with the observed choices, where choice must match the name of the dependent variable in form. Such a column is required for model fitting but not for prediction.

  • For each alternative specific covariate p in form and each choice alternative j in alternatives, choice_data must contain a column named p_j.

  • For each covariate q in form that is constant across alternatives, choice_data must contain a column named q.

alternatives

A character vector with the names of the choice alternatives. If not specified, the choice set is defined by the observed choices.

re

A character (vector) of covariates of form with random effects. If re = NULL (the default), there are no random effects. To have random effects for the alternative specific constants, include "ASC" in re.

id

A character, the name of the column in choice_data that contains unique identifier for each decision maker. The default is "id".

standardize

A character vector of names of covariates that get standardized. Covariates of type 1 or 3 have to be addressed by <covariate>_<alternative>. If standardize = "all", all covariates get standardized.

test_prop

Either NULL or a numeric between 0 and 1. In the latter case, the data is split into a training set (of decider proportion 1-test_prop) and a testing set (of decider proportion test_prop).

Details

See the vignette "Data management" for more details: vignette("data_management", package = "RprobitB").

Value

An object of class RprobitB_data. If test_prop is specified, a list of two RprobitB_data objects labelled "train" and "test".

Examples

1
2
3
4
data("Train", package = "mlogit")
data = prepare(form = choice ~ price | 0 | time + comfort + change,
               choice_data = Train, re = c("price","time"),
               standardize = "all")

RprobitB documentation built on Nov. 12, 2021, 5:08 p.m.