Places each agent entirely in ONE RI grid per replication, drawn from its county-commodity candidate grids with the supplied probabilities (the sampled-assignment alternative to probability-weighted apportionment, which smooths away within-county placement risk). Replications are reproducible in isolation: replication r uses seed seed + r, so a given replication is identical regardless of how many replications are requested, and the set of replications can be extended later without disturbing existing ones.

assign_ri_grids(
  agents,
  candidates,
  reps = 100,
  seed = 20260703,
  key_cols = c("state_code", "county_code", "commodity_code")
)

Arguments

agents

data.table with agent_uid plus the key columns linking agents to candidate sets (e.g. from build_agent_panel(method = "grid_free")).

candidates

Candidate grids: either long (key_cols + grid_id + probability) or nested with a ri_candidates list-column.

reps

Either a single count (replications 1:reps) or an explicit vector of replication indices (e.g. 51:100 to extend an existing set).

seed

Master seed; replication r draws under seed + r.

key_cols

Columns linking agents to candidate sets.

Value

data.table with replication, agent_uid, grid_id; one row per agent per replication. Agents with no candidate set are dropped with a message.