Skip to contents

This function takes the experiment_data result of list_tidy_data() which contains list experiment variables and runs a specified model for list experiment. If you need the break (demographic) variables or the weight variable, you need to join it to the experiment_data data.frame. Variable containing weights should have weights name. For multiple bundles you can use list_model_bulk() wrapper which takes the results of the list_tidy_data_bulk() and run the models using Kubernetes.

Usage

list_model_bulk(data, seed = 666, file_prefix, path = "models", ...)

list_model(data, model = c("g6trliststan"), seed = NULL, ...)

Arguments

data

Results of list_tidy_data() (for single bundle) or list_tidy_data_bulk() (for multiple bundles).

seed

Set seed for reproducible modeling.

file_prefix

A prefix that will be added to the output files. All the output files of the models will end with bundle_x.rds.

path

A path to directory where models will be stored. Default "models".

...

Arguments passed to rstan::sampling() (e.g. iter, chains).

model

Name of Stan model that will be used to calculate List Experiment. One of: g6trliststan.

Value

A list with an object of class stanfit returned by rstan::sampling() and vector of predictors.

Examples

if (FALSE) { # \dontrun{
library("dplyr")
data("list_experiment_toy")

## Create a data frame with demographic variables
### We select 3 categorical variables as demographic breaks and one artificial
### numeric variable just for the purpose of demonstration.

demo_toy <- list_experiment_toy %>%
  select("response_id", "d_party", "s_gender", "s_region") %>%
  mutate(num_var = rnorm(nrow(.), 3, 0.4))

## Tidy the asserted data
### We can run read %>% assert %>% tidy in pipe to make code
### more compact.

le_tidy_data <- list_read_data_bulk(list_experiment_toy, "response_id") %>%
  list_assert_data_bulk(demo_toy, id = "response_id", n_items = 4L) %>%
  list_tidy_data_bulk(id = response_id)

## Run Models
### We use output of tidy data as list_model() input, and additionally add 
### some rstan::sampling arguments to save time on execution.

model_output <- list_model(
  le_tidy_data[[2]], model = "g6trliststan", seed = 666,
  iter = 400, cores = 2, chains = 2
)
###!!! TEMPORARLY UNAVAILABLE !!!###
### Usually there is a lot of bundles in our dataset. Since the models are
### greedy for resources, we can run them on *Kubernetes*. To use this path
### you can run list_model_bulk() function that will handle everything for
### you. This function has two additional parameters: file_prefix which stores
### the prefix that will be added to files storing modeling results, and path
### which points the function where to store the files (default "models").

list_model_bulk(
  le_tidy_data, seed = 666, 
  file_prefix = "list_model_toy", path = "models", 
  iter = 400, cores = 2, chains = 2
)
} # }