Skip to contents

Samples n personas with attributes drawn independently from the supplied margins, and renders each persona's text from a template. Independence across attributes is a deliberate simplification: the attributes are sampled marginally, not jointly. For instrument pretesting this rarely matters; for anything resembling estimation it does, and panel_calibrate() will tell you. When you hold microdata and want the joint distribution preserved, use panel_from_data().

Usage

panel_from_margins(margins, n, persona_template = NULL)

Arguments

margins

A named list; each element a named probability vector, e.g. list(age = c("18-34" = .3, "35-64" = .45, "65+" = .25)). Probabilities are renormalized if they do not sum to 1.

n

Panel size.

persona_template

Text with {attribute} placeholders rendered per persona. NULL builds a plain "attribute: value" persona.

Value

A silicon_panel: a tibble with persona_id, one column per attribute, and persona (the rendered text).

Details

For a reproducible panel, set a seed before calling (the function never sets one itself).

Examples

set.seed(110)
panel <- panel_from_margins(
  list(cohort = c(young = .3, middle = .45, older = .25),
       party  = c(left = .45, right = .45, independent = .10)),
  n = 50,
  persona_template = "A {cohort} voter who leans {party}."
)
panel