@dra2020/district-analytics 5.4.0 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +12 -6
- package/dist/cli.js.map +1 -1
- package/package.json +13 -13
package/dist/cli.js
CHANGED
|
@@ -89430,7 +89430,9 @@ function evalMinorityOpportunity(p, bLog = false) {
|
|
|
89430
89430
|
// Calculate average Democratic win share
|
|
89431
89431
|
const VfArray = p.partisanProfile.vfArray;
|
|
89432
89432
|
const DWins = VfArray.filter(x => x > 0.5);
|
|
89433
|
+
const RWins = VfArray.filter(x => x <= 0.5); // Ties credited to R's
|
|
89433
89434
|
const averageDVf = (DWins.length > 0) ? U.avgArray(DWins) : undefined;
|
|
89435
|
+
const averageRVf = (RWins.length > 0) ? U.avgArray(RWins) : undefined;
|
|
89434
89436
|
// Determine proportional minority districts by demographic (ignore 'White')
|
|
89435
89437
|
const districtsByDemo = calcDistrictsByDemo(p.demographicProfile.stateMfArray.slice(1), p.nDistricts);
|
|
89436
89438
|
// Initialize arrays for results
|
|
@@ -89438,6 +89440,7 @@ function evalMinorityOpportunity(p, bLog = false) {
|
|
|
89438
89440
|
const nDemos = 6 /* Native */ + 1 - offset; // Ditto
|
|
89439
89441
|
const nBuckets = 2; // 37–50% and > 50%
|
|
89440
89442
|
const demosByDistrict = p.demographicProfile.mfArrayByDistrict;
|
|
89443
|
+
// Initialize the demographic buckets
|
|
89441
89444
|
let bucketsByDemo = new Array(nDemos);
|
|
89442
89445
|
for (let j = 0; j < nDemos; j++) {
|
|
89443
89446
|
bucketsByDemo[j] = [0, 0];
|
|
@@ -89459,13 +89462,14 @@ function evalMinorityOpportunity(p, bLog = false) {
|
|
|
89459
89462
|
}
|
|
89460
89463
|
// Sum the # of opportunity districts - ignore total minority
|
|
89461
89464
|
const oD = U.sumArray(opptyByDemo.slice(1));
|
|
89462
|
-
// Sum the # of
|
|
89465
|
+
// Sum the # of proportional districts - ignore total minority
|
|
89463
89466
|
const pD = U.sumArray(districtsByDemo.slice(1));
|
|
89464
89467
|
// Score opportunity
|
|
89465
89468
|
const score = scoreMinority(oD, pD);
|
|
89466
89469
|
let mS = {
|
|
89467
89470
|
report: {
|
|
89468
89471
|
averageDVf: averageDVf,
|
|
89472
|
+
averageRVf: averageRVf,
|
|
89469
89473
|
bucketsByDemographic: bucketsByDemo
|
|
89470
89474
|
},
|
|
89471
89475
|
nProportional: pD,
|
|
@@ -89682,7 +89686,7 @@ const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts")
|
|
|
89682
89686
|
* MM' [mMd] = Mean – median difference using average district v
|
|
89683
89687
|
* LO [LO] = Lopsided outcomes
|
|
89684
89688
|
|
|
89685
|
-
* B% [bias]= the bias calculated as S% – ^S%
|
|
89689
|
+
* B% [bias] = the bias calculated as S% – ^S%
|
|
89686
89690
|
* B$ [bias.score] = the bias score normalized [0–100]
|
|
89687
89691
|
|
|
89688
89692
|
* UE# [unearnedS] = the number of unearned seats (R = positive; D = negative)
|
|
@@ -89728,6 +89732,7 @@ function scorePartisan(Vf, VfArray, options) {
|
|
|
89728
89732
|
const Bs50 = bAlternateMetrics ? estPartisanBias(inferredSVpoints, N) : undefined;
|
|
89729
89733
|
const Bs50f = (!(Bs50 === undefined)) ? U.trim(Bs50 / N) : undefined;
|
|
89730
89734
|
const Bv50f = bAlternateMetrics ? estVotesBias(inferredSVpoints, N) : undefined;
|
|
89735
|
+
const rvPoints = bAlternateMetrics ? keyRVpoints(VfArray) : undefined;
|
|
89731
89736
|
const decl = bAlternateMetrics ? calcDeclination(VfArray) : undefined;
|
|
89732
89737
|
const gSym = bAlternateMetrics ? calcGlobalSymmetry(inferredSVpoints, Bs50f) : undefined;
|
|
89733
89738
|
const EG = bAlternateMetrics ? calcEfficiencyGap(Vf, estSf) : undefined;
|
|
@@ -89778,6 +89783,7 @@ function scorePartisan(Vf, VfArray, options) {
|
|
|
89778
89783
|
biasScoring.bS50 = Bs50f;
|
|
89779
89784
|
biasScoring.bV50 = Bv50f;
|
|
89780
89785
|
biasScoring.decl = decl;
|
|
89786
|
+
biasScoring.rvPoints = rvPoints;
|
|
89781
89787
|
biasScoring.gSym = gSym;
|
|
89782
89788
|
biasScoring.gamma = gamma;
|
|
89783
89789
|
biasScoring.eG = EG;
|
|
@@ -90171,9 +90177,9 @@ function estMarginalCompetitiveDistricts(Mrange, VfArray) {
|
|
|
90171
90177
|
const maxId = Mrange[C.END];
|
|
90172
90178
|
// Sort the array values, and subset it to those districts
|
|
90173
90179
|
// NOTE - I'm *not* keeping track of the district indexes right now
|
|
90174
|
-
let subsetVfArray = VfArray.sort().slice(minId - 1, maxId);
|
|
90180
|
+
let subsetVfArray = U.deepCopy(VfArray).sort().slice(minId - 1, maxId);
|
|
90175
90181
|
// Est. competitive districts on that array
|
|
90176
|
-
const Md = U.sumArray(subsetVfArray.map(v => estDistrictCompetitiveness(v)));
|
|
90182
|
+
const Md = U.sumArray(subsetVfArray.map((v) => estDistrictCompetitiveness(v)));
|
|
90177
90183
|
return U.trim(Md);
|
|
90178
90184
|
}
|
|
90179
90185
|
exports.estMarginalCompetitiveDistricts = estMarginalCompetitiveDistricts;
|
|
@@ -90360,7 +90366,7 @@ exports.estMeanMedianDifference = estMeanMedianDifference;
|
|
|
90360
90366
|
// HELPERS FOR DECLINATION & LOPSIDED OUTCOMES
|
|
90361
90367
|
// Key r(v) points, defined in Fig. 19:
|
|
90362
90368
|
// * VfArray are Democratic seat shares (by convention).
|
|
90363
|
-
// * But the x-axis of r(v) graphs
|
|
90369
|
+
// * But the x-axis of r(v) graphs is Republican seat share.
|
|
90364
90370
|
// * So, you have to invert the D/R axis for Vb; and
|
|
90365
90371
|
// * Invert the D/R probabilities for Va.
|
|
90366
90372
|
function keyRVpoints(VfArray) {
|
|
@@ -90369,7 +90375,7 @@ function keyRVpoints(VfArray) {
|
|
|
90369
90375
|
const Sb = estSeatShare(estS, nDistricts);
|
|
90370
90376
|
// TODO - Understand why the corresponding V to Sb is always @ 0.5.
|
|
90371
90377
|
// John Nagle: "This is the dividing vote for party A vs party B wins defined
|
|
90372
|
-
// by Warrington.My modification just puts fractions of districts to the each side."
|
|
90378
|
+
// by Warrington. My modification just puts fractions of districts to the each side."
|
|
90373
90379
|
const Rb = Sb / 2;
|
|
90374
90380
|
const Ra = (1 + Sb) / 2;
|
|
90375
90381
|
const Vb = 1.0 - (U.sumArray(VfArray.map(v => estSeatProbability(v) * v))) / estS;
|