specify_model function

Validate the utility functions against the dataset and generate the optimised logliklihood function

Validate the utility functions against the dataset and generate the optimised logliklihood function

This function takes a utility function description, and generates a optimised C++ version of the utility function which can be called from R. If the data_names are provided, then the variables in the function are checked against those provided. If an output_file is provided, the C++ code is saved there. See the user guide vignette for how to write valid utility scripts. There is some minimal specific syntax required.

specify_model( utility_script, dataset = NULL, output_file = NULL, compile = TRUE, model_name = "mixl_model", disable_multicore = T, ... )

Arguments

  • utility_script: The utility script to be compiled
  • dataset: An (optional) dataframe to check if the all the variables are present
  • output_file: An (optional) location where the compiled code should be saved (useful for debugging
  • compile: If compile is false, then the code will not be compiled, but just validated and saved if an output_file is specified. Default is true.
  • model_name: A name for the model, which will be used for saving. Defaults to mixl_model
  • disable_multicore: Depreciated and not used. Mutlicore is now autodetected
  • ...: Further parameters to pass to sourceCpp

Returns

An object which contains the loglikelihood function, and information from the compile process

Examples

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)

See Also

browseVignettes("mixl")

  • Maintainer: Joseph Molloy
  • License: GPL (>= 2)
  • Last published: 2024-02-07