@civiq/civic-statistics
Civic data statistics utilities — correlation, peer comparison, and confidence scoring with civic-domain defaults.
Install
npm install @civiq/civic-statistics
Quick Start
import {
correlation,
peerComparison,
confidenceScore,
meetsSampleSize,
} from '@civiq/civic-statistics';
const result = correlation(donations, votingScores);
const comparison = peerComparison(0.73, peerValues, 'Senate Finance Committee');
const confidence = confidenceScore({
sampleSize: 25,
minimumSampleSize: 10,
dataCompleteness: 0.9,
peerCount: 15,
});
meetsSampleSize(8, 'votes');
meetsSampleSize(5, 'trades');
API Reference
correlation(x, y, options?)
Compute correlation between two numeric arrays. Defaults to Spearman rank correlation (robust to non-normal distributions typical in civic data).
Returns null if arrays differ in length, have fewer than minimumSampleSize elements, or contain zero variance.
peerComparison(value, peerValues, peerGroupLabel)
Compare a value against a peer group using percentile rank. Returns null if fewer than 3 peers.
confidenceScore(factors)
Compute a confidence score (0-1) based on sample size, data completeness, and peer count. Below 0.6 = hide, 0.6-0.8 = amber, above 0.8 = green.
meetsSampleSize(actual, type)
Check if a sample size meets the minimum threshold. Types: votes (10), quarters (4), trades (3), peers (3), filings (5), recipients (3).
mean(values), sampleStandardDeviation(values)
Re-exported from simple-statistics for convenience.
Constants
MIN_VOTES_PER_SECTOR | 10 | Vote-finance correlation |
MIN_QUARTERS_TEMPORAL | 4 | Temporal analysis |
MIN_TRADES_STOCK | 3 | Stock-committee analysis |
MIN_FILINGS_LOBBYING | 5 | Lobbying pipeline |
MIN_PAC_RECIPIENTS | 3 | PAC-vote analysis |
MIN_RELEVANT_VOTES | 3 | Per-recipient PAC votes |
MIN_PEERS | 3 | Peer comparison |
Data Sources
This library provides statistical utilities for analyzing data from:
- Congress.gov API (voting records, bill classifications)
- FEC.gov API (campaign contributions, PAC disbursements)
- Senate LDA API (lobbying filings)
- House Clerk (stock trade disclosures)
License
MIT - Mark Sandford