County map
Choropleth frommodel_frame · optional overlays
Distribution chart
Top counties by selected variable (bar length = value).
Results table
| Build a dataframe, then Apply map. |
Follow the steps below: set Year(s) and Geography,
choose outcome Y from one source, then select Features
from County Health Rankings,
Social Vulnerability Index, USA Health Experience,
USA Mortality Data,
USA Cancer Atlas,
USA Overdose Mortality, and/or
Census Demography,
Religion Census, and/or
Presidential Election Data.
Rows join on county FIPS into AlaSQL table model_frame.
Check one or more years for a county × year panel (year column in model_frame). Optional Mean of selected years averages numeric fields by FIPS. County Health Rankings (2020–2025) and Census Demography (PEP 2010–2023) use the selected year; Religion Census (2010, 2020) and Presidential Election Data (2004–2024) use the nearest election/census year; SVI is 2022; mortality is 2019–2023; Health Experience is the current PLACES release.
Contiguous U.S. includes 48 states + DC (excludes AK, HI, PR). Or pick a single state.
Pick the data source, then the variable to predict (dependent variable).
Health Experience values are crude prevalence (%).
CHR national county releases (2020–2025) · measures and ranks for the selected year(s). Obesity/diabetes are proportions (0–1). Use Load & select all CHR to pull the full variable list from the County Health Rankings explorer.
CDC/ATSDR SVI 2022 · US percentile ranks (0–1).
CDC PLACES crude prevalence (%).
NIMHD HDPulse · age-adjusted deaths per 100,000 (2019–2023). See USA Mortality Data.
Census PEP · 20 county indicators: population & change, births/deaths/migration, age/sex, race/ethnicity, % rural (2010–2023; nearest year per pipeline row). See Census Demography.
U.S. Religion Census (RCMS) · 10 dominant traditions plus total adherents; adherents, congregations, rate per 1,000, and % of population (2010, 2020; nearest year per pipeline row). See Religion Census.
County presidential returns · Democratic/Republican votes and percentages, margin (D − R), and two-party shares (2004, 2008, 2012, 2016, 2020, 2024; nearest election year per pipeline row). See Presidential Election Data.
State Cancer Profiles county rates — synthetic annual incidence (2020–2025), observed pooled incidence (2017–2021), and reconstructed mortality (2019–2023). See USA Cancer Atlas.
Live CDC/NCHS county layers — model-based rates (2003–2021), VSRR provisional counts (2020→), and VSRR opioid totals allocated to counties (2020→). See USA Overdose Mortality.
Outcome (Y) must be present for each row. Imputation applies to selected features only — not Y, FIPS, or geography fields.
Complete steps 1–5, then Build dataframe.
| Build a dataframe to preview rows here. |
After building, open Exploratory Data Analysis to map columns and run
descriptive statistics. Map tip: selected variable is copied to val for choropleths.
model_frame · optional overlays
Top counties by selected variable (bar length = value).
| Build a dataframe, then Apply map. |
Run an analysis to see results here.
Equivalent pandas / SciPy / statsmodels workflow for the selected analysis.
Assumes df is the model_frame built in Data Pipeline
(or loaded from an exported CSV).
Run an analysis to see reproducible Python here.
| No analysis yet. |
County health data live on a map, not in a spreadsheet row. Spatial statistics asks how where a county is affects the numbers you see — and whether ignoring location would mislead you. Tobler's First Law of Geography says it plainly: "Everything is related to everything else, but near things are more related than distant things."
After you build a model_frame in the Data Pipeline, use the six workflows below to explore
clustering, model spatial dependence, smooth unstable small-area rates, and detect disease hot spots.
Each tab runs in your browser and can export full Python code for PySAL / esda / mgwr.
Plain English Look at a choropleth map of diabetes prevalence. If high counties sit next to other high counties (and low next to low), the map is spatially autocorrelated — similarity depends on location.
Weights We encode "who is a neighbor" in a matrix W. Entry wij = 1 if counties i and j share a border (queen/rook), or a positive number if they are close (distance / k-NN). Row-standardized weights make each county's neighbors sum to 1.
Global Moran's I — one number for the whole map:
I = (n / S0) · [ Σi Σj wij (yi − ȳ)(yj − ȳ) ] / [ Σi (yi − ȳ)² ]
Local Moran's I (LISA) — one score per county. Let zi = (yi − ȳ) / SD(y):
Ii = zi · Σj wij zj
p-value We shuffle county values across the map many times (permutations) and ask: "How often does random data produce an I this extreme?" A small p-value means clustering is unlikely to be chance.
Global Moran's I, Moran scatterplot, and LISA cluster maps for county health outcomes.
| Run analysis to see LISA summary. |
Select an outcome and click Show Python.
Plain English Univariate LISA asks whether a county is high among high neighbours for the same variable. Bivariate LISA links two variables: is high mortality at county i associated with high poverty in neighbouring counties?
Bivariate Local Moran's I — one score per county:
IiXY = zX,i · Σj wij zY,j
Quadrants Significant clusters use the same HH / LL / HL / LH labels, but X is at county i and the lag uses Y in neighbours:
p-value Y values are permuted across counties many times while X stays fixed; a small p-value means the X–lag(Y) association at that location is unlikely to be chance.
HH = high X, high neighbour Y · LL = low X, low neighbour Y · HL/LH = discordant · NS = not significant (p ≥ 0.05)
Bivariate Local Moran's I cluster maps for cross-variable spatial association.
| Run analysis to see bivariate LISA summary. |
Select X and Y variables and click Show Python.
Plain English Ordinary regression predicts health outcomes from risk factors. But if unmeasured nearby influences matter (shared hospitals, pollution plumes, policy regions), standard errors and coefficients can be wrong. Spatial regression models that extra "location effect."
Ordinary least squares (OLS) baseline:
y = Xβ + ε
y = outcome vector, X = predictors (poverty, smoking, …), β = coefficients, ε = leftover error. If Moran's I on ε is significant, OLS assumes independence that the map violates.
SLX — spatially lagged exogenous regressors (neighbours' covariates):
y = Xβ + WXθ + ε
(WX)i = Σj wij Xj is the weighted average of covariate X in neighbours of county i. β captures local effects; θ captures spillover from neighbouring characteristics (e.g. neighbour poverty affecting local mortality).
Spatial Lag Model (SAR / SLM) — outcome spills to neighbors (like a contagion):
y = ρ W y + Xβ + ε
ρ (rho) measures spillover: a high value in county j pulls up county i even after controlling for X. Example intuition: opioid deaths in one county affect neighboring counties.
Spatial Error Model (SEM) — hidden regional shocks in the errors:
y = Xβ + u, u = λ W u + ε
λ (lambda) lets errors be correlated across space (unobserved regional factors), while coefficients β stay global.
Workflow here Run OLS + residual Moran's I first. If residuals cluster, try SLX (neighbours' X), SAR (lagged Y), or SEM (spatial errors). Use Compare models for an AIC table (OLS & SLX in-browser; SAR & SEM via Python export).
| Run compare mode to see AIC table. |
| Run SLX or compare mode to see coefficients. |
Diagnose residual spatial autocorrelation; fit SLX, spatial lag, or spatial error models.
Select Y, predictors, and model type.
Plain English Global correlation or regression assumes one relationship everywhere on the map. Geographically weighted methods let the relationship change by location — poverty may matter more in some regions than others.
GWCORR — local weighted Pearson correlation at county i:
wij = exp(−dij² / 2h²), ri = Covi(y₁, y₂) / (σ1,i σ2,i)
Gaussian weights emphasize nearby counties; h is the bandwidth (auto-selected as 30th percentile of distances if blank).
GW-OLS — location-specific coefficients:
yi = β0(ui, vi) + Σj βj(ui, vi) Xij + εi
Each βj is estimated by weighted least squares using neighbours within the bandwidth (mgwr in Python export).
GW-RF — locally weighted random forest:
Train RFi on {(Xk, yk), wik}k=1n
At each location, samples are weighted by proximity; local feature importance maps show which predictors explain variation there.
GWCORR, GW-OLS, and GW-RF for spatially varying relationships.
Select model and variables, then click Show Python.
Plain English A county with 2 deaths in 1,000 people can look terrifying on a map — or harmless — depending on luck. Disease mapping stabilizes noisy small-area rates by "borrowing strength" from the regional average (and optionally from neighbors).
Raw standardized mortality / incidence ratio (SMR):
SMRi = Oi / Ei
Oi = observed cases, Ei = expected cases if the county matched the national rate × population. SMR = 1 is average; SMR = 2 is double the expected rate.
Empirical Bayes (gamma–Poisson) shrinkage — a weighted average:
θ̂i = wi · SMRi + (1 − wi) · SMR̄
θ̂i is the smoothed rate. wi ∈ (0, 1) is the shrinkage weight: large populous counties keep their raw SMR (wi → 1); tiny counties get pulled toward the overall mean SMR̄ (wi → 0). The map becomes less speckled but more honest about uncertainty.
BYM model (Besag–York–Mollié) — adds spatial neighbors:
log θi = α + ui + vi, vi ~ CAR(W), ui ~ iid
vi is a spatially structured random effect (similar counties move together); ui is unstructured noise. In practice this produces smooth regional patterns instead of isolated outlier counties.
Read the maps Compare Raw vs Smoothed: extreme colors that disappear after smoothing were likely small-number noise, not true hot spots.
Compare raw county rates vs empirical Bayes or BYM-smoothed disease maps.
Select a rate column for disease mapping.
Plain English LISA finds many local hot spots. A spatial scan asks a sharper question: "Is there one window on the map with surprisingly many cases, compared to what we'd expect?"
Expected cases under a constant risk:
Ei = (Σ O / Σ P) · Pi
Total observed cases O spread proportionally to each county's population Pi.
Kulldorff log-likelihood ratio (Poisson scan) for a candidate cluster C:
LLR(C) = OC log(OC/EC) + OC̄ log(OC̄/EC̄)
OC, EC = observed & expected inside the window; C̄ = outside. The algorithm grows a circle (or neighbor set) from every county and keeps the window with the largest LLR.
p-value Monte Carlo: randomly redistribute total cases across counties many times, re-run the scan each time, and count how often a random LLR ≥ your observed LLR. A small p-value means the cluster is unlikely to be chance.
LISA comparison LISA HH flags counties that are high with high neighbors — many small clusters. The scan finds the single best cluster window; use both maps together for confirmation.
Detect significant disease clusters with spatial scan statistics.
Select outcome and population for cluster detection.
Train and compare regression models on your model_frame:
filter by year and county sample, split data, select covariates, pick models, choose metrics, run training, and explore variable importance.
Select features in the sidebar.
Shared goal Predict outcome Y (e.g. overdose rate) from features X = (x₁, …, xₚ). Each model learns a function ŷ = f(X) and we score it with RMSE, MAE, or R².
OLS — Ordinary Least Squares (plain linear regression).
ŷ = β₀ + β₁x₁ + … + βₚxₚ
Pick β to minimize Σ(yᵢ − ŷᵢ)². Fast baseline; assumes a straight-line relationship.
Ridge — OLS + penalty on large coefficients (L2).
min Σ(yᵢ − ŷᵢ)² + α Σ βⱼ²
Shrinks coefficients toward zero; helps when covariates are correlated.
Lasso — OLS + L1 penalty; can zero out weak features.
min Σ(yᵢ − ŷᵢ)² + α Σ |βⱼ|
Elastic Net — mix of Ridge + Lasso.
min Σ(yᵢ − ŷᵢ)² + α [ ρΣ|βⱼ| + (1−ρ)Σβⱼ² ]
Random Forest — many decision trees on random row/feature subsamples; average their votes.
ŷ = (1/B) Σb=1B Tb(X)
Each tree asks yes/no questions (e.g. poverty > 20%?) until a leaf prediction.
Gradient Boosting — add small trees one at a time to fix previous errors.
Fm(X) = Fm−1(X) + η · hm(X), hm fits residuals (y − Fm−1)
η = learning rate (small steps → less overfitting).
XGBoost — boosted trees with regularization (depth limit, row/column subsample, λ on leaf weights).
obj = Σ L(yᵢ, ŷᵢ) + Σ [ γT + ½λ Σ wj² ]
Similar to GBM but optimized for speed and controlled complexity.
LightGBM — gradient boosting with deeper, leaf-wise trees (grows where loss drops most).
ŷ = F0 + η Σm treem(X)
Often fast on many rows; here approximated with deeper GBM-style trees in-browser.
k-NN — predict from the k nearest counties in feature space (distance-weighted average).
ŷ = Σ wᵢ yᵢ / Σ wᵢ, wᵢ = 1 / (dᵢ + ε)
Needs scaled features; local, non-parametric.
MLP — small neural net: hidden ReLU layer + linear output.
h = ReLU(W₁X + b₁), ŷ = W₂h + b₂
Can capture mild non-linearity; trained with gradient descent on squared error.
SHAP (Variable Importance tab) — fair credit per feature for each prediction. Click Compute SHAP after training (sampled rows; keeps the page responsive).
φᵢ = ΣS⊆N\{i} [|S|!(|N|−|S|−1)! / |N|!] · [ v(S∪{i}) − v(S) ]
Global = mean |φ| across rows; local = waterfall for individual counties. Computed for the top 4 features by permutation importance.
Enable ensemble to see stacking diagram.
Run training to see tuned parameters per model.
Run training to generate sklearn code.
| Run models to see results. |
Plain English SHAP assigns each feature a contribution φᵢ showing how much it pushed the prediction above or below the average. We rank features by permutation importance, keep the top 4, then compute exact Shapley values (all 2⁴ coalitions).
ŷ = φ₀ + φ₁ + … + φ₄ (φ₀ = baseline prediction with no feature info)
Global — mean |φᵢ| across evaluation rows (which drivers matter on average). Local — waterfall for sample rows (why this county scored high/low). County map — full evaluation-set φᵢ per FIPS for the top features.
Click Compute SHAP for charts (sampled rows). Build the county map separately — keeps the page responsive.
One row per evaluation county (fips) with exact SHAP φ for the top features.
County SHAP runs in the background (one county per tick) so the tab stays responsive.
Compute SHAP charts, then click Build county SHAP frame.
| — |