Learn R Programming

apollo (version 0.1.0)

apollo_mnl: Calculates multinomial logit probabilities

Description

Calculates probabilities of a multinomial logit model.

Usage

apollo_mnl(mnl_settings, functionality)

Arguments

mnl_settings

List of inputs of the MNL model. It should contain the following.

  • alternatives: Named numeric vector. Names of alternatives and their corresponding value in choiceVar.

  • avail: Named list of numeric vectors or scalars. Availabilities of alternatives, one element per alternative. Names of elements must match those in alternatives. Values can be 0 or 1.

  • choiceVar: Numeric vector. Contains choices for all observations. It will usually be a column from the database. Values are defined in alternatives.

  • V: Named list of deterministic utilities . Utilities of the alternatives. Names of elements must match those in alternatives.

  • rows: Boolean vector. Consideration of rows in the likelihood calculation, FALSE to exclude. Length equal to the number of observations (nObs). Default is "all", equivalent to rep(TRUE, nObs).

  • componentName: Character. Name given to model component.

functionality

Character. Can take different values depending on desired output.

  • "estimate": Used for model estimation.

  • "prediction": Used for model predictions.

  • "validate": Used for validating input.

  • "zero_LL": Used for calculating null likelihood.

  • "conditionals": Used for calculating conditionals.

  • "output": Used for preparing output after model estimation.

  • "raw": Used for debugging.

Value

The returned object depends on the value of argument functionality as follows.

  • "estimate": vector/matrix/array. Returns the probabilities for the chosen alternative for each observation.

  • "prediction": List of vectors/matrices/arrays. Returns a list with the probabilities for all alternatives, with an extra element for the probability of the chosen alternative.

  • "validate": Same as "estimate", but it also runs a set of tests to validate the function inputs.

  • "zero_LL": vector/matrix/array. Returns the probability of the chosen alternative when all parameters are zero.

  • "conditionals": Same as "estimate"

  • "output": Same as "estimate" but also writes summary of input data to internal Apollo log.

  • "raw": Same as "prediction"

Examples

Run this code
# NOT RUN {
### Load data
data(apollo_modeChoiceData)
database <- apollo_modeChoiceData
rm(apollo_modeChoiceData)

### Parameters
b = list(asc_1=0, asc_2=0, asc_3=0, asc_4=0, tt=0, tc=0, acc=0)

### List of utilities
V = list()
V[['car' ]] = b$asc_1 + b$tt*database$time_car  + b$tc*database$cost_car
V[['bus' ]] = b$asc_2 + b$tt*database$time_bus  + b$tc*database$cost_bus  +
              b$acc*database$access_bus
V[['air' ]] = b$asc_3 + b$tt*database$time_air  + b$tc*database$cost_air  +
              b$acc*database$access_air
V[['rail']] = b$asc_4 + b$tt*database$time_rail + b$tc*database$cost_rail +
              b$acc*database$access_rail

### MNL settings
mnl_settings <- list(
   alternatives = c(car=1, bus=2, air=3, rail=4),
   avail        = list(car=database$av_car, bus=database$av_bus,
                       air=database$av_air, rail=database$av_rail),
   choiceVar    = database$choice,
   V            = V
)

### Compute choice probabilities using MNL model
apollo_mnl(mnl_settings, functionality="estimate")
# }

Run the code above in your browser using DataLab