Skip to contents

This function simulates the probability that a given ranking permutation pattern is chosen over a random effect variable. The function is based on the sim function from the clarify package as well as the mlogit package, and designed to work with mlogit objects.

Usage

sim_rank(
  m,
  permn,
  random_var = NULL,
  newdata = NULL,
  range_cont = NULL,
  conf_level = 0.95,
  seed = NULL,
  n = 1000,
  vcov = NULL,
  coefs = NULL,
  dist = NULL
)

Arguments

m

An mlogit object.

permn

A permutation pattern that is being checked over a combination of variables.

random_var

A character string that specifies the random effect variable. Default is NULL.

newdata

A data frame that contains the new data to be used for prediction. Default is NULL. You cannot specify both random_var and newdata and must pick one.

range_cont

A vector that specifies the range of the random effect variable to be visualized/simulated.

conf_level

A numeric value that specifies the confidence level of the confidence interval. The default is 0.95.

seed

An integer that specifies the seed for the random number. Default is NULL.

n

An integer that specifies the number of simulations. Defaults to 1,000.

vcov

Argument for clarify::sim. The default is NULL.

coefs

Argument for clarify::sim. The default is NULL.

dist

Argument for clarify::sim. The default is NULL.

Value

A data frame that contains the mean, lower bound, and upper bound of the probability that a given ranking permutation pattern is chosen over a random effect variable's values.

Examples


## This model does not mean *anything.*
## This is simply to demonstrate the function.
library(mlogit)
#> Loading required package: dfidx
#> 
#> Attaching package: ‘dfidx’
#> The following object is masked from ‘package:stats’:
#> 
#>     filter
library(dfidx)

data("Fishing", package = "mlogit")
Fish <- dfidx(Fishing, varying = 2:9, shape = "wide", choice = "mode")
m1 <- mlogit(mode ~ 1 | price, reflevel = "beach", data = Fish)

sim_rank_randeff(
  m = m1,
  permn = c("charter", "boat", "pier", "beach"),
  random_var = "price",
  range_cont = c(10, 50, 100),
  seed = 123
)
#> # A tibble: 3 × 5
#>   price   mean    low  high ranking                
#>   <dbl>  <dbl>  <dbl> <dbl> <chr>                  
#> 1    10 0.170  0.140  0.201 charter_boat_pier_beach
#> 2    50 0.166  0.145  0.188 charter_boat_pier_beach
#> 3   100 0.0854 0.0638 0.109 charter_boat_pier_beach