@dra2020/district-analytics 5.4.1 → 5.5.0

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 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 proportion districts - ignore total minority
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;
@@ -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 us Republican seat share.
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;