Fits the Stan model for a single list experiment and returns an lx_model
containing posterior draws and convergence diagnostics.
Usage
lx_fit(
data,
unsure_coding = "disagree",
use_public = "control",
iter = 500,
cores = 1,
chains = 1,
seed = NULL,
...
)Arguments
- data
Parsed data for one list experiment. For example, a single element extracted from the
datacolumn of anlx_parse_data()result.- unsure_coding
How to treat "unsure" responses in
publicandmajority. One of"disagree"or"remove". Defaults to"disagree".- use_public
Which respondents to use for the public-data model part . One of
"control"(default),"both", or"treatment"."treatment"is generally not recommended because exposure to the sensitive statement in the count question may influence direct public answers.- iter
A positive integer specifying the number of iterations for each chain (including warmup). The default is 2000.
- cores
Number of cores to use when executing the chains in parallel, which defaults to 1 but we recommend setting the
mc.coresoption to be as many processors as the hardware and RAM allow (up to the number of chains).- chains
A positive integer specifying the number of Markov chains. The default is 4.
- seed
Optional integer seed to set before sampling.
- ...
Additional arguments passed to
rstan::sampling().
Value
An object of class lx_model with components:
prob_publictibble with columnsidanddraws(public probabilities)prob_privatetibble with columnsidanddraws(private probabilities)response_publictibble with columnsidandresponseresponse_privatetibble with columnsidandresponseresponse_majorityoptional tibble with columnsidandresponsedraws_summarydata frame fromposterior::summarise_draws()rhat_summaryper-array counts of R-hat diagnosticssim_public/sim_privatetibbles withidand adrawsmatrix-column containing simulated outcomesdatathe parsed input data passed tolx_fit()n_insensnumber of insensitive statements used in the experimentblueprintahardhatblueprint used by downstream helpers
Details
What you provide
A single parsed experiment from
lx_parse_data()(one element of itsdatacolumn).A choice for how to treat "unsure" responses in the public/majority questions:
"disagree"(treat as 0) or"remove"(drop those rows).A choice for which treatment arm contributes to the public-data model part:
"control"(default),"both", or"treatment"(not recommended).
What you get
An
lx_modelwith posterior draws for public and private probabilities, plus summary diagnostics you can inspect for convergence.Convenient follow-ups:
Use
lx_predict_for_cohorts()to aggregate predictions for the whole sample or for custom cohorts (with means, intervals, and draws).Inspect
rhat_summaryto quickly spot any problematic R-hat values.
Tips
Set
seedfor reproducible results.Increase
iter,chains, andcoresas needed for accuracy and speed.
Examples
if (FALSE) { # \dontrun{
parsed <- lx_parse_data(
example_srv_lx,
n_insens = 4,
id_col = response_id,
treatment = m2_list_treatment,
private = "m2_list_{exp}_private",
public = "m3_list_{exp}_public",
majority = "m3_list_{exp}_majority",
predictors = tidyselect::starts_with("d_"),
treatment_coding = c(control = "ctrl", treatment = "trt")
)
pets_data <- parsed$data$pets
model_pets <- lx_fit(
pets_data,
iter = 1000,
chains = 4,
cores = 4,
seed = 123
)
model_pets
} # }