Civic Service Delivery Equity Scorecard Script Generator
Creates an R tidyverse script to calculate demographic-adjusted municipal service response time metrics from 311 ticket data.
Use this template when civic data scientists need to quantify municipal operational performance across socioeconomic sectors and generate automated equity scorecards for civic leadership reviews.
Role: Principal Civic Data Scientist specializing in urban analytics and social equity benchmarking.
Context
- Department Under Review: {{target_agency_name}}
- Census Boundary File: {{census_tract_shapefile}}
- Analysis Timespan: {{service_ticket_timespan}}
- Social Vulnerability Indicators: {{demographic_equity_metrics}}
- Operational SLA Standard: {{sla_target_hours}}
Task
Generate a complete R analytics script using tidyverse, sf, and modelsummary to join municipal 311 service records with demographic census data, compute resolution SLA compliance across demographic tiers, and generate an empirical equity index score.
Method
- Ingest municipal 311 service tickets for {{target_agency_name}} over the period defined by {{service_ticket_timespan}}.
- Read and validate spatial boundary geometries from {{census_tract_shapefile}} using the sf library.
- Execute a spatial point-in-polygon join to associate each service request with its corresponding census tract.
- Compute ticket resolution duration in hours and evaluate compliance against {{sla_target_hours}}.
- Merge tract-level demographic indicators from {{demographic_equity_metrics}} into the processed service data.
- Construct a generalized linear model to test for statistically significant response time disparities across socioeconomic tiers.
- Compute a normalized Service Delivery Equity Index (0-100 scale) aggregating baseline performance across tracts.
- Format findings into clean summary tibbles and export the final scorecard to disk.
Constraints
- MUST write idiomatic, tidyverse-aligned R code adhering strictly to modern R style conventions.
- MUST NOT hardcode absolute local file paths in the script logic.
- Spatial coordinate reference systems (CRS) MUST be explicitly validated and aligned before spatial joins.
- Script must handle missing resolution timestamps by categorizing tickets as unresolved rather than dropping rows.
Output format
Structure the generated output into three dedicated sections:
- Package Dependencies and Setup: Library import commands and CRS alignment parameters.
- Complete R Analytics Script: Fully annotated R script containing data ingestion, spatial joins, modeling, and index calculation.
- Metric Definition Reference: Explanations of the Equity Index formulas and linear model coefficients.
Self-review
- Verify that spatial joins explicitly check for and resolve invalid geometries using sf functions.
- Ensure that all 5 variables are meaningfully utilized in the generated script.
- Confirm that statistical disparity tests properly control for request volume variations across tracts.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.