@dra2020/dra-analytics 3.1.4 ā 3.2.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/cli/partisan.ts +5 -3
- package/dist/dra-analytics.js +24 -15
- package/dist/dra-analytics.js.map +1 -1
- package/dist/lib/partisan/bias.d.ts +2 -0
- package/dist/lib/types/partisan.d.ts +1 -0
- package/lib/partisan/all.ts +4 -2
- package/lib/partisan/bias.ts +28 -13
- package/lib/types/partisan.ts +2 -1
- package/package.json +2 -2
package/cli/partisan.ts
CHANGED
|
@@ -123,13 +123,13 @@ 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>), Rd, R, r, MIR, Cd, Cdf, BS_50, BV_50, Decl, GS, š¾, β, LO, EG, PR, MM, TO, MM\', B%, LS, LPR, LPR\'');
|
|
126
|
+
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
127
|
// 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
128
|
}
|
|
129
129
|
|
|
130
130
|
export function printPartisanDetailsRow(xx: string, name: string, N: number, Vf: number, s: T.PartisanScorecard): void
|
|
131
131
|
{
|
|
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',
|
|
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
133
|
xx,
|
|
134
134
|
|
|
135
135
|
trim(Vf),
|
|
@@ -159,10 +159,12 @@ export function printPartisanDetailsRow(xx: string, name: string, N: number, Vf:
|
|
|
159
159
|
trim(s.bias.mMd), // Not shown in Table 1
|
|
160
160
|
|
|
161
161
|
trim(s.bias.deviation), // Simple deviation from best # of seats
|
|
162
|
+
trim(s.impact.unearnedS),
|
|
162
163
|
|
|
163
164
|
// EXPERIMENTAL
|
|
164
165
|
(s.experimental.lSym) ? trim(s.experimental.lSym) : s.experimental.lSym,
|
|
165
166
|
(s.experimental.lProp) ? trim(s.experimental.lProp) : s.experimental.lProp,
|
|
166
|
-
(s.experimental.lPropAlt) ? trim(s.experimental.lPropAlt) : s.experimental.lPropAlt
|
|
167
|
+
(s.experimental.lPropAlt) ? trim(s.experimental.lPropAlt) : s.experimental.lPropAlt,
|
|
168
|
+
(s.experimental.lUE) ? trim(s.experimental.lUE) : s.experimental.lUE
|
|
167
169
|
);
|
|
168
170
|
}
|
package/dist/dra-analytics.js
CHANGED
|
@@ -1636,6 +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, dSVpoints);
|
|
1639
1640
|
const biasMeasurements = {
|
|
1640
1641
|
bestS: bestS,
|
|
1641
1642
|
bestSf: bestSf,
|
|
@@ -1677,7 +1678,8 @@ function makePartisanScorecard(Vf, VfArray, bLog = false) {
|
|
|
1677
1678
|
const experimentalMetrics = {
|
|
1678
1679
|
lSym: lSym,
|
|
1679
1680
|
lProp: lProp,
|
|
1680
|
-
lPropAlt: lPropAlt
|
|
1681
|
+
lPropAlt: lPropAlt,
|
|
1682
|
+
lUE: lUE
|
|
1681
1683
|
};
|
|
1682
1684
|
const s = {
|
|
1683
1685
|
bias: biasMeasurements,
|
|
@@ -1735,7 +1737,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
1735
1737
|
return result;
|
|
1736
1738
|
};
|
|
1737
1739
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1738
|
-
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.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;
|
|
1739
1741
|
const U = __importStar(__webpack_require__(/*! ../utils/all */ "./lib/utils/all.ts"));
|
|
1740
1742
|
const C = __importStar(__webpack_require__(/*! ../rate/dra-config */ "./lib/rate/dra-config.ts"));
|
|
1741
1743
|
const method_1 = __webpack_require__(/*! ./method */ "./lib/partisan/method.ts");
|
|
@@ -2174,27 +2176,34 @@ exports.estLocalDisproportionalityAlt = estLocalDisproportionalityAlt;
|
|
|
2174
2176
|
function rangeDisproportionalityAlt(N, dSVpoints) {
|
|
2175
2177
|
const ndPts = dSVpoints.length;
|
|
2176
2178
|
let tot = 0.0;
|
|
2177
|
-
let lastBestS;
|
|
2178
2179
|
for (let i in dSVpoints) {
|
|
2179
2180
|
const bestS = bestSeats(N, dSVpoints[i].v);
|
|
2180
2181
|
const bestSf = bestSeatShare(bestS, N);
|
|
2181
2182
|
tot += calcDisproportionalityFromBest(dSVpoints[i].s, bestSf);
|
|
2182
|
-
/* DEBUG
|
|
2183
|
-
{
|
|
2184
|
-
if (lastBestS && (bestS != lastBestS)) console.log("Best # seats changes to ", bestS, bestSf, " at ", dSVpoints[i].v, " vote share. ");
|
|
2185
|
-
|
|
2186
|
-
const j: number = +i;
|
|
2187
|
-
if (j == 0)
|
|
2188
|
-
{
|
|
2189
|
-
console.log("Best # seats starts @ ", bestS, bestSf, " at ", dSVpoints[i].v, " vote share. ");
|
|
2190
|
-
}
|
|
2191
|
-
else lastBestS = bestS;
|
|
2192
|
-
}
|
|
2193
|
-
*/
|
|
2194
2183
|
}
|
|
2195
2184
|
return tot / ndPts;
|
|
2196
2185
|
}
|
|
2197
2186
|
exports.rangeDisproportionalityAlt = rangeDisproportionalityAlt;
|
|
2187
|
+
// Average local unearned seats from the best # of seats (closest to proportional)
|
|
2188
|
+
function estLocalUnearnedSeats(Vf, N, dSVpoints) {
|
|
2189
|
+
const dPts = svPointRange(Vf, dSVpoints);
|
|
2190
|
+
if (!dPts)
|
|
2191
|
+
return undefined;
|
|
2192
|
+
const lUE = rangeUnearnedSeats(N, dPts);
|
|
2193
|
+
return lUE;
|
|
2194
|
+
}
|
|
2195
|
+
exports.estLocalUnearnedSeats = estLocalUnearnedSeats;
|
|
2196
|
+
function rangeUnearnedSeats(N, dSVpoints) {
|
|
2197
|
+
const ndPts = dSVpoints.length;
|
|
2198
|
+
let tot = 0.0;
|
|
2199
|
+
for (let i in dSVpoints) {
|
|
2200
|
+
const estS = dSVpoints[i].s * N;
|
|
2201
|
+
const bestS = bestSeats(N, dSVpoints[i].v);
|
|
2202
|
+
tot += estUnearnedSeats(bestS, estS);
|
|
2203
|
+
}
|
|
2204
|
+
return tot / ndPts;
|
|
2205
|
+
}
|
|
2206
|
+
exports.rangeUnearnedSeats = rangeUnearnedSeats;
|
|
2198
2207
|
// Filter the full [0.25ā0.75] range of SāV points down to the 'local' range.
|
|
2199
2208
|
// Make sure that range is w/in the full range.
|
|
2200
2209
|
function svPointRange(Vf, svPoints) {
|