Skip to contents

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 data column of an lx_parse_data() result.

unsure_coding

How to treat "unsure" responses in public and majority. 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.cores option 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_public tibble with columns id and draws (public probabilities)

  • prob_private tibble with columns id and draws (private probabilities)

  • response_public tibble with columns id and response

  • response_private tibble with columns id and response

  • response_majority optional tibble with columns id and response

  • draws_summary data frame from posterior::summarise_draws()

  • rhat_summary per-array counts of R-hat diagnostics

  • sim_public / sim_private tibbles with id and a draws matrix-column containing simulated outcomes

  • data the parsed input data passed to lx_fit()

  • n_insens number of insensitive statements used in the experiment

  • blueprint a hardhat blueprint used by downstream helpers

Details

What you provide

  • A single parsed experiment from lx_parse_data() (one element of its data column).

  • 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_model with 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_summary to quickly spot any problematic R-hat values.

Tips

  • Set seed for reproducible results.

  • Increase iter, chains, and cores as 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
} # }