Turns rows of a persona data frame (one respondent per row, demographics plus
survey or attitude answers) into a silicon_panel whose personas can be
administered survey items. It is built for frames following the LLMR persona
contract, such as LLMR::anes_2024_personas: the demographics and the answers
are read with LLMR::llm_persona_split() (so answers are keyed by their
question wording when the frame carries a dictionary), and each persona is
rendered as a person to answer in character.
Arguments
- data
A persona data frame. Defaults to
LLMR::anes_2024_personas.- n
Optional panel size. With
NULL, every selected row is used; with a number, rows are sampled (without replacement whenndoes not exceed the pool, otherwise with replacement).- rows
Optional row selector: an integer or logical vector, or a predicate
function(df)returning a logical vector. Applied before sampling.- weights
Optional survey weights for the draw: a column name in
data, or a numeric vector aligned to the selected rows. Used only whennis given.NULL(default) draws uniformly.
Details
Unlike panel_from_margins() and panel_from_data(), this constructor keeps
each selected respondent's answers together. The margins attribute contains
the demographic distribution of the selected rows.
For a reproducible draw, set a seed before calling (the function never sets one itself).
Examples
# \donttest{
if (requireNamespace("LLMR", quietly = TRUE)) {
set.seed(110)
panel <- panel_from_personas(LLMR::anes_2024_personas, n = 8)
}
# }