Skip to contents
library("g6tr.list")
library("dplyr")
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
data("list_experiment_toy")

List Experiment Workflow

Getting started

To begin, we’ll tackle reading the list experiment data. We’ve incorporated specific criteria into our functions for obtaining column names of all responses. Initially, the list_read_data() function scans the raw dataset for three patterns: _list_X_bundle, _list_X_direct, and _list_X_bundle, where X denotes a bundle number. A bundle represents a single list experiment. As surveys often include multiple list experiments, the bundle number helps correlate responses to respective tasks.

It’s crucial to provide the id column name to the list_read_data() function. This parameter can be quoted or unquoted and should also be supplied to the list_assert_data() and list_tidy_data() functions.

Example:

# Variables in example dataset
names(list_experiment_toy)
#>  [1] "response_id"      "m1_list_1_group"  "m1_list_1_bundle" "m1_list_1_direct"
#>  [5] "m1_list_2_group"  "m1_list_2_bundle" "m1_list_2_direct" "m1_list_3_group" 
#>  [9] "m1_list_3_bundle" "m1_list_3_direct" "d_party"          "s_gender"        
#> [13] "s_region"         "s_race"           "weights"

# How the raw variables look
list_experiment_toy %>% 
  select(contains("_list_")) %>%
  head()
#> # A tibble: 6 × 9
#>   m1_list_1_group m1_list_1_bundle m1_list_1_direct            m1_list_2_group
#>             <dbl> <dbl+lbl>        <dbl+lbl>                             <dbl>
#> 1               0 7 [4]            1 [Agree]                                 0
#> 2               0 4 [1]            4 [Disagree]                              0
#> 3               1 5 [2]            5 [Don’t know / No opinion]               1
#> 4               1 4 [1]            1 [Agree]                                 1
#> 5               0 6 [3]            4 [Disagree]                              0
#> 6               0 4 [1]            4 [Disagree]                              0
#> # ℹ 5 more variables: m1_list_2_bundle <dbl+lbl>, m1_list_2_direct <dbl+lbl>,
#> #   m1_list_3_group <dbl>, m1_list_3_bundle <dbl+lbl>,
#> #   m1_list_3_direct <dbl+lbl>

list_data <- list_read_data_bulk(data = list_experiment_toy, id = response_id)

# Result of reading
list_data %>% lapply(head, 5)
#> $bundle_1
#> # A tibble: 5 × 4
#>   response_id       group le_response le_direct              
#>   <chr>             <dbl>       <int> <fct>                  
#> 1 R_3hmU6JnwqHTdM4K     0           4 agree                  
#> 2 R_1iqZhVMAC7wE5vE     0           1 disagree               
#> 3 R_3GrhDcnGpsy0YmA     1           2 don’t know / no opinion
#> 4 R_20OPJhnGqVxdrRD     1           1 agree                  
#> 5 R_1MNckiiUwazy18h     0           3 disagree               
#> 
#> $bundle_2
#> # A tibble: 5 × 4
#>   response_id       group le_response le_direct
#>   <chr>             <dbl>       <int> <fct>    
#> 1 R_3hmU6JnwqHTdM4K     0           0 disagree 
#> 2 R_1iqZhVMAC7wE5vE     0           3 disagree 
#> 3 R_3GrhDcnGpsy0YmA     1           3 disagree 
#> 4 R_20OPJhnGqVxdrRD     1           4 agree    
#> 5 R_1MNckiiUwazy18h     0           2 agree    
#> 
#> $bundle_3
#> # A tibble: 5 × 4
#>   response_id       group le_response le_direct              
#>   <chr>             <dbl>       <int> <fct>                  
#> 1 R_3hmU6JnwqHTdM4K     0           4 agree                  
#> 2 R_1iqZhVMAC7wE5vE     0           1 disagree               
#> 3 R_3GrhDcnGpsy0YmA     1           2 don’t know / no opinion
#> 4 R_20OPJhnGqVxdrRD     1           1 agree                  
#> 5 R_1MNckiiUwazy18h     0           3 disagree

As seen above, more than 15 variables have been condensed into relevant ones for the list experiment. Each bundle is now stored as a separate list element. Raw variables suffixed with _list_X_bundle are transformed into the proper numeric le_response variable, with values from raw variable value labels. The group variable takes a value of 1 if the respondent addressed treatment questions (_list_X_group == 1), or 0 for control questions (_list_X_group == 0). The variable suffixed with _list_X_direct becomes le_direct, with values extracted from raw value labels.

Asserting the Data

In the next step, a series of checks is performed to ensure the data we model is accurate. Besides data from list experiments, demographic data is also required. This demographic data serves as predictors in the STAN model. While categorical variables are commonly used, continuous variables are also accepted by the model.

Example:

# We select 3 categorical variables as demographic breaks and one artificial
# numeric variable just for the purpose of demonstration.
demo_toy <- list_experiment_toy[1:300, ] %>%
  select(response_id, d_party, s_gender, s_region) %>%
  mutate(num_var = rnorm(nrow(.), 3, 0.4))

# First we need to read List Experiment data and pass the results
# to list_assert_data_bulk() along with demo data.
le_data_toy <- list_read_data_bulk(list_experiment_toy[1:300, ], "response_id")
list_data_asserted <- list_assert_data_bulk(
  le_data_toy, demo_toy, "response_id", 4L
)
#> 
#> ── Asserting data for `bundle_1` ───────────────────────────────────────────────
#> ℹ Asserting Identifiers
#> ℹ Asserting groups
#> ℹ Asserting direct question
#> ℹ Asserting response question
#> ℹ Asserting demo variables
#> ℹ Demo is data.frame with `response_id` column
#> ✖ 21 respondents have at least one missing value in break variables - dropping them.
#> 
#> 
#> ── Asserting data for `bundle_2` ───────────────────────────────────────────────
#> ℹ Asserting Identifiers
#> ℹ Asserting groups
#> ℹ Asserting direct question
#> ℹ Asserting response question
#> ✖ 4 respondents from control group have response values that should not be available (other than integers from 0 to n_item) - dropping them.
#> ℹ Asserting demo variables
#> ℹ Demo is data.frame with `response_id` column
#> ✖ 21 respondents have at least one missing value in break variables - dropping them.
#> 
#> 
#> ── Asserting data for `bundle_3` ───────────────────────────────────────────────
#> ℹ Asserting Identifiers
#> ℹ Asserting groups
#> ℹ Asserting direct question
#> ℹ Asserting response question
#> ℹ Asserting demo variables
#> ℹ Demo is data.frame with `response_id` column
#> ✖ 21 respondents have at least one missing value in break variables - dropping them.
#> 

The list_assert_data_bulk() function tests various assumptions. If any fail, it may either trigger an error or attempt to rectify the issue if a solution has been previously identified. For instance, as shown above, 4 respondents from the control group provided an invalid response. Additionally, in the provided demo dataset, 21 respondents did not answer at least one demographic question. Other assumptions tested include response ID uniqueness, valid group values, valid direct question values, and valid and non-empty 'le_response' values.

The function’s output is a list with 7 elements for each bundle, containing:

  • data_private: Cleaned data.frame of the list experiment
  • data_public: Cleaned data.frame of the direct (sensitive) question
  • n_items: Number of non-sensitive (control group) items
  • demo: Cleaned tibble with demographic variables
  • var_classes: Vector describing variable classes in the demo tibble
  • removed_responses: tibble with response IDs and reasons for removal from list experiment and direct question data
  • removed_demo: tibble with response IDs and reasons for removal from demographic data

The n_items argument must also be supplied as an Integer(1) (e.g., 4L for 4 non-sensitive statements). Refer to ?list_assert_data for further details.

Tidying the Data

The list_tidy_data_bulk() function is a straightforward wrapper that converts categorical data from demographic variables into a grid of dummy variables, stored in the grid list element. It also adds the predictors list element, which holds the names of columns in the dummy dataset.

Example:

list_data_tidied <- list_tidy_data_bulk(list_data_asserted, "response_id")

Optional arguments for this function are:

  • keep_treat_direct – with default value TRUE. This argument controls if tidying process should include (default) answers to direct question from both: treatment and control groups. If you wish to use only the answers form control group set this argument to FALSE.
  • unsure – since we allow respondents to answer Agree, Disagree or Don’t know / No opinion and our List Experiment model accepts only binary responses we need to deal somehow with Unsure answer. Depending on the context we can assume that respondents who answered Don’t know / No opinion indeed have no clue what to answer. Or they might not to answer Agree to the direct question hiding their true thoughts. In the former case it would be justified to remove those answers from data set and set argument unsure = "remove". If the latter is true, we would like to include those who hide their opinions into Disagree group (by setting argument unsure = "recode" which is also default behavior of the function). The reason for this is that the list experiment is trying to uncover preference falsification that occurs through direct questioning of sensitive items. Therefore, we need to isolate the % who respond Agree to the item in both the direct and indirect questioning.

For example, if you would like to use only direct responses from the control group and remove those who were unsure you would re-write previous function call as:

list_data_tidied_control_remove_unsure <- list_tidy_data_bulk(
  list_data_asserted, "response_id", keep_treat_direct = FALSE, unsure = "remove"
)

Make life easier

The above mentioned functions can work in pipe. So, if you do not need the intermediate steps, the whole read >> assert >> tidy workflow can be written as simply as:

Note that this automatically removes respondents that did not pass the assert check!

## For make things work faster and use less space let's use only two 
## categorical variables: d_party and s_gender
demo_toy <- list_experiment_toy[1:300, ] %>%
  select(response_id, d_party, s_gender)

list_data_tidied <- list_experiment_toy[1:300, ] %>%
  list_read_data_bulk(response_id) %>%
  list_assert_data_bulk(demo_toy, response_id, n_items = 4L) %>%
  list_tidy_data_bulk(response_id)

Estimating STAN model

The STAN model is supported by g6tr.list. The data prepared as shown above can be directly fed into the model. Common arguments include model and seed. Currently, the package supports a single STAN model, g6trliststan. The seed can be specified for reproducibility. list_model() uses rstan::sampling() internally, and other arguments will be passed to this function.

Model/s used by g6tr.list are not pre-compiled. This means that during each session, during the first run of list_model() you will need to wait around 2 minutes for rstan to compile the model. The good news is, that every next iteration during the same session will automatically pull the compiled model from cache and it will take only fraction of a second.

For a single bundle, use list_model(). Be sure to select the appropriate list element from the results of list_tidy_data().

model_output <- list_model(
  list_data_tidied[[1]], model = "g6trliststan", seed = 666,
  iter = 500, cores = 2, chains = 2 #parameters to be passed to rstan::sampling
)

To run the model for multiple bundles efficiently, employ list_model_bulk(). Results will be stored in files with the given file_prefix and can be found in the models directory by default.

Since, usually we have quite a few bundles, and the modeling part takes a lot of time and resources, it is better to push the modeling tasks to our Kubernetes machine. We have a simple wrapper function: list_model_bulk() that will take care of everything for you. It has similar syntax as the list_model. The difference is that the results of the modeling will be automatically dumped into files. There is a file_prefix argument, where you should specify the prefix of the file names. By default, all the results will be stored in the models directory.

list_model_bulk(
  list_data_tidied, model = "g6trliststan", seed = 666, 
  file_prefix = "list_model",
  iter = 500, cores = 2, chains = 2 #parameters to be passed to rstan::sampling
)

Model output includes a list with raw results from sampling() (list_fit) and predictor names (predictors). Further processing should be done with the list_statistics() function.

Model Results and Statistics

To explore model results and compare them to raw data, use list_statistics_bulk(). This function takes parameters including path, file_prefix, data, weights_df, weights_var, id, hdi, and higher.

To explore the results of the model and to compare them to raw data we can use list_statistics_bulk() function. It takes eight parameters: * path – the path to the folder containing results files of the list_models_bulk() function *file_prefix-- the prefix for file names *data-- object containing the results oflist_tidy_data()*weights_df-- an optional (defaultNULL) object containingdata.framewithweights* weights_var -- an optional (defaultNULL) character value indicating variable name containing weights * id -- variable name containing ids (default "response_id") *hdi-- a fraction for which highest posterior density interval will be calculated (default0.95) *higher-- a boundary of the difference between private and public opinion to be considered as meaningful (default0.03`).

Two of this parameters: hdi and higher might be confusing. The hdi will tell the function for what mass interval it should calculate the range of the difference between the private and public opinion probabilities. Assume that we use hdi = 0.89. The function will calculate what is the smallest interval of calculated differences between probabilities of the private and public opinion. E.g. if the interval is 0.1 to 0.14, this will mean that there is 0.89 probability that the difference of probability of saying Agree in private and public opinion is between 0.1 and 0.14. In the case of higher parameter, we indicate what is the boundary of the difference that we would consider significant. Lets say that if the difference between private and public opinion is less than 0.04, we consider it not relevant. The results of the function will tell us what is the probability that the difference is indeed higher than 0.04.

bundles_statistics <- list_statistics_bulk(
  path = "models", file_prefix = "list_model_",
  data = list_data_tidied, 
  hdi = 0.89, higher = 0.04
)
#> 
#> ── Tidying Model Results ───────────────────────────────────────────────────────
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> ── Calculating Overall Model Statistics ────────────────────────────────────────
#> ℹ Calculating parameters quantiles
#> ✔ Parameters quantiles ready! [31ms]
#> 
#> ℹ Calculating public simulated vs. actual answers
#> ✔ Public simulated vs. actual answers ready! [113ms]
#> 
#> ℹ Calculating private simulated vs. actual answers
#> ✔ Private simulated vs. actual answers ready! [26ms]
#> 
#> ℹ Calculating average public probabilities
#> ✔ Average public probabilities ready! [7ms]
#> 
#> ℹ Calculating average private probabilities
#> ✔ Average private probabilities ready! [7ms]
#> 
#> ℹ Calculating average delta probabilities
#> ✔ Average delta probabilities ready! [8ms]
#> 
#> ℹ Calculating average survey responses
#> ✔ Average survey responses ready! [9ms]
#> 
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> ── Calculating Statistical Tests ───────────────────────────────────────────────
#> 
#> ── Calcualting Average group probabilities ──
#> 
#> ℹ Calculating public probabilities for: `d_party`
#> ✔ Public probabilities for: `s_gender` ready! [5ms]
#> 
#> ℹ Calculating public probabilities for: `s_gender`
#> ✔ Public probabilities for: `s_region` ready! [10ms]
#> 
#> ℹ Calculating public probabilities for: `s_region`
#> ✔ Public probabilities for: `d_party` ready! [9ms]
#> 
#> ℹ Calculating private probabilities for: `d_party`
#> ✔ Private probabilities for: `s_gender` ready! [9ms]
#> 
#> ℹ Calculating private probabilities for: `s_gender`
#> ✔ Private probabilities for: `s_region` ready! [9ms]
#> 
#> ℹ Calculating private probabilities for: `s_region`
#> ✔ Private probabilities for: `d_party` ready! [9ms]
#> 
#> ℹ Calculating delta probabilities for: `d_party`
#> ✔ Delta probabilities for: `s_gender` ready! [10ms]
#> 
#> ℹ Calculating delta probabilities for: `s_gender`
#> ✔ Delta probabilities for: `s_region` ready! [10ms]
#> 
#> ℹ Calculating delta probabilities for: `s_region`
#> ✔ Delta probabilities for: `s_region` ready! [27ms]
#> 
#> ── Tidying Model Results ───────────────────────────────────────────────────────
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> ── Calculating Overall Model Statistics ────────────────────────────────────────
#> ℹ Calculating parameters quantiles
#> ✔ Parameters quantiles ready! [12ms]
#> 
#> ℹ Calculating public simulated vs. actual answers
#> ✔ Public simulated vs. actual answers ready! [20ms]
#> 
#> ℹ Calculating private simulated vs. actual answers
#> ✔ Private simulated vs. actual answers ready! [35ms]
#> 
#> ℹ Calculating average public probabilities
#> ✔ Average public probabilities ready! [8ms]
#> 
#> ℹ Calculating average private probabilities
#> ✔ Average private probabilities ready! [8ms]
#> 
#> ℹ Calculating average delta probabilities
#> ✔ Average delta probabilities ready! [8ms]
#> 
#> ℹ Calculating average survey responses
#> ✔ Average survey responses ready! [12ms]
#> 
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> ── Calculating Statistical Tests ───────────────────────────────────────────────
#> 
#> ── Calcualting Average group probabilities ──
#> 
#> ℹ Calculating public probabilities for: `d_party`
#> ✔ Public probabilities for: `s_gender` ready! [4ms]
#> 
#> ℹ Calculating public probabilities for: `s_gender`
#> ✔ Public probabilities for: `s_region` ready! [9ms]
#> 
#> ℹ Calculating public probabilities for: `s_region`
#> ✔ Public probabilities for: `d_party` ready! [8ms]
#> 
#> ℹ Calculating private probabilities for: `d_party`
#> ✔ Private probabilities for: `s_gender` ready! [9ms]
#> 
#> ℹ Calculating private probabilities for: `s_gender`
#> ✔ Private probabilities for: `s_region` ready! [9ms]
#> 
#> ℹ Calculating private probabilities for: `s_region`
#> ✔ Private probabilities for: `d_party` ready! [9ms]
#> 
#> ℹ Calculating delta probabilities for: `d_party`
#> ✔ Delta probabilities for: `s_gender` ready! [9ms]
#> 
#> ℹ Calculating delta probabilities for: `s_gender`
#> ✔ Delta probabilities for: `s_region` ready! [9ms]
#> 
#> ℹ Calculating delta probabilities for: `s_region`
#> ✔ Delta probabilities for: `s_region` ready! [22ms]
#> 
#> ── Tidying Model Results ───────────────────────────────────────────────────────
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> ── Calculating Overall Model Statistics ────────────────────────────────────────
#> ℹ Calculating parameters quantiles
#> ✔ Parameters quantiles ready! [11ms]
#> 
#> ℹ Calculating public simulated vs. actual answers
#> ✔ Public simulated vs. actual answers ready! [19ms]
#> 
#> ℹ Calculating private simulated vs. actual answers
#> ✔ Private simulated vs. actual answers ready! [23ms]
#> 
#> ℹ Calculating average public probabilities
#> ✔ Average public probabilities ready! [7ms]
#> 
#> ℹ Calculating average private probabilities
#> ✔ Average private probabilities ready! [7ms]
#> 
#> ℹ Calculating average delta probabilities
#> ✔ Average delta probabilities ready! [7ms]
#> 
#> ℹ Calculating average survey responses
#> ✔ Average survey responses ready! [8ms]
#> 
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> ── Calculating Statistical Tests ───────────────────────────────────────────────
#> 
#> ── Calcualting Average group probabilities ──
#> 
#> ℹ Calculating public probabilities for: `d_party`
#> ✔ Public probabilities for: `s_gender` ready! [4ms]
#> 
#> ℹ Calculating public probabilities for: `s_gender`
#> ✔ Public probabilities for: `s_region` ready! [9ms]
#> 
#> ℹ Calculating public probabilities for: `s_region`
#> ✔ Public probabilities for: `d_party` ready! [9ms]
#> 
#> ℹ Calculating private probabilities for: `d_party`
#> ✔ Private probabilities for: `s_gender` ready! [9ms]
#> 
#> ℹ Calculating private probabilities for: `s_gender`
#> ✔ Private probabilities for: `s_region` ready! [8ms]
#> 
#> ℹ Calculating private probabilities for: `s_region`
#> ✔ Private probabilities for: `d_party` ready! [8ms]
#> 
#> ℹ Calculating delta probabilities for: `d_party`
#> ✔ Delta probabilities for: `s_gender` ready! [8ms]
#> 
#> ℹ Calculating delta probabilities for: `s_gender`
#> ✔ Delta probabilities for: `s_region` ready! [10ms]
#> 
#> ℹ Calculating delta probabilities for: `s_region`
#> ✔ Delta probabilities for: `s_region` ready! [20ms]
#> 

The structure of the output is a nested list. Results for each bundle are stored in separate element. For each of the bundles there are 6 elements containing: * params_quantiles – a summary of model parameter quantiles * sim_vs_actual – two tibbles with comparison of the simulated and actual ratios of the answers to the list experiment and direct questions * point_estimates – two tibbles with point estimates of actual (raw) results and simulated probabilities * raw_means_by_group – a tibble with actual (raw) results calculated by demographic group * prob_by_group – a tibble with simulated probabilities results calculated by a demographic group * stat_by_group – a tibble with HDI and probabilities that the difference between private and public probability is higher than the threshold

bundles_statistics %>% glimpse()
#> List of 3
#>  $ bundle_1:List of 6
#>   ..$ params_quantiles  : tibble [17 × 6] (S3: tbl_df/tbl/data.frame)
#>   ..$ sim_vs_actual     :List of 2
#>   .. ..$ public : tibble [2 × 3] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ private: tibble [6 × 3] (S3: tbl_df/tbl/data.frame)
#>   ..$ point_estimates   :List of 2
#>   .. ..$ mean_raw          : tibble [1 × 7] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ mean_probabilities: tibble [1 × 4] (S3: tbl_df/tbl/data.frame)
#>   ..$ raw_means_by_group: tibble [10 × 9] (S3: tbl_df/tbl/data.frame)
#>   ..$ prob_by_group     : tibble [10 × 6] (S3: tbl_df/tbl/data.frame)
#>   ..$ stat_by_group     : tibble [63 × 9] (S3: tbl_df/tbl/data.frame)
#>  $ bundle_2:List of 6
#>   ..$ params_quantiles  : tibble [17 × 6] (S3: tbl_df/tbl/data.frame)
#>   ..$ sim_vs_actual     :List of 2
#>   .. ..$ public : tibble [2 × 3] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ private: tibble [6 × 3] (S3: tbl_df/tbl/data.frame)
#>   ..$ point_estimates   :List of 2
#>   .. ..$ mean_raw          : tibble [1 × 7] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ mean_probabilities: tibble [1 × 4] (S3: tbl_df/tbl/data.frame)
#>   ..$ raw_means_by_group: tibble [10 × 9] (S3: tbl_df/tbl/data.frame)
#>   ..$ prob_by_group     : tibble [10 × 6] (S3: tbl_df/tbl/data.frame)
#>   ..$ stat_by_group     : tibble [63 × 9] (S3: tbl_df/tbl/data.frame)
#>  $ bundle_3:List of 6
#>   ..$ params_quantiles  : tibble [17 × 6] (S3: tbl_df/tbl/data.frame)
#>   ..$ sim_vs_actual     :List of 2
#>   .. ..$ public : tibble [2 × 3] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ private: tibble [6 × 3] (S3: tbl_df/tbl/data.frame)
#>   ..$ point_estimates   :List of 2
#>   .. ..$ mean_raw          : tibble [1 × 7] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ mean_probabilities: tibble [1 × 4] (S3: tbl_df/tbl/data.frame)
#>   ..$ raw_means_by_group: tibble [10 × 9] (S3: tbl_df/tbl/data.frame)
#>   ..$ prob_by_group     : tibble [10 × 6] (S3: tbl_df/tbl/data.frame)
#>   ..$ stat_by_group     : tibble [63 × 9] (S3: tbl_df/tbl/data.frame)

Lets take a closer look at particular elements of the results for a single bundle.

Parameter Quantiles

Here you can find quantiles of the estimated parameters of the model. The purpose of this element is purely diagnostic of the model.

bundles_statistics$bundle_1$params_quantiles
#> # A tibble: 17 × 6
#>    parameter                    `0%`     `25%`     `50%`    `75%`   `100%`
#>    <chr>                       <dbl>     <dbl>     <dbl>    <dbl>    <dbl>
#>  1 beta_public              -3.44e+0   -0.657    -0.0485    0.365    1.66 
#>  2 beta_list_control        -1.52e+0   -0.214     0.0141    0.199    1.07 
#>  3 beta_list_sensitive      -5.46e+0   -0.957     0.149     1.46     6.16 
#>  4 intercept_public         -4.57e+0   -3.30     -2.28     -1.53    -0.218
#>  5 intercept_list_sensitive -3.73e+0   -1.37     -0.241     1.23     4.15 
#>  6 intercept_list_control   -1.29e+0   -0.402    -0.0233    0.423    1.31 
#>  7 prob_public               1.59e-3    0.125     0.193     0.280    0.746
#>  8 prob_private              3.31e-5    0.248     0.549     0.824    1.000
#>  9 prob_hid_pos              3.13e-5    0.194     0.418     0.623    0.979
#> 10 prob_hid_neg              1.66e-7    0.0298    0.0716    0.133    0.650
#> 11 public_logit             -6.44e+0   -1.95     -1.43     -0.945    1.08 
#> 12 public_in_private_logit  -6.44e+0   -1.95     -1.43     -0.945    1.08 
#> 13 control_logit            -1.67e+0   -0.122     0.0959    0.371    1.26 
#> 14 sensitive_logit          -1.03e+1   -1.11      0.196     1.54    14.8  
#> 15 public_sim                0          0         0         0        1    
#> 16 private_sim               0          2         2         3        5    
#> 17 lp__                     -7.39e+2 -728.     -725.     -723.    -716.
Simulated vs Actual Values

This element contains two tibbles: public and private opinion comparisons. Both tables show what ratio of particular responses is simulated by the model, and what is the current ratio of the responses in our data set. It is useful to check how good our model performs in generating data.

bundles_statistics$bundle_1$sim_vs_actual
#> $public
#> # A tibble: 2 × 3
#>   response simulated_public_answers actual_public_answers
#>   <fct>                       <dbl>                 <dbl>
#> 1 0                           0.786                 0.789
#> 2 1                           0.214                 0.211
#> 
#> $private
#> # A tibble: 6 × 3
#>   response simulated_private_answers actual_private_answers
#>   <fct>                        <dbl>                  <dbl>
#> 1 0                           0.0396                0.00662
#> 2 1                           0.172                 0.113  
#> 3 2                           0.304                 0.404  
#> 4 3                           0.298                 0.311  
#> 5 4                           0.154                 0.0596 
#> 6 5                           0.0319                0.106
Point Estimates

This element also has two tibbles: what are the actual values calculated from raw survey data, and what are the values of the probabilities. Both data sets contain also column/s indicating the number of respondents.

bundles_statistics$bundle_1$point_estimates
#> $mean_raw
#> # A tibble: 1 × 7
#>   group_treatment group_control public_question mean_raw_delta N_Public
#>             <dbl>         <dbl>           <dbl>          <dbl>    <dbl>
#> 1            2.62          2.13           0.211          0.278      279
#> # ℹ 2 more variables: N_Control <dbl>, N_Treatment <dbl>
#> 
#> $mean_probabilities
#> # A tibble: 1 × 4
#>   probability_public probability_private probability_delta N_Overall
#>                <dbl>               <dbl>             <dbl>     <dbl>
#> 1              0.211               0.531             0.321       279
Raw Means by Group

Her you will find calculated average of responses for each of the demographic groups, taken from demo data set. Our model is capable of using continuous variables, which are omitted in this comparison.

bundles_statistics$bundle_1$raw_means_by_group
#> # A tibble: 10 × 9
#>    demo_variable demo_value  raw_public N_Public raw_control N_Control
#>    <chr>         <chr>            <dbl>    <dbl>       <dbl>     <dbl>
#>  1 d_party       Democrat         0.221      113        2.17        52
#>  2 d_party       Independent      0.127       79        2.11        38
#>  3 d_party       Republican       0.295       78        2.18        33
#>  4 d_party       Other            0.111        9        1.6          5
#>  5 s_gender      Female           0.170      176        2           91
#>  6 s_gender      Male             0.282      103        2.46        37
#>  7 s_region      Northeast        0.226       53        2.28        18
#>  8 s_region      Midwest          0.172       58        2.32        31
#>  9 s_region      South            0.246      122        2.03        59
#> 10 s_region      West             0.152       46        2           20
#> # ℹ 3 more variables: raw_treatment <dbl>, N_Treatment <dbl>,
#> #   mean_raw_delta <dbl>
Calculated Probabilities by Group

Similarly to the previous tibble this one also presents the average results by demographic groups. Instead of using the raw survey data, it calculates averages of estimated probabilities.

bundles_statistics$bundle_1$prob_by_group
#> # A tibble: 10 × 6
#>    demo_variable demo_value  private_probability public_probability
#>    <chr>         <chr>                     <dbl>              <dbl>
#>  1 d_party       Democrat                  0.475              0.218
#>  2 d_party       Independent               0.480              0.132
#>  3 d_party       Republican                0.674              0.288
#>  4 d_party       Other                     0.458              0.134
#>  5 s_gender      Female                    0.520              0.170
#>  6 s_gender      Male                      0.551              0.280
#>  7 s_region      Northeast                 0.427              0.222
#>  8 s_region      Midwest                   0.587              0.175
#>  9 s_region      South                     0.658              0.244
#> 10 s_region      West                      0.245              0.155
#> # ℹ 2 more variables: delta_probability <dbl>, N <dbl>
Model Statistics by Group

This tibble presents the HDI and probability that the calculated difference in probabilities is higher than the threshold (set with higher parameter). Additionally it presents if the difference between Overall population and demographic group in the same probability is greater than +/- threshold. The tibble is in a long format. For each of the demographic breaks there is calculated probability of private and public opinion as well as the difference between them and differences compared to Overall population. Each of this, is recorded in a separate row (coded as public, private or diff in statistic column). The following columns with hdi_ prefix covers the lower and higher boundary of the HDI region.

bundles_statistics$bundle_1$stat_by_group
#> # A tibble: 63 × 9
#>    demo_variable demo_value  statistic     hdi_0.89_lower hdi_0.89_upper
#>    <chr>         <chr>       <chr>                  <dbl>          <dbl>
#>  1 Overall       Overall     private               0.380          0.729 
#>  2 Overall       Overall     public                0.181          0.253 
#>  3 Overall       Overall     delta                 0.166          0.509 
#>  4 d_party       Democrat    private               0.253          0.750 
#>  5 d_party       Democrat    public                0.168          0.266 
#>  6 d_party       Democrat    delta                 0.0506         0.570 
#>  7 d_party       Democrat    delta_private        -0.189          0.0934
#>  8 d_party       Democrat    delta_public         -0.0424         0.0426
#>  9 d_party       Democrat    delta_delta          -0.214          0.0894
#> 10 d_party       Independent private               0.199          0.712 
#> # ℹ 53 more rows
#> # ℹ 4 more variables: `Pr delta >= 0.04` <dbl>, `Pr delta <= -0.04` <dbl>,
#> #   `Pr delta Overall >= 0.04` <dbl>, `Pr delta Overall <= -0.04` <dbl>

In our example we set hdi = 0.89. This means we are looking for the most narrow interval that covers 89% of calculated probabilities. hdi_0.89_low tells us what is the lower boundary of this interval and hdi_0.89_high tells us what is the higher boundary of this interval. From our example, we can tell that 89% of the public probability of Democrats is found in 0.168 to 0.266 interval.

The column with Pr delta >= prefix contains the probability that the difference between public and private probability within a demographic level is higher or equal to the threshold. In our example we set higher = 0.04. We can read from the results that the value for the Democrat break in Pr delta >= 0.04 is 0.94. This means that 94% of the calculated differences was higher than 0.04.

In the last two columns you can find the the probability that the difference between related probability of a demographic level is higher or lower than the threshold when compared to the overall population. It sounds more confusing than it is in reality. Lets filter the difference rows for Overall and Democrat:

bundles_statistics$bundle_1$point_estimates$mean_probabilities
#> # A tibble: 1 × 4
#>   probability_public probability_private probability_delta N_Overall
#>                <dbl>               <dbl>             <dbl>     <dbl>
#> 1              0.211               0.531             0.321       279

bundles_statistics$bundle_1$prob_by_group %>%
  filter(demo_value %in% c("Democrat"))
#> # A tibble: 1 × 6
#>   demo_variable demo_value private_probability public_probability
#>   <chr>         <chr>                    <dbl>              <dbl>
#> 1 d_party       Democrat                 0.475              0.218
#> # ℹ 2 more variables: delta_probability <dbl>, N <dbl>

bundles_statistics$bundle_1$stat_by_group %>%
  filter(
    demo_value %in% c("Overall", "Democrat") & 
      statistic %in% c("delta_private", "delta_public", "delta_delta")
  )
#> # A tibble: 3 × 9
#>   demo_variable demo_value statistic     hdi_0.89_lower hdi_0.89_upper
#>   <chr>         <chr>      <chr>                  <dbl>          <dbl>
#> 1 d_party       Democrat   delta_private        -0.189          0.0934
#> 2 d_party       Democrat   delta_public         -0.0424         0.0426
#> 3 d_party       Democrat   delta_delta          -0.214          0.0894
#> # ℹ 4 more variables: `Pr delta >= 0.04` <dbl>, `Pr delta <= -0.04` <dbl>,
#> #   `Pr delta Overall >= 0.04` <dbl>, `Pr delta Overall <= -0.04` <dbl>

As you can see there is around 17% chance that the private probability in Democrats group is more than 4 percent points higher than in the overall population. On the other hand there is around 58% chance that the difference in the private probabilities between Democrats and Overall is indeed lower than 4 percent points. Similar conclusions can be made for public probability and deltas.

Summary statistics

Other way to check the results of the model is to make a summary of the draws. This can be done with list_summary_stats() function. The function will also display a message if the rhat values were lower or higher than 1.05. If some of the values were higher than 1.05 this would mean that the model did not converge, so it should be re-run with more iterations. Computation of those values takes a lot of time. With several bundles it might easily take an hour. Thus, to avoid unnecessary computation the function is only available for a single model outputs.

data("list_model_toy_1")
model_summary <- list_summary_stats(list_model_toy_1)
#> At least one rhat value exceeds 1.05 or there are NA. Model did not converged.
model_summary
#> $beta
#> # A tibble: 24 × 10
#>    variable      mean  median    sd   mad     q5     q95  rhat ess_bulk ess_tail
#>    <chr>        <dbl>   <dbl> <dbl> <dbl>  <dbl>   <dbl> <dbl>    <dbl>    <dbl>
#>  1 beta_publ… -0.741  -0.679  0.455 0.415 -1.57  -0.0259 1.00     105.      45.7
#>  2 beta_publ…  0.182   0.225  0.360 0.295 -0.493  0.723  1.00      88.3     47.5
#>  3 beta_publ… -0.873  -0.828  0.966 0.938 -2.51   0.771  1.08     158.      92.6
#>  4 beta_publ…  0.638   0.629  0.295 0.345  0.215  1.10   0.996     51.0     67.2
#>  5 beta_publ… -0.356  -0.383  0.480 0.520 -1.04   0.456  0.992    176.      89.8
#>  6 beta_publ…  0.0400  0.0815 0.394 0.414 -0.678  0.619  1.01     129.     112. 
#>  7 beta_publ… -0.587  -0.574  0.550 0.588 -1.47   0.316  0.990    129.      92.6
#>  8 beta_publ…  0.349   0.345  0.338 0.394 -0.193  0.882  0.991     85.9     92.6
#>  9 beta_list…  0.0246  0.0281 0.164 0.162 -0.268  0.281  0.999    120.     113. 
#> 10 beta_list…  0.0686  0.0759 0.169 0.130 -0.236  0.319  1.01      77.4    112. 
#> # ℹ 14 more rows
#> 
#> $intercept
#> # A tibble: 3 × 10
#>   variable        mean  median    sd   mad     q5    q95  rhat ess_bulk ess_tail
#>   <chr>          <dbl>   <dbl> <dbl> <dbl>  <dbl>  <dbl> <dbl>    <dbl>    <dbl>
#> 1 intercept_… -2.41    -2.28   1.05  1.17  -4.11  -0.832 0.992     88.2     37.8
#> 2 intercept_… -0.0561  -0.241  1.76  1.81  -2.74   2.59  1.02      44.9     52.5
#> 3 intercept_…  0.00358 -0.0233 0.573 0.630 -0.881  0.881 0.998    119.      58.9
#> 
#> $respondents
#> # A tibble: 2,791 × 10
#>    variable       mean median     sd    mad     q5   q95  rhat ess_bulk ess_tail
#>    <chr>         <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl> <dbl>    <dbl>    <dbl>
#>  1 prob_public[… 0.268  0.268 0.0626 0.0547 0.165  0.377 0.995    104.      74.7
#>  2 prob_public[… 0.200  0.189 0.0909 0.0983 0.0847 0.364 1.00      74.9     71.3
#>  3 prob_public[… 0.330  0.330 0.0780 0.0757 0.213  0.440 1.01      82.2     24.8
#>  4 prob_public[… 0.153  0.148 0.0703 0.0864 0.0626 0.282 0.994    101.      58.9
#>  5 prob_public[… 0.124  0.115 0.0470 0.0453 0.0593 0.212 0.996    104.      64.3
#>  6 prob_public[… 0.268  0.268 0.0627 0.0551 0.165  0.377 0.996    104.      74.7
#>  7 prob_public[… 0.303  0.300 0.0816 0.0804 0.184  0.444 1.01      87.7     48.4
#>  8 prob_public[… 0.172  0.174 0.0661 0.0722 0.0770 0.301 0.994    117.      78.3
#>  9 prob_public[… 0.174  0.171 0.0565 0.0711 0.0997 0.264 0.995     94.7     98.4
#> 10 prob_public[… 0.214  0.215 0.0498 0.0539 0.141  0.302 1.000     80.7     56.8
#> # ℹ 2,781 more rows

As a results you will get a list with 3 elements. Each of the elements contains basic summary statistics for model parameters. First element contains betas (or coefficients if you will), second contains intercepts and the last one contains particular respondents probabilities.