brycewang-stanford/Auto-Empirical-Research-Skills / skills/22-christopherkenny-skills/skills/redistricting-analysis
redistricting-analysis
VerifiedRedistricting analysis in R using the redistverse ecosystem. Use whenever the user is working with redist, redistmetrics, ggredist, geomander, adj, alarmdata, PL94171, censable, easycensus, tinytiger, baf, rict, or redistio. Covers the complete pipeline: Census and spatial data loading, adjacency graph construction, SMC/MCMC simulation, constraints (population balance, county splits, VRA compliance), convergence diagnostics, plan metrics (compactness, partisan fairness, splits), visualization, summary tables, and interactive plan drawing. Invoke whenever the user mentions redistricting, gerrymandering, district plans, simulation ensembles, or any redistverse package by name.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.8 KB |
| references/01-redist-simulation.md | markdown | 5.7 KB |
| references/02-redist-constraints.md | markdown | 5.0 KB |
| references/03-redist-advanced.md | markdown | 3.2 KB |
| references/04-redistmetrics-compactness.md | markdown | 4.1 KB |
| references/05-redistmetrics-partisan.md | markdown | 4.6 KB |
| references/06-redistmetrics-other.md | markdown | 4.5 KB |
| references/07-ggredist.md | markdown | 4.6 KB |
| references/08-adj.md | markdown | 4.2 KB |
| references/09-geomander-adjacency.md | markdown | 6.1 KB |
| references/10-geomander-spatial.md | markdown | 6.7 KB |
| references/11-geomander-data.md | markdown | 4.3 KB |
| references/12-alarmdata.md | markdown | 4.2 KB |
| references/13-pl94171.md | markdown | 3.6 KB |
| references/14-census-utilities.md | markdown | 5.2 KB |
| references/15-baf.md | markdown | 3.4 KB |
| references/16-rict.md | markdown | 3.4 KB |
| references/17-redistio.md | markdown | 4.3 KB |
references/03-redist-advanced.md
View on GitHub# redist — Advanced Algorithms
## Overview
Beyond the standard SMC and merge-split workflows, `redist` provides exact enumeration for small problems, short-burst heuristic optimization for finding extreme plans, and cycle-walk MCMC. Use these when you need to find optimal plans, exhaustively characterize small maps, or explore the Pareto frontier across competing criteria.
## `redist_enumpart()` — Exact Enumeration
Uses zero-suppressed binary decision diagrams (ZDDs) to enumerate all valid plans. Practical only for maps with fewer than ~70 precincts. Returns either all valid plans or a uniform sample from them.
```r
plans <- redist_enumpart(
map,
ndists = map$ndists,
pop_tol = 0.05,
save_all = TRUE # FALSE to uniform-sample instead of returning all
)
```
This is the only algorithm that can compute exact statistics (e.g., exact seat probabilities) because it covers the full space of valid plans.
## `redist_shortburst()` — Short-Burst Optimization
Finds extreme plans by running short MCMC bursts and keeping the best plan seen. Useful for:
- Finding the most/least gerrymandered plan (given a metric)
- Characterizing the Pareto frontier across two criteria
- Producing extreme examples for illustration
```r
plans_opt <- redist_shortburst(
map,
score_fn = function(plans, map) part_egap(plans, map$ndv, map$nrv),
max_bursts = 200,
burst_size = 10, # MCMC steps per burst
maximize = TRUE, # TRUE to maximize, FALSE to minimize
constraints = constr,
verbose = TRUE
)
```
The `score_fn` receives the `redist_plans` object and `map`, and should return a numeric vector (one value per plan). Any `redistmetrics` function works.
### Pareto Frontier
To trace the tradeoff between two metrics (e.g., compactness vs. partisan fairness):
```r
# Use the built-in frontier approach with redist_shortburst
# Run multiple optimizations with varying weights between objectives
```
## `redist_cyclewalk()` — Cycle-Walk MCMC
A variant MCMC that adds random cycles into spanning trees before cutting, increasing diversity in the generated plans. Can be useful when merge-split mixes poorly.
```r
plans <- redist_cyclewalk(
map,
nsims = 10000,
constraints = constr,
init_plan = NULL,
verbose = TRUE
)
```
## `init_particles` — Partial-State Simulations
For states where some districts are predetermined (e.g., island districts that must include specific precincts), supply an initial particle set to SMC that fixes the predetermined structure.
```r
# Example: Hawaii has two focal regions that must anchor the two districts
# Precompute which precincts must go in each region, then pass to SMC
plans <- redist_smc(
map,
nsims = 5000,
init_particles = my_particle_list # list of partial plan assignments
)
```
This is used in the ALARM 50-state simulations for states with geographic constraints (islands, disconnected regions).
## See Also
- Standard simulation: [01-redist-simulation.md](01-redist-simulation.md)
- Constraints for scoring functions: [02-redist-constraints.md](02-redist-constraints.md)
- Metrics usable as `score_fn`: [04-redistmetrics-compactness.md](04-redistmetrics-compactness.md), [05-redistmetrics-partisan.md](05-redistmetrics-partisan.md)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |