estimate: Runs a maximum likelihood estimation on a mixl choice model

Description Usage Arguments Details Value Examples

Description

This function performs a maximum likelihood estimation for choice models speficied using this package.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
estimate(
  model_spec,
  start_values,
  data,
  availabilities,
  draws = NULL,
  nDraws = NULL,
  fixedparam = c(),
  num_threads = 1,
  ...
)

Arguments

model_spec

The object that contains the loglikelihood function and other variables that help return better error messages. This function is best generated using the specify_model() function.

start_values

A named vector of start values for the estimation. A warning and error will be given respectively if to many values are included or some are missing.

data

A dataframe of the observations. It must include The columns CHOICE and ID, as well as columns for the variables specified in the utility function. The CHOICE variable must be from 1..k, where k is the number of utility functions

availabilities

A 1/0 matrix of availabilities. The dimensions must be nrows(data) * k, where there are k utility functions.

draws

A numeric matrix of draws for calculating mixed effects. If there no mixed effects, this should be left null. If the model specification included mixed effects, either this or nDraws need to be specified.

nDraws

The number of draws to use in estimating a mixed model. Only needed if draws is left null. Then a matrix of normal halton draws will be generated.

fixedparam

(optional) Coefficients which should be fixed to their starting values during estimation.

num_threads

The maximum number of parallel cores to use in estimation. The default is 1. This should only be speficied on machines with an openMP compiler (linux and some OSXs).

...

futher arguments. such as control are passed to the maximisaiton routine in maxLik. See maxLik::maxLik() for more details

Details

It is a wrapper for the maxLik function in the maxLik package. And additional arguments can be passed through to this function if required.

Value

a mixl object that contains the results of the estimation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
	data("Train", package="mlogit")
	Train$ID <- Train$id
	Train$CHOICE <- as.numeric(Train$choice)
	    
	mnl_test <- "
	U_A = @B_price * $price_A / 1000 + @B_time * $time_A / 60;
	U_B = @asc + @B_price * $price_B / 1000 + @B_timeB * $time_B / 60;
	"

	model_spec <- mixl::specify_model(mnl_test, Train, disable_multicore=T)

	#only take starting values that are needed
	est <- stats::setNames(c(1, 1,1,1), c("asc", "B_price", "B_time", "B_timeB"))
	availabilities <- mixl::generate_default_availabilities(
		Train, model_spec$num_utility_functions)

	model <- mixl::estimate(model_spec, est, Train, availabilities = availabilities)
	print(model)

mixl documentation built on Oct. 23, 2020, 7:28 p.m.