specify_model: Validate the utility functions against the dataset and...

Description Usage Arguments Value See Also Examples

View source: R/compiler.R

Description

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.

Usage

1
2
3
4
5
6
7
8
9
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

Value

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

See Also

browseVignettes("mixl")

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.