probabilities: Calculate the probabilities for a specified and estimated...

Description Usage Arguments Value Examples

View source: R/probabilities.R

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

1
2
3
4
5
6
7
8
probabilities(
  model,
  data = NULL,
  availabilities = NULL,
  draws = NULL,
  nDraws = NULL,
  num_threads = 1
)

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

Value

Dataframe of individual-level posteriors

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
	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)

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