inst/doc/v02_choice_data.R

## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "img/",
  fig.align = "center",
  fig.dim = c(8, 6), 
  out.width = "75%"
)
library("RprobitB")
options("RprobitB_progress" = FALSE)

## ---- overview-Train-data-----------------------------------------------------
data("Train", package = "mlogit")
str(Train)

## ---- train-formula-----------------------------------------------------------
form <- choice ~ price + time + comfort + change | 0

## ---- train-re----------------------------------------------------------------
re <- c("price","time")

## ---- eval = FALSE------------------------------------------------------------
#  data <- prepare_data(form = form, choice_data = choice_data)

## ---- prepare-Train-----------------------------------------------------------
data <- prepare_data(form = form, choice_data = Train, re = re, id = "id", idc = "choiceid")

## ---- summary-Train-----------------------------------------------------------
summary(data)
plot(data)

## ---- eval = FALSE------------------------------------------------------------
#  data <- simulate_choices(form = form, N = N, T = T, J = J)

## ---- data-sim-meta-----------------------------------------------------------
N <- 100
T <- 10
alternatives <- c("A", "B")
base <- "B"
form <- choice ~ var1 | var2 | var3
re <- c("ASC", "var2")

## ---- data-sim-overview-------------------------------------------------------
overview_effects(form = form, re = re, alternatives = alternatives, base = base)

## ---- data-sim----------------------------------------------------------------
data <- simulate_choices(
  form = form, 
  N = N, 
  T = T, 
  J = 2, 
  re = re, 
  alternatives = alternatives, 
  seed = 1,
  true_parameter = list(
    alpha = c(-1,0,1),
    b = matrix(c(2,-0.5), ncol = 1)
  )
)
summary(data)

## ---- data-plot-by-choice-----------------------------------------------------
plot(data, by_choice = TRUE)

## ---- data-split-deciders-----------------------------------------------------
train_test(data, test_proportion = 0.3, by = "N")

## ---- data-split-occasions----------------------------------------------------
train_test(data, test_number = 2, by = "T", random = TRUE, seed = 1)

Try the RprobitB package in your browser

Any scripts or data that you put into this service are public.

RprobitB documentation built on Nov. 10, 2022, 5:12 p.m.