Predicting List Experiment Responses
Michal Czyz
2025-10-17
Source:vignettes/predictions_list_experiments.Rmd
predictions_list_experiments.Rmd
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")Making Predictions for List Experiments
Predictions by Individual Respondents
When we need to generate predictions for new data, we can utilize the
list_predict() function. This function takes four
inputs:
-
model: calculated usinglist_model() -
newdata: a data frame containing all predictive variables used for the model, structured asmatrix.model -
weights_df: a data frame with response IDs and weights -
weights_var: name of the column containing weights
If you do not want to make weighted predictions, feel free to skip
this argument. The function will automatically set up weight equal to
1 for each observation.
And the function call looks like:
The output is a list containing three elements:
-
private_predict_prob: a matrix with predicted probabilities of responding yes in the list experiment -
public_predict_prob: a matrix with predicted probabilities of responding yes to the direct question -
difference_predict: the mean difference betweenprivate_predict_probandpublic_predict_prob
The results from list_predict() can be used to calculate
mean probabilities in various ways. For instance, to obtain a general
prediction of the probability of responding Yes to the indirect
question, you can use:
Predictions by Categorical Variables
In most cases, you’ll be interested in predicting probabilities for
specific levels of demographic variables. For example, you might want to
predict the difference in the probability of answering
yes to the direct question for males vs. females, or
predict the difference by race or region. To achieve this, we introduce
the list_predict_demo() function. While this function may
not be straightforward to use, it offers robust capabilities.
To utilize list_predict_demo(), you need to create a
list of predictor and contrast names. If you’re unsure about contrasts,
remember that in the grid, there are n - 1
columns for a predictor variable with n levels. The
contrast corresponds to the missing column. To simplify this process, we
provide the list_make_predictors() function.
For our example, where we have two categorical variables for prediction, creating the predictor and contrast lists is simple:
-
predictors_list: created usinglist_make_predictors()for categorical variabless_genderandd_party
Next, we call the list_predict_demo() function. Similar
to list_predict(), if the weights data frame name isn’t
provided, all calculations will assume a weight of 1. The
critical aspect here is to ensure that the same data passed to the
demo_grid argument matches the data provided to the
newdata argument when general predictions were made.
The output is a tibble with 4 columns:
-
demo: demographic variable levels -
private_probability: probability of responding Yes to the indirect question -
public_probability: probability of responding Yes to the direct question -
diff_probability: difference in probabilities
You may wonder why diff_probability is not exactly the
difference of private_probability - public_probability. The
reason is in the case of differences, we first calculate it on the
respondent level, and take mean of the differences in the second
step.
Thus, the probabilities for gender are:
and for party:
You might also be curious why there’s no Other in the
demo column in party_predictions. Review:
As you can observe, none of the respondents were from the
Other group (all have 0 as
d_partyOther value), resulting in the omission of this
level in the results.