@dra2020/dra-analytics 3.3.1 → 3.3.5

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.
@@ -1 +1 @@
1
- export { ratePopulationDeviation, rateProportionality, rateCompetitiveness, rateMinorityRepresentation, rateCompactness, rateReock, ratePolsby, rateSplitting, rateCountySplitting, rateDistrictSplitting, ratePartisanBias, isAntimajoritarian, popdevThreshold } from '../rate/all';
1
+ export { ratePopulationDeviation, rateProportionality, rateCompetitiveness, rateMinorityRepresentation, rateCompactness, rateReock, ratePolsby, rateSplitting, rateCountySplitting, rateDistrictSplitting, ratePartisanBias, normalizePartisanBias, isAntimajoritarian, popdevThreshold } from '../rate/all';
@@ -1 +1 @@
1
- export { Scorecard, PopulationScorecard, PartisanScorecard, MinorityScorecard, CompactnessScorecard, SplittingScorecard, Dict, PCAModel, MinorityFilter, dictPoint, DemographicVotingByFeature, RPVFactor, RPVAnalysis } from '../types/all';
1
+ export { Scorecard, PopulationScorecard, PartisanScorecard, MinorityScorecard, CompactnessScorecard, SplittingScorecard, Dict, VfArray, SVpoint, rVpoints, PCAModel, MinorityFilter, dictPoint, DemographicVotingByFeature, RPVFactor, RPVAnalysis } from '../types/all';
@@ -12,6 +12,7 @@ export declare function estGeometricSeatsBias(Vf: number, dSVpoints: T.SVpoint[]
12
12
  export declare function inferGeometricSeatsBiasPoints(dSVpoints: T.SVpoint[], rSVpoints: T.SVpoint[]): T.SVpoint[];
13
13
  export declare function invertSVPoints(inferredSVpoints: T.SVpoint[]): T.SVpoint[];
14
14
  export declare function calcEfficiencyGap(Vf: number, Sf: number, shareType?: T.Party): number;
15
+ export declare function calcEfficiencyGapPrime(Vf: number, Sf: number, R: number | undefined): number | undefined;
15
16
  export declare function calcMeanMedianDifference(VfArray: T.VfArray, Vf?: number): number;
16
17
  export declare function keyRVpoints(VfArray: T.VfArray): T.rVpoints;
17
18
  export declare function isASweep(Sf: number, nDistricts: number): boolean;
@@ -4,6 +4,7 @@ export declare function extraBonus(Vf: number): number;
4
4
  export declare function adjustDeviation(Vf: number, disproportionality: number, extra: number): number;
5
5
  export declare function isAntimajoritarian(Vf: number, Sf: number): boolean;
6
6
  export declare function ratePartisanBias(rawSeatsBias: number, rawVotesBias: number): number;
7
+ export declare function normalizePartisanBias(biasPct: number, pctAt50: number): number;
7
8
  export declare function rateCompetitiveness(rawCdf: number): number;
8
9
  export declare function rateMinorityRepresentation(rawOd: number, pOd: number, rawCd: number, pCd: number): number;
9
10
  export declare function rateReock(rawValue: number): number;
package/lib/all/rate.ts CHANGED
@@ -13,7 +13,7 @@ export
13
13
  // rateSplittingLegacy, adjustSplittingRating, rateCountySplittingLegacy, rateDistrictSplittingLegacy,
14
14
 
15
15
  // For use in DRA client UI
16
- ratePartisanBias,
16
+ ratePartisanBias, normalizePartisanBias,
17
17
  isAntimajoritarian,
18
18
 
19
19
  popdevThreshold
package/lib/all/types.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  export
4
4
  {
5
- // Scorecards & helpers
5
+ // Scorecards
6
6
  Scorecard,
7
7
  PopulationScorecard,
8
8
  PartisanScorecard,
@@ -11,6 +11,9 @@ export
11
11
  SplittingScorecard,
12
12
  Dict,
13
13
 
14
+ // Subordinate types
15
+ VfArray, SVpoint, rVpoints,
16
+
14
17
  // For legacy KIWYSI compactness calculations
15
18
  PCAModel,
16
19
 
@@ -262,6 +262,21 @@ export function calcEfficiencyGap(Vf: number, Sf: number, shareType = T.Party.De
262
262
  return efficiencyGap;
263
263
  }
264
264
 
265
+ // For illustration purposes only
266
+ // Assumes Democratic vote shares
267
+ // Alternate specification with winner's bonus (R) heuristic built in:
268
+ // - By convention, '+' = R bias; '-' = D bias
269
+ // - If 1 <= R <= 2, EG is undefined (no/acceptable bias).
270
+ export function calcEfficiencyGapPrime(Vf: number, Sf: number, R: number | undefined): number | undefined
271
+ {
272
+ let EG = undefined;
273
+
274
+ if (R && ((R > 2) || (R < 1)))
275
+ EG = (2.0 * (Vf - 0.5)) - (Sf - 0.5);
276
+
277
+ return EG;
278
+ }
279
+
265
280
  // MEAN–MEDIAN DIFFERENCE
266
281
  //
267
282
  // From PlanScore.org: "The mean-median difference is a party’s median vote share
@@ -409,7 +424,7 @@ export function calcLopsidedOutcomes(VfArray: T.VfArray): number | undefined
409
424
  //
410
425
  // * gSym is the area of asymmetry between the two curves.
411
426
  // * The choice of what base to normalize it by is somewhat arbitrary.
412
- // * We actually only infer the S–V curver over the range [0.25–0.75] <<< 101 points (not 100!)
427
+ // * We actually only infer the S–V curve over the range [0.25–0.75] <<< 101 points (not 100!)
413
428
  // * But dividing by 100 normalizes the area of asymmetry to the area of the SxV unit square.
414
429
  export function calcGlobalSymmetry(dSVpoints: T.SVpoint[], rSVpoints: T.SVpoint[], S50V: number): number
415
430
  {
@@ -146,7 +146,7 @@ export function ratePartisanBias(rawSeatsBias: number, rawVotesBias: number): nu
146
146
  }
147
147
 
148
148
  // NOTE - John Nagle specified this function vs. simple linear normalization
149
- function normalizePartisanBias(biasPct: number, pctAt50: number): number
149
+ export function normalizePartisanBias(biasPct: number, pctAt50: number): number
150
150
  {
151
151
  const b: number = pctAt50 / Math.log(1 / 2);
152
152
  const rating: number = 100 * Math.exp(-Math.abs(biasPct / b));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/dra-analytics",
3
- "version": "3.3.1",
3
+ "version": "3.3.5",
4
4
  "description": "DRA analytics",
5
5
  "main": "dist/dra-analytics.js",
6
6
  "types": "./dist/lib/all/all.d.ts",
@@ -43,27 +43,27 @@
43
43
  "homepage": "https://github.com/dra2020/dra-analytics#readme",
44
44
  "devDependencies": {
45
45
  "@types/geojson": "^7946.0.8",
46
- "@types/jest": "^27.0.1",
46
+ "@types/jest": "^27.0.3",
47
47
  "@types/node": "^12.20.20",
48
48
  "@types/yargs": "^16.0.4",
49
49
  "csv-parse": "^4.16.0",
50
- "jest": "^27.0.6",
50
+ "jest": "^27.4.3",
51
51
  "json-loader": "^0.5.7",
52
52
  "prettier": "^2.3.2",
53
53
  "shapefile": "^0.6.6",
54
54
  "source-map-loader": "^3.0.0",
55
- "ts-jest": "^27.0.5",
56
- "ts-loader": "^9.2.5",
55
+ "ts-jest": "^27.1.1",
56
+ "ts-loader": "^9.2.6",
57
57
  "tsify": "^5.0.4",
58
58
  "tslint": "^6.1.3",
59
59
  "tslint-config-prettier": "^1.18.0",
60
- "typescript": "^4.3.5",
61
- "webpack": "^5.51.1",
62
- "webpack-cli": "^4.8.0",
60
+ "typescript": "^4.5.2",
61
+ "webpack": "^5.65.0",
62
+ "webpack-cli": "^4.9.1",
63
63
  "yargs": "^17.1.1"
64
64
  },
65
65
  "dependencies": {
66
- "@dra2020/baseclient": "^1.0.54",
66
+ "@dra2020/baseclient": "^1.0.67",
67
67
  "geojson": "^0.5.0"
68
68
  }
69
69
  }