@dra2020/dra-analytics 3.2.0 → 3.3.3
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/cli/partisan.ts +21 -21
- package/dist/dra-analytics.js +19 -7
- package/dist/dra-analytics.js.map +1 -1
- package/dist/lib/all/types.d.ts +1 -1
- package/dist/lib/partisan/bias.d.ts +3 -2
- package/lib/all/types.ts +4 -1
- package/lib/partisan/all.ts +1 -1
- package/lib/partisan/bias.ts +20 -6
- package/package.json +10 -10
package/cli/partisan.ts
CHANGED
|
@@ -123,48 +123,48 @@ function trim(fullFraction: number, digits: number | undefined = undefined): num
|
|
|
123
123
|
// Generate partisan details (Table 1)
|
|
124
124
|
export function printPartisanDetailsHeader(): void
|
|
125
125
|
{
|
|
126
|
-
console.log('XX, <V>, S(<V>),
|
|
126
|
+
console.log('XX, <V>, S(<V>), R, r, MIR, Decl, LO, MM, BS_50, BV_50, β, GS, PR, EG, 𝛾, B%, LPR\', LUE');
|
|
127
|
+
// console.log('XX, <V>, S(<V>), Rd, R, r, MIR, Cd, Cdf, BS_50, BV_50, Decl, GS, 𝛾, β, LO, EG, PR, MM, TO, MM\', B%, UE, LS, LPR, LPR\', LUE');
|
|
127
128
|
// console.log('XX, <V>, S(<V>), B%, BS_50, BV_50, Decl, GS, EG, Beta, PR, MM, TO, MM\', LO, Rd, R, r, MIR, Cd, Cdf, LS, LPR, LPR\'');
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export function printPartisanDetailsRow(xx: string, name: string, N: number, Vf: number, s: T.PartisanScorecard): void
|
|
131
132
|
{
|
|
132
|
-
console.log('%s, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f',
|
|
133
|
+
// console.log('%s, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f',
|
|
134
|
+
console.log('%s, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f',
|
|
133
135
|
xx,
|
|
134
136
|
|
|
135
137
|
trim(Vf),
|
|
136
138
|
trim(s.bias.estSf),
|
|
137
139
|
|
|
138
|
-
trim(s.responsiveness.rD),
|
|
139
|
-
(s.responsiveness.bigR) ? trim(s.responsiveness.bigR) : s.responsiveness.bigR,
|
|
140
|
-
(s.responsiveness.littleR) ? trim(s.responsiveness.littleR) : s.responsiveness.littleR,
|
|
141
|
-
(s.responsiveness.mIR) ? trim(s.responsiveness.mIR) : s.responsiveness.mIR,
|
|
140
|
+
// trim(s.responsiveness.rD),
|
|
141
|
+
(s.responsiveness.bigR) ? trim(s.responsiveness.bigR) : s.responsiveness.bigR,
|
|
142
|
+
(s.responsiveness.littleR) ? trim(s.responsiveness.littleR) : s.responsiveness.littleR,
|
|
143
|
+
(s.responsiveness.mIR) ? trim(s.responsiveness.mIR) : s.responsiveness.mIR,
|
|
142
144
|
|
|
143
|
-
trim(s.responsiveness.cD),
|
|
144
|
-
trim(s.responsiveness.cDf),
|
|
145
|
+
// trim(s.responsiveness.cD),
|
|
146
|
+
// trim(s.responsiveness.cDf),
|
|
147
|
+
|
|
148
|
+
(s.bias.decl) ? trim(s.bias.decl) : s.bias.decl,
|
|
149
|
+
(s.bias.lO) ? trim(s.bias.lO) : s.bias.lO,
|
|
150
|
+
trim(s.bias.mMs),
|
|
151
|
+
// trim(s.bias.tOf),
|
|
152
|
+
// trim(s.bias.mMd),
|
|
145
153
|
|
|
146
154
|
trim(s.bias.bS50),
|
|
147
155
|
(s.bias.bV50) ? trim(s.bias.bV50) : s.bias.bV50,
|
|
148
|
-
(s.bias.
|
|
156
|
+
(s.bias.bSV) ? trim(s.bias.bSV) : s.bias.bSV, // Beta
|
|
149
157
|
trim(s.bias.gSym),
|
|
150
|
-
(s.bias.gamma) ? trim(s.bias.gamma) : s.bias.gamma,
|
|
151
158
|
|
|
152
|
-
(s.bias.bSV) ? trim(s.bias.bSV) : s.bias.bSV, // Beta
|
|
153
|
-
(s.bias.lO) ? trim(s.bias.lO) : s.bias.lO,
|
|
154
159
|
trim(s.bias.prop), // PR
|
|
155
160
|
trim(s.bias.eG),
|
|
156
|
-
|
|
157
|
-
trim(s.bias.mMs), // Not shown in Table 1
|
|
158
|
-
trim(s.bias.tOf), // Not shown in Table 1
|
|
159
|
-
trim(s.bias.mMd), // Not shown in Table 1
|
|
161
|
+
(s.bias.gamma) ? trim(s.bias.gamma) : s.bias.gamma,
|
|
160
162
|
|
|
161
163
|
trim(s.bias.deviation), // Simple deviation from best # of seats
|
|
162
|
-
trim(s.
|
|
163
|
-
|
|
164
|
-
// EXPERIMENTAL
|
|
165
|
-
(s.experimental.lSym) ? trim(s.experimental.lSym) : s.experimental.lSym,
|
|
166
|
-
(s.experimental.lProp) ? trim(s.experimental.lProp) : s.experimental.lProp,
|
|
164
|
+
// (s.experimental.lProp) ? trim(s.experimental.lProp) : s.experimental.lProp,
|
|
167
165
|
(s.experimental.lPropAlt) ? trim(s.experimental.lPropAlt) : s.experimental.lPropAlt,
|
|
166
|
+
// trim(s.impact.unearnedS),
|
|
168
167
|
(s.experimental.lUE) ? trim(s.experimental.lUE) : s.experimental.lUE
|
|
168
|
+
// (s.experimental.lSym) ? trim(s.experimental.lSym) : s.experimental.lSym,
|
|
169
169
|
);
|
|
170
170
|
}
|
package/dist/dra-analytics.js
CHANGED
|
@@ -1636,7 +1636,7 @@ function makePartisanScorecard(Vf, VfArray, bLog = false) {
|
|
|
1636
1636
|
const lSym = (0, bias_1.estLocalAsymmetry)(Vf, dSVpoints, rSVpoints);
|
|
1637
1637
|
const lProp = (0, bias_1.estLocalDisproportionality)(Vf, dSVpoints);
|
|
1638
1638
|
const lPropAlt = (0, bias_1.estLocalDisproportionalityAlt)(Vf, N, dSVpoints);
|
|
1639
|
-
const lUE = (0, bias_1.estLocalUnearnedSeats)(Vf, N,
|
|
1639
|
+
const lUE = (0, bias_1.estLocalUnearnedSeats)(Vf, N, dSVpoints);
|
|
1640
1640
|
const biasMeasurements = {
|
|
1641
1641
|
bestS: bestS,
|
|
1642
1642
|
bestSf: bestSf,
|
|
@@ -1737,7 +1737,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
1737
1737
|
return result;
|
|
1738
1738
|
};
|
|
1739
1739
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1740
|
-
exports.rangeUnearnedSeats = exports.estLocalUnearnedSeats = exports.rangeDisproportionalityAlt = exports.estLocalDisproportionalityAlt = exports.rangeDisproportionality = exports.estLocalDisproportionality = exports.rangeAsymmetry = exports.estLocalAsymmetry = exports.calcGamma = exports.calcMinimalInverseResponsiveness = exports.calcBigR = exports.calcDisproportionality = exports.calcGlobalSymmetry = exports.calcLopsidedOutcomes = exports.calcDeclination = exports.radiansToDegrees = exports.isASweep = exports.keyRVpoints = exports.calcMeanMedianDifference = exports.calcEfficiencyGap = exports.invertSVPoints = exports.inferGeometricSeatsBiasPoints = exports.estGeometricSeatsBias = exports.estVotesBias = exports.estSeatBias = exports.estPartisanBias = exports.calcTurnoutBias = exports.estUnearnedSeats = exports.calcDisproportionalityFromBest = exports.estSeatShare = exports.bestSeatShare = exports.bestSeats = void 0;
|
|
1740
|
+
exports.rangeUnearnedSeats = exports.estLocalUnearnedSeats = exports.rangeDisproportionalityAlt = exports.estLocalDisproportionalityAlt = exports.rangeDisproportionality = exports.estLocalDisproportionality = exports.rangeAsymmetry = exports.estLocalAsymmetry = exports.calcGamma = exports.calcMinimalInverseResponsiveness = exports.calcBigR = exports.calcDisproportionality = exports.calcGlobalSymmetry = exports.calcLopsidedOutcomes = exports.calcDeclination = exports.radiansToDegrees = exports.isASweep = exports.keyRVpoints = exports.calcMeanMedianDifference = exports.calcEfficiencyGapPrime = exports.calcEfficiencyGap = exports.invertSVPoints = exports.inferGeometricSeatsBiasPoints = exports.estGeometricSeatsBias = exports.estVotesBias = exports.estSeatBias = exports.estPartisanBias = exports.calcTurnoutBias = exports.estUnearnedSeats = exports.calcDisproportionalityFromBest = exports.estSeatShare = exports.bestSeatShare = exports.bestSeats = void 0;
|
|
1741
1741
|
const U = __importStar(__webpack_require__(/*! ../utils/all */ "./lib/utils/all.ts"));
|
|
1742
1742
|
const C = __importStar(__webpack_require__(/*! ../rate/dra-config */ "./lib/rate/dra-config.ts"));
|
|
1743
1743
|
const method_1 = __webpack_require__(/*! ./method */ "./lib/partisan/method.ts");
|
|
@@ -1925,6 +1925,18 @@ function calcEfficiencyGap(Vf, Sf, shareType = 0 /* Democratic */) {
|
|
|
1925
1925
|
return efficiencyGap;
|
|
1926
1926
|
}
|
|
1927
1927
|
exports.calcEfficiencyGap = calcEfficiencyGap;
|
|
1928
|
+
// For illustration purposes only
|
|
1929
|
+
// Assumes Democratic vote shares
|
|
1930
|
+
// Alternate specification with winner's bonus (R) heuristic built in:
|
|
1931
|
+
// - By convention, '+' = R bias; '-' = D bias
|
|
1932
|
+
// - If 1 <= R <= 2, EG is undefined (no/acceptable bias).
|
|
1933
|
+
function calcEfficiencyGapPrime(Vf, Sf, R) {
|
|
1934
|
+
let EG = undefined;
|
|
1935
|
+
if (R && ((R > 2) || (R < 1)))
|
|
1936
|
+
EG = (2.0 * (Vf - 0.5)) - (Sf - 0.5);
|
|
1937
|
+
return EG;
|
|
1938
|
+
}
|
|
1939
|
+
exports.calcEfficiencyGapPrime = calcEfficiencyGapPrime;
|
|
1928
1940
|
// MEAN–MEDIAN DIFFERENCE
|
|
1929
1941
|
//
|
|
1930
1942
|
// From PlanScore.org: "The mean-median difference is a party’s median vote share
|
|
@@ -2044,7 +2056,7 @@ exports.calcLopsidedOutcomes = calcLopsidedOutcomes;
|
|
|
2044
2056
|
//
|
|
2045
2057
|
// * gSym is the area of asymmetry between the two curves.
|
|
2046
2058
|
// * The choice of what base to normalize it by is somewhat arbitrary.
|
|
2047
|
-
// * We actually only infer the S–V
|
|
2059
|
+
// * We actually only infer the S–V curve over the range [0.25–0.75] <<< 101 points (not 100!)
|
|
2048
2060
|
// * But dividing by 100 normalizes the area of asymmetry to the area of the SxV unit square.
|
|
2049
2061
|
function calcGlobalSymmetry(dSVpoints, rSVpoints, S50V) {
|
|
2050
2062
|
let gSym = 0.0;
|
|
@@ -2185,19 +2197,19 @@ function rangeDisproportionalityAlt(N, dSVpoints) {
|
|
|
2185
2197
|
}
|
|
2186
2198
|
exports.rangeDisproportionalityAlt = rangeDisproportionalityAlt;
|
|
2187
2199
|
// Average local unearned seats from the best # of seats (closest to proportional)
|
|
2188
|
-
function estLocalUnearnedSeats(Vf, N,
|
|
2200
|
+
function estLocalUnearnedSeats(Vf, N, dSVpoints) {
|
|
2189
2201
|
const dPts = svPointRange(Vf, dSVpoints);
|
|
2190
2202
|
if (!dPts)
|
|
2191
2203
|
return undefined;
|
|
2192
|
-
const
|
|
2193
|
-
const lUE = rangeUnearnedSeats(N, estS, dPts);
|
|
2204
|
+
const lUE = rangeUnearnedSeats(N, dPts);
|
|
2194
2205
|
return lUE;
|
|
2195
2206
|
}
|
|
2196
2207
|
exports.estLocalUnearnedSeats = estLocalUnearnedSeats;
|
|
2197
|
-
function rangeUnearnedSeats(N,
|
|
2208
|
+
function rangeUnearnedSeats(N, dSVpoints) {
|
|
2198
2209
|
const ndPts = dSVpoints.length;
|
|
2199
2210
|
let tot = 0.0;
|
|
2200
2211
|
for (let i in dSVpoints) {
|
|
2212
|
+
const estS = dSVpoints[i].s * N;
|
|
2201
2213
|
const bestS = bestSeats(N, dSVpoints[i].v);
|
|
2202
2214
|
tot += estUnearnedSeats(bestS, estS);
|
|
2203
2215
|
}
|