Learn R Programming

mixl (version 1.3.4)

probabilities: Calculate the probabilities for a specified and estimated model. Note that if new data or draws are provided, the model will not be re-estimated

Description

Calculate the probabilities for a specified and estimated model. Note that if new data or draws are provided, the model will not be re-estimated

Usage

probabilities(
  model,
  data = NULL,
  availabilities = NULL,
  draws = NULL,
  nDraws = NULL,
  num_threads = 1
)

Value

Dataframe of individual-level posteriors

Arguments

model

The estimated Model

data

(Optional) New data to use instead of that in the dataset

availabilities

(Optional) New availabilites to use

draws

(Optional) Optional new set of random draws to use

nDraws

(Optional) Optional new number of random draws to use

num_threads

Enable parallel computing where available using this many cores

Examples

Run this code
# \donttest{
	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)
	probabilities(model)

	#hypothetical scenario where the travel time of option A doubles
	Train$time_A = Train$time_A * 2
	probabilities(model, Train)
# }

Run the code above in your browser using DataLab