utilities: Return the the utilities for a set of coefficients

Description Usage Arguments Value Examples

View source: R/utilities.R

Description

Return the the utilities for a set of coefficients

Usage

1
utilities(model_spec, beta, data, availabilities, draws, nDraws)

Arguments

model_spec

The generated model_spec.

beta

The coefficients to use in the model when estimating the utilities.

data

The dataframe of observations.

availabilities

The availabilities of each alternative.

draws

For mixed models, a matrix of draws. If none is provided, one is created.

nDraws

The number of draws to use or generated.

Value

Dataframe of utilties for each observation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
  data("Train", package="mlogit")
  Train$ID <- Train$id
  Train$CHOICE <- as.numeric(Train$choice)
  
  est <- stats::setNames(c(1,1,1,1), c("B_price", "B_time", "B_timeB", "B_change"))
  
  availabilities <- mixl::generate_default_availabilities(Train, 2)
  
  Nindividuals <- length(unique(Train$ID))
  
  utility_script <- "
      U_A = @B_price * $price_A / 1000 + @B_time * $time_A / 60 + @B_change * $change_A;
      U_B = @B_price * $price_B / 1000 + @B_timeB * $time_B / 60 ;
      "
  
  model_spec <- mixl::specify_model(utility_script, Train)
  
  utilities_matrix = mixl::utilities(model_spec, est, Train, availabilities, NULL)
  
  utilities_matrix

mixl documentation built on Dec. 11, 2021, 9:07 a.m.