@mark1russell7/rigor-statistics 0.1.20 → 0.1.22
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/README.md +63 -1
- package/build/index.d.ts +239 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +584 -1
- package/build/index.js.map +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mark1russell7/rigor-statistics
|
|
2
2
|
|
|
3
|
-
The statistics of measured work. It gives quantiles, bootstrap intervals, the sign test, the paired permutation test, Wilson intervals and the Holm correction. It gives the interval of a median from order statistics, and the central interval of a binomial count. It also gives least squares, rank correlation, the comparison with a baseline beyond the noise, and the Brier score of predictions. It fits response records that a browser can evaluate from plain JSON.
|
|
3
|
+
The statistics of measured work. It gives quantiles, bootstrap intervals, the sign test, the paired permutation test, Wilson intervals and the Holm correction. It gives the interval of a median from order statistics, and the central interval of a binomial count. It also gives least squares, rank correlation, the comparison with a baseline beyond the noise, and the Brier score and the log-loss of predictions. It rates items from pairwise results with Elo, Glicko-2 and a Bradley-Terry fit. It fits response records that a browser can evaluate from plain JSON, and it gives the Sobol indices of their models.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
npm install @mark1russell7/rigor-statistics
|
|
@@ -100,6 +100,61 @@ A measure with `null` has no value. To tell why, declare the reasons in the fiel
|
|
|
100
100
|
|
|
101
101
|
The default expansion has one product for each pair of levels of two dimensions. Two dimensions with 76 and 33 levels thus give 2508 products, and the limit `RESPONSE_MAX_TERMS` refuses them. With the option `interactions: "seen"`, a ridge fit keeps only the terms that are not 0 at one point or more. This choice looks only at the inputs of the points. A term with no point has the weight 0, so the choice does not change a prediction. The limit applies after the choice.
|
|
102
102
|
|
|
103
|
+
### The Sobol indices of a model
|
|
104
|
+
|
|
105
|
+
`sobolIndices(record, measure, options)` tells how much of the variance of a fitted model comes from each dimension. The first-order index `first` is the share of one dimension alone. The total index `total` also includes its interactions.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { sobolIndices } from "@mark1russell7/rigor-statistics";
|
|
109
|
+
|
|
110
|
+
const sobol = sobolIndices(record, "ms", { n: 4096, seed: 1 });
|
|
111
|
+
sobol.indices; // [{ dimension: "size", first: 0.71, total: 0.74 }, ...]
|
|
112
|
+
sobol.variance; // the variance of the prediction over the input distribution
|
|
113
|
+
sobol.evaluations; // n * (dimensions + 2) evaluations of the model
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- Each dimension is independent and uniform over its range or its levels. A dimension with `log` is uniform in log space.
|
|
117
|
+
- A conditional dimension gets an independent draw. The model gets `null` for it where `whenHolds` fails.
|
|
118
|
+
- The method is Monte Carlo with the matrices A, B and AB_i of Saltelli (2010). The first-order index uses the estimator of Saltelli (2010), and the total index uses the estimator of Jansen (1999).
|
|
119
|
+
- A constant model has the variance 0. Then each index is 0, not NaN.
|
|
120
|
+
- The option `scale: "model"` gives the indices on the scale of the model, for example the logarithm of a measure with a log scale.
|
|
121
|
+
- The option `interval` adds a percentile bootstrap interval over the N rows to each index.
|
|
122
|
+
|
|
123
|
+
A test examines models with known indices. At N = 16384, the root mean square error of an index is approximately 0.01.
|
|
124
|
+
|
|
125
|
+
## Rate items from pairwise results
|
|
126
|
+
|
|
127
|
+
A pairwise result is a comparison of two items: the first item wins, the second item wins, or a tie. Each function of this section is pure, so a log of results gives the same ratings each time.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { bradleyTerry, eloUpdate, glicko2Update, logLoss, pairProbabilities, strengthToRating } from "@mark1russell7/rigor-statistics";
|
|
131
|
+
|
|
132
|
+
// The fit of a full log: the items are indexes from 0.
|
|
133
|
+
const fit = bradleyTerry(3, [
|
|
134
|
+
{ a: 0, b: 1, outcome: "a" },
|
|
135
|
+
{ a: 1, b: 2, outcome: "tie" },
|
|
136
|
+
{ a: 2, b: 0, outcome: "b", weight: 2 },
|
|
137
|
+
]);
|
|
138
|
+
fit.strengths, fit.se; // the log-strength of each item, with its standard error
|
|
139
|
+
fit.tie; // the Davidson tie parameter
|
|
140
|
+
const p = pairProbabilities(fit.strengths[0], fit.strengths[1], fit.tie); // { a, b, tie }
|
|
141
|
+
strengthToRating(fit.strengths[0]); // 1500 + 400 * log10(e) * strength
|
|
142
|
+
|
|
143
|
+
// One result at a time.
|
|
144
|
+
eloUpdate(1500, 1500, 1, { k: 32 }); // { a: 1516, b: 1484, expected: 0.5 }
|
|
145
|
+
glicko2Update({ rating: 1500, rd: 200, volatility: 0.06 }, [{ rating: 1400, rd: 30, score: 1 }]);
|
|
146
|
+
logLoss([{ p: p.a, hit: true }]); // the probability of the observed outcome
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`bradleyTerry` gives the maximum a posteriori fit with a normal prior on each log-strength. The prior keeps an item with only wins finite. An item with no comparison gets the prior mean and the prior SD. A constant added to each strength changes no probability. Thus only the differences have a meaning, and the prior mean sets the center.
|
|
150
|
+
|
|
151
|
+
- The default tie model is the model of Davidson (1970). The probability of a tie is `nu / (exp(d / 2) + exp(-d / 2) + nu)`, with `d` the difference of the strengths.
|
|
152
|
+
- With the option `ties: "half"`, a tie counts as half a win and half a loss of each item, and `tie` is 0.
|
|
153
|
+
- The fit uses Newton steps with a line search. The negative log posterior is convex, so the steps go to its one minimum.
|
|
154
|
+
- The standard errors come from the inverse of the Hessian at the fit. They include the uncertainty of the tie parameter.
|
|
155
|
+
|
|
156
|
+
`glicko2Update` gives the update of one player after one rating period (Glickman, 2012). A test examines the worked example of the paper: 1500, 200 and 0.06 against three opponents give 1464.06, 151.52 and 0.05999. `glicko2Idle` gives the growth of the RD for a period with no games.
|
|
157
|
+
|
|
103
158
|
## The functions
|
|
104
159
|
|
|
105
160
|
| Function | What it gives |
|
|
@@ -136,10 +191,17 @@ The default expansion has one product for each pair of levels of two dimensions.
|
|
|
136
191
|
| `modeCount(values, { minShare, valleyRatio })` | The count of the modes of a sample, from a kernel density estimate. |
|
|
137
192
|
| `smoothLawScores(values)`, `bestSmoothLaw(values)` | The mean log density of the uniform, normal, exponential, log-normal and Pareto laws at their fits, and the best of them. |
|
|
138
193
|
| `brier`, `calibration` | The Brier score of predictions, and the hit rate of each stated level. |
|
|
194
|
+
| `logLoss(forecasts)` | The mean log-loss of predictions, with the natural log. A p of 0 for a hit gives Infinity. |
|
|
195
|
+
| `eloExpected(ra, rb, { scale, base })`, `eloUpdate(ra, rb, score, { k, scale, base })` | The expected score of the first item, and the ratings of a pair after one result. The defaults are 400, 10 and a `k` of 32. |
|
|
196
|
+
| `glicko2Update(player, games, { tau, tolerance })`, `glicko2Idle(player)` | The Glicko-2 rating, RD and volatility after one rating period, and after a period with no games. The default `tau` is 0.5. |
|
|
197
|
+
| `bradleyTerry(items, comparisons, options)` | The Bradley-Terry fit of pairwise comparisons, with a normal prior and Davidson ties. It gives the strengths, the standard errors, the tie parameter, the log-likelihood, the steps and `converged`. |
|
|
198
|
+
| `pairProbabilities(sa, sb, tie)` | The probabilities of a win of each item and of a tie, from two log-strengths and the tie parameter. |
|
|
199
|
+
| `strengthToRating(strength, { center, scale, base })`, `ratingToStrength(rating, options)` | The rating of a log-strength, `center + scale * strength / ln(base)`, and the inverse. |
|
|
139
200
|
| `fitResponse(data, options)` | A record of the format `response-records/1`, with one model for each measure and held-out folds. |
|
|
140
201
|
| `parseResponseRecord(value)` | The examination of unknown data. It gives the record, or one fault with a path for each error. |
|
|
141
202
|
| `predictResponse(model, inputs)`, `heldOutError(record, measure)` | The value of a model at one set of inputs, and the error of the folds of a measure. |
|
|
142
203
|
| `heldOutErrorAt(record, measure, ids)` | The held-out error of a chosen set of points, from the predictions of the option `outOfFold`. |
|
|
204
|
+
| `sobolIndices(record, measure, options)` | The first-order and the total Sobol index of each dimension, for the model of a measure. The default N is 4096. |
|
|
143
205
|
| `responseCells(record, vary, steps)` | The number of fitted places of a view, level axes included. It lets a caller bound the time of a view before the view starts. |
|
|
144
206
|
| `whenHolds(dimension, values)` | True when a place has the condition of a dimension. A dimension with no `when` is always present. |
|
|
145
207
|
| `sliceResponse(record, measure, options)`, `surfaceResponse(record, measure, options)` | A fitted curve over one dimension, or a fitted surface over two, with the matching measured points, the matching points with no value, a band and the distance to the nearest measurement. |
|
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "@mark1russell7/rigor-generators";
|
|
1
2
|
/**
|
|
2
3
|
* The descriptive statistics: the mean, the standard deviation, the median, the quantiles and a summary of a list.
|
|
3
4
|
* Each function throws a RangeError for an empty list or for a value that is NaN. Thus a missing value cannot make a
|
|
@@ -757,6 +758,86 @@ export declare const RESPONSE_MAX_TERMS = 1024;
|
|
|
757
758
|
* or less on a log scale with no `logFloor`. It throws for more than `RESPONSE_MAX_TERMS` terms.
|
|
758
759
|
*/
|
|
759
760
|
export declare function fitResponse(data: ResponseData, options?: ResponseFitOptions): ResponseRecord;
|
|
761
|
+
/** The options of `sobolIndices`. */
|
|
762
|
+
interface SobolOptions {
|
|
763
|
+
/** The number N of rows of each base matrix. The default is 4096. */
|
|
764
|
+
readonly n?: number;
|
|
765
|
+
/** The seed of the draws. The default is 1. */
|
|
766
|
+
readonly seed?: number | string;
|
|
767
|
+
/**
|
|
768
|
+
* The scale of the output. The value `measure` uses `predictResponse`. The value `model` uses the scale of the
|
|
769
|
+
* model, so a model with a log scale gives the indices of the logarithm. The default is `measure`.
|
|
770
|
+
*/
|
|
771
|
+
readonly scale?: "measure" | "model";
|
|
772
|
+
/**
|
|
773
|
+
* With this option, each index also gets a percentile bootstrap interval over the N rows. Each run draws N rows
|
|
774
|
+
* with replacement, and it calculates all the indices from these rows. The default is no interval.
|
|
775
|
+
*/
|
|
776
|
+
readonly interval?: BootstrapOptions;
|
|
777
|
+
}
|
|
778
|
+
/** The two Sobol indices of one dimension. */
|
|
779
|
+
interface SobolIndex {
|
|
780
|
+
/** The id of the dimension. */
|
|
781
|
+
readonly dimension: string;
|
|
782
|
+
/** The first-order index S_i: the estimator of Saltelli (2010). */
|
|
783
|
+
readonly first: number;
|
|
784
|
+
/** The total index ST_i: the estimator of Jansen (1999). */
|
|
785
|
+
readonly total: number;
|
|
786
|
+
/** The bootstrap interval of `first`. Only the option `interval` writes this field. */
|
|
787
|
+
readonly firstInterval?: Interval;
|
|
788
|
+
/** The bootstrap interval of `total`. Only the option `interval` writes this field. */
|
|
789
|
+
readonly totalInterval?: Interval;
|
|
790
|
+
}
|
|
791
|
+
/** The result of `sobolIndices`. */
|
|
792
|
+
interface SobolIndices {
|
|
793
|
+
/** The id of the measure. */
|
|
794
|
+
readonly measure: string;
|
|
795
|
+
/** The scale of the output. */
|
|
796
|
+
readonly scale: "measure" | "model";
|
|
797
|
+
/** The number N of rows of each base matrix. */
|
|
798
|
+
readonly n: number;
|
|
799
|
+
/** The number of model evaluations: N * (d + 2). */
|
|
800
|
+
readonly evaluations: number;
|
|
801
|
+
/** The seed as a 32-bit number. */
|
|
802
|
+
readonly seed: number;
|
|
803
|
+
/** The mean of the outputs of A and B. */
|
|
804
|
+
readonly mean: number;
|
|
805
|
+
/** The variance of the outputs of A and B, with the divisor 2N. */
|
|
806
|
+
readonly variance: number;
|
|
807
|
+
/** The indices of each dimension of the record, in the order of the record. */
|
|
808
|
+
readonly indices: readonly SobolIndex[];
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* This function gives the first-order and the total Sobol index of each dimension of a record, for the model of
|
|
812
|
+
* `measure`. The indices are of the prediction of the model, not of the measured points.
|
|
813
|
+
*
|
|
814
|
+
* The input distribution:
|
|
815
|
+
* - Each dimension is independent of the other dimensions.
|
|
816
|
+
* - A continuous dimension is uniform over its range. With `log`, the logarithm of the value is uniform.
|
|
817
|
+
* - An ordinal or a categorical dimension is uniform over its levels.
|
|
818
|
+
* - A conditional dimension gets an independent draw. The model gets `null` for it where `whenHolds` fails for the drawn parent.
|
|
819
|
+
*
|
|
820
|
+
* Thus the inputs stay independent, and the indices have their usual meaning. A parent gets the effect of the absence of its child.
|
|
821
|
+
*
|
|
822
|
+
* The estimators:
|
|
823
|
+
* - The first-order index is `mean(f(B) * (f(AB_i) - f(A))) / V` (Saltelli, 2010).
|
|
824
|
+
* - The total index is `mean((f(A) - f(AB_i)) ** 2) / 2 / V` (Jansen, 1999).
|
|
825
|
+
* - V is the variance of the outputs of A and B together.
|
|
826
|
+
* - The variance uses the outputs of A and B less their mean. The first-order sum uses `f(B)` less that mean.
|
|
827
|
+
* - The total sum uses differences of outputs, so it uses no mean.
|
|
828
|
+
* - This step keeps the estimators unbiased, and it decreases their error when the mean is large.
|
|
829
|
+
*
|
|
830
|
+
* A model with a constant output has the variance 0. Then each index is 0, not NaN. An estimate can be a little
|
|
831
|
+
* below 0 or above 1, from the Monte Carlo error. The function does not clip it.
|
|
832
|
+
*
|
|
833
|
+
* The draws fill A row by row, then B row by row. Each row has one draw for each dimension, in the order of the
|
|
834
|
+
* record. Thus the same seed gives the same indices. The model can ignore a dimension. Then that dimension gets 0 for both
|
|
835
|
+
* indices exactly, unless it is the parent of a dimension that the model reads.
|
|
836
|
+
*
|
|
837
|
+
* The function throws a RangeError when the record has no model of `measure`, and when N is not a whole number of 2 or more.
|
|
838
|
+
* `predictResponse` throws for a value that the model refuses, for example a level that the model does not know.
|
|
839
|
+
*/
|
|
840
|
+
export declare function sobolIndices(record: Pick<ResponseRecord, "dimensions" | "models">, measure: string, options?: SobolOptions): SobolIndices;
|
|
760
841
|
/**
|
|
761
842
|
* The sign test of paired results: `better` inputs where the candidate wins and `worse` where it loses. The ties
|
|
762
843
|
* do not count. One-sided (the default), it is the p of `better` wins or more if the two are equal. Two-sided, it is
|
|
@@ -1060,6 +1141,12 @@ interface Forecast {
|
|
|
1060
1141
|
}
|
|
1061
1142
|
/** The Brier score: the mean of (p - outcome)^2. 0 is perfect, and 0.25 is a constant 0.5. Lower is better. */
|
|
1062
1143
|
export declare function brier(forecasts: readonly Forecast[]): number;
|
|
1144
|
+
/**
|
|
1145
|
+
* The log-loss of predictions: the mean of `-ln(p)` for a hit and `-ln(1 - p)` for a miss. 0 is perfect, and
|
|
1146
|
+
* `ln(2)` is a constant 0.5. Lower is better. A p of 0 for a hit gives Infinity. For an outcome of three values,
|
|
1147
|
+
* give the probability of the observed outcome as `p`, with `hit` true.
|
|
1148
|
+
*/
|
|
1149
|
+
export declare function logLoss(forecasts: readonly Forecast[]): number;
|
|
1063
1150
|
/** The predictions of one stated level. */
|
|
1064
1151
|
interface CalibrationLevel {
|
|
1065
1152
|
readonly stated: number;
|
|
@@ -1316,5 +1403,156 @@ interface UStatisticInterval {
|
|
|
1316
1403
|
* @returns The estimate and the interval of the total, and of the mean of the kernel.
|
|
1317
1404
|
*/
|
|
1318
1405
|
export declare function uStatisticInterval(totals: readonly number[], options: UStatisticOptions): UStatisticInterval;
|
|
1319
|
-
|
|
1406
|
+
/**
|
|
1407
|
+
* The ratings of pairwise results. This module gives the Elo update and the Glicko-2 update of one rating period. It
|
|
1408
|
+
* also gives the probabilities of a pair under the Bradley-Terry model with Davidson ties, and the conversion between
|
|
1409
|
+
* a log-strength and a rating. Each function is pure. It changes no input, and the same inputs give the same result.
|
|
1410
|
+
*/
|
|
1411
|
+
/** The scale of a rating. A difference of `scale` points gives odds of `base` to 1. */
|
|
1412
|
+
interface RatingScale {
|
|
1413
|
+
/** The rating of the log-strength 0. The default is 1500. Elo uses only differences, so it does not read it. */
|
|
1414
|
+
readonly center?: number;
|
|
1415
|
+
/** The number of points that gives odds of `base` to 1. The default is 400. */
|
|
1416
|
+
readonly scale?: number;
|
|
1417
|
+
/** The base of the odds. The default is 10. */
|
|
1418
|
+
readonly base?: number;
|
|
1419
|
+
}
|
|
1420
|
+
/** The options of an Elo update. */
|
|
1421
|
+
interface EloOptions extends RatingScale {
|
|
1422
|
+
/** The largest change of a rating after one result (the K factor). The default is 32. */
|
|
1423
|
+
readonly k?: number;
|
|
1424
|
+
}
|
|
1425
|
+
/** The ratings of a pair after one result. */
|
|
1426
|
+
interface EloUpdate {
|
|
1427
|
+
/** The new rating of the first item. */
|
|
1428
|
+
readonly a: number;
|
|
1429
|
+
/** The new rating of the second item. */
|
|
1430
|
+
readonly b: number;
|
|
1431
|
+
/** The expected score of the first item before the result. */
|
|
1432
|
+
readonly expected: number;
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* The expected score of the first item against the second item: `1 / (1 + base ** ((rb - ra) / scale))`. A win
|
|
1436
|
+
* counts 1, a tie 0.5 and a loss 0. The expected score of the second item is 1 minus this value.
|
|
1437
|
+
*/
|
|
1438
|
+
export declare function eloExpected(ra: number, rb: number, options?: RatingScale): number;
|
|
1439
|
+
/**
|
|
1440
|
+
* The Elo update of a pair after one result. The `score` is the score of the first item: 1 for a win, 0.5 for a tie
|
|
1441
|
+
* and 0 for a loss. Each rating moves by `k` times the difference between the score and the expected score. Thus
|
|
1442
|
+
* the sum of the two ratings does not change.
|
|
1443
|
+
*/
|
|
1444
|
+
export declare function eloUpdate(ra: number, rb: number, score: number, options?: EloOptions): EloUpdate;
|
|
1445
|
+
/** A Glicko-2 rating on the Glicko scale: the rating, the rating deviation (RD) and the volatility. */
|
|
1446
|
+
interface Glicko2Rating {
|
|
1447
|
+
readonly rating: number;
|
|
1448
|
+
/** The rating deviation, in rating points. It is above 0. */
|
|
1449
|
+
readonly rd: number;
|
|
1450
|
+
/** The volatility: the expected size of a change of the true strength in one rating period. It is above 0. */
|
|
1451
|
+
readonly volatility: number;
|
|
1452
|
+
}
|
|
1453
|
+
/** One game of a rating period: the rating and the RD of the opponent, and the score of the player. */
|
|
1454
|
+
interface Glicko2Game {
|
|
1455
|
+
readonly rating: number;
|
|
1456
|
+
readonly rd: number;
|
|
1457
|
+
/** The score of the player: 1 for a win, 0.5 for a tie and 0 for a loss. */
|
|
1458
|
+
readonly score: number;
|
|
1459
|
+
}
|
|
1460
|
+
/** The options of a Glicko-2 update. */
|
|
1461
|
+
interface Glicko2Options {
|
|
1462
|
+
/** The constraint on the change of the volatility over time (tau). The default is 0.5. Glickman uses 0.3 to 1.2. */
|
|
1463
|
+
readonly tau?: number;
|
|
1464
|
+
/** The tolerance of the iteration for the new volatility (epsilon). The default is 0.000001, as in the paper. */
|
|
1465
|
+
readonly tolerance?: number;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* The Glicko-2 update of one player after one rating period (Glickman, "Example of the Glicko-2 system", 2012). The
|
|
1469
|
+
* function uses the Illinois algorithm for the new volatility. The games use the ratings of the opponents from the
|
|
1470
|
+
* start of the period. An empty list of games gives `glicko2Idle(player)`.
|
|
1471
|
+
*/
|
|
1472
|
+
export declare function glicko2Update(player: Glicko2Rating, games: readonly Glicko2Game[], options?: Glicko2Options): Glicko2Rating;
|
|
1473
|
+
/**
|
|
1474
|
+
* The Glicko-2 rating of a player after a rating period with no games. The rating and the volatility stay the same.
|
|
1475
|
+
* The RD grows to `sqrt(RD^2 + (173.7178 * volatility)^2)`.
|
|
1476
|
+
*/
|
|
1477
|
+
export declare function glicko2Idle(player: Glicko2Rating): Glicko2Rating;
|
|
1478
|
+
/** The probabilities of the three outcomes of a pair. Their sum is 1. */
|
|
1479
|
+
interface PairProbabilities {
|
|
1480
|
+
/** The probability that the first item wins. */
|
|
1481
|
+
readonly a: number;
|
|
1482
|
+
/** The probability that the second item wins. */
|
|
1483
|
+
readonly b: number;
|
|
1484
|
+
/** The probability of a tie. It is 0 when the tie parameter is 0. */
|
|
1485
|
+
readonly tie: number;
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* The probabilities of a pair under the Bradley-Terry model with Davidson (1970) ties. The inputs are the
|
|
1489
|
+
* log-strengths of the two items and the tie parameter `tie` of `bradleyTerry`. With `tie` 0, the probability that
|
|
1490
|
+
* the first item wins is `1 / (1 + exp(sb - sa))`. A constant added to the two strengths changes no probability.
|
|
1491
|
+
*/
|
|
1492
|
+
export declare function pairProbabilities(sa: number, sb: number, tie?: number): PairProbabilities;
|
|
1493
|
+
/**
|
|
1494
|
+
* The rating of a log-strength: `center + scale * strength / ln(base)`. The defaults give
|
|
1495
|
+
* `1500 + 400 * log10(e) * strength`. Thus `eloExpected` of two ratings is the Bradley-Terry win probability.
|
|
1496
|
+
*/
|
|
1497
|
+
export declare function strengthToRating(strength: number, options?: RatingScale): number;
|
|
1498
|
+
/** The log-strength of a rating. It is the inverse of `strengthToRating` with the same options. */
|
|
1499
|
+
export declare function ratingToStrength(rating: number, options?: RatingScale): number;
|
|
1500
|
+
/** The result of a comparison: the first item wins, the second item wins, or a tie. */
|
|
1501
|
+
type PairOutcome = "a" | "b" | "tie";
|
|
1502
|
+
/** One comparison of two items, by their indexes from 0. */
|
|
1503
|
+
interface PairComparison {
|
|
1504
|
+
readonly a: number;
|
|
1505
|
+
readonly b: number;
|
|
1506
|
+
readonly outcome: PairOutcome;
|
|
1507
|
+
/** The weight of the comparison. The default is 1. A weight of 2 counts as two equal comparisons. */
|
|
1508
|
+
readonly weight?: number;
|
|
1509
|
+
}
|
|
1510
|
+
/** The model of a tie. */
|
|
1511
|
+
type TieModel = "davidson" | "half";
|
|
1512
|
+
/** The options of `bradleyTerry`. */
|
|
1513
|
+
interface BradleyTerryOptions {
|
|
1514
|
+
/** The mean of the prior of each log-strength. The default is 0. */
|
|
1515
|
+
readonly priorMean?: number;
|
|
1516
|
+
/** The standard deviation of the prior of each log-strength. The default is 1. A smaller value pulls the strengths together. */
|
|
1517
|
+
readonly priorSd?: number;
|
|
1518
|
+
/**
|
|
1519
|
+
* The model of a tie. With `"davidson"` (the default), the fit also gives a tie parameter. With `"half"`, a tie
|
|
1520
|
+
* counts as half a win and half a loss of each item, and the tie parameter is 0.
|
|
1521
|
+
*/
|
|
1522
|
+
readonly ties?: TieModel;
|
|
1523
|
+
/**
|
|
1524
|
+
* The standard deviation of the normal prior of the log of the tie parameter, with mean 0. The default is 10. The
|
|
1525
|
+
* prior is weak. It keeps the parameter finite when each comparison is a tie.
|
|
1526
|
+
*/
|
|
1527
|
+
readonly tiePriorSd?: number;
|
|
1528
|
+
/** The largest number of Newton steps. The default is 100. */
|
|
1529
|
+
readonly maxIterations?: number;
|
|
1530
|
+
/** The fit stops when the full Newton step moves no parameter more than this value. The default is 1e-10. */
|
|
1531
|
+
readonly tolerance?: number;
|
|
1532
|
+
}
|
|
1533
|
+
/** The result of `bradleyTerry`. The lists have one value for each item, in the order of the indexes. */
|
|
1534
|
+
interface BradleyTerryFit {
|
|
1535
|
+
/** The log-strength of each item. An item with no comparison has the prior mean. */
|
|
1536
|
+
readonly strengths: number[];
|
|
1537
|
+
/**
|
|
1538
|
+
* The standard error of each log-strength: the square root of the diagonal of the inverse of the Hessian of the
|
|
1539
|
+
* negative log posterior. An item with no comparison has the prior SD.
|
|
1540
|
+
*/
|
|
1541
|
+
readonly se: number[];
|
|
1542
|
+
/** The Davidson tie parameter. It is 0 with the model `"half"`, and when no comparison is a tie. */
|
|
1543
|
+
readonly tie: number;
|
|
1544
|
+
/** The log-likelihood of the comparisons at the fit, with no prior term. */
|
|
1545
|
+
readonly logLikelihood: number;
|
|
1546
|
+
/** The number of Newton steps. */
|
|
1547
|
+
readonly iterations: number;
|
|
1548
|
+
/** True when the last full Newton step moved no parameter more than the tolerance. */
|
|
1549
|
+
readonly converged: boolean;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* The Bradley-Terry fit of `comparisons` among `items` items. The function does not sort or change its inputs. An
|
|
1553
|
+
* empty list of comparisons gives the prior for each item. The function throws a RangeError for a bad index, a bad
|
|
1554
|
+
* outcome, a bad weight and a bad option.
|
|
1555
|
+
*/
|
|
1556
|
+
export declare function bradleyTerry(items: number, comparisons: readonly PairComparison[], options?: BradleyTerryOptions): BradleyTerryFit;
|
|
1557
|
+
export type { BinomialSide, BootstrapOptions, BradleyTerryFit, BradleyTerryOptions, CalibrationLevel, CategoricalDimension, CompareOptions, Comparison, ContinuousDimension, Corrected, CountInterval, CoverageBar, CoverageCell, CoverageMinSample, CoverageReason, CoverageStep, Effect, EloOptions, EloUpdate, Forecast, Glicko2Game, Glicko2Options, Glicko2Rating, Interval, Kappa, LeastSquaresFit, LeastSquaresOptions, MedianInterval, ModeOptions, NoiseOptions, NoiseState, NoiseVerdict, OptionFloorOptions, OrdinalDimension, PairComparison, PairOutcome, PairProbabilities, ParsedResponseRecord, PermutationOptions, PermutationResult, Proportion, QuantileInterval, QuantileMethod, RatingScale, ResponseAbsentPoint, ResponseBand, ResponseCurvePoint, ResponseData, ResponseDimension, ResponseDimensionBase, ResponseFactor, ResponseFault, ResponseFitOptions, ResponseFold, ResponseFoldError, ResponseHeldOutError, ResponseInputValue, ResponseMeasure, ResponseModel, ResponseModelBase, ResponsePoint, ResponseReason, ResponseRecord, ResponseSlice, ResponseSliceOptions, ResponseSlicePoint, ResponseSurface, ResponseSurfaceAbsentPoint, ResponseSurfaceOptions, ResponseSurfacePoint, ResponseTableCell, ResponseValue, ResponseViewOptions, ResponseWhen, RidgeInput, RidgeInputBase, RidgeLevelInput, RidgeNumberInput, RidgeOptions, RidgeRankInput, RidgeResponseModel, RidgeTerm, SampleTotalOptions, SideP, SmoothLaw, SmoothLawScore, SobolIndex, SobolIndices, SobolOptions, Summary, TableResponseModel, TieModel, TwoSamplePermutationOptions, TwoSamplePermutationResult, UStatisticInterval, UStatisticMean, UStatisticMethod, UStatisticOptions };
|
|
1320
1558
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/describe.ts","../src/regression.ts","../src/bootstrap.ts","../src/distribution.ts","../src/ridge.ts","../src/response.ts","../src/response-parse.ts","../src/response-fit.ts","../src/tests.ts","../src/agreement.ts","../src/rank.ts","../src/discrete.ts","../src/compare.ts","../src/power.ts","../src/coverage.ts","../src/u-statistic.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/describe.ts","../src/regression.ts","../src/bootstrap.ts","../src/distribution.ts","../src/ridge.ts","../src/response.ts","../src/response-parse.ts","../src/response-fit.ts","../src/response-sobol.ts","../src/tests.ts","../src/agreement.ts","../src/rank.ts","../src/discrete.ts","../src/compare.ts","../src/power.ts","../src/coverage.ts","../src/u-statistic.ts","../src/rating.ts","../src/bradley-terry.ts"],"mappings":";;;;;;;KAOY;;wBAmBI,OAAO;wBAIP,KAAK;;;;;wBAgBL,GAAG;;;;;;;wBAgBH,eAAe,iCAAiC,WAAW,SAAQ;;wBAkBnE,SAAS,2BAA2B,WAAW,SAAQ;;;;;wBASvD,OAAO;;UAQN;WACN;WACA;;WAEA;WACA;;WAEA;WACA;;WAEA;WACA;;WAEA;;wBAGK,UAAU,4BAA4B;;;;;;UC3GrC;;WAEN;;UAGM;;WAEN;;WAEA;;;;;WAKA;;WAEA;;WAEA;;;;;;;;;;;wBAkBK,aAAa,mCAAmC,sBAAsB,UAAS,sBAA2B;UC7BzG;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;;;;WAMT;;;;;WAKA;;;UAIM;;WAEN;;WAEA;;WAEA;;UAGM,iBAAiB,QAAQ;;WAE/B;WACA;WACA;WACA;WACA;;WAEA;;WAEA;;;;;;wBAOK,UAAU,GAAG,eAAe,KAAK,YAAY,iBAAiB,gBAAgB,UAAS,mBAAwB;;;;;;;;wBAsB/G,aAAa,GAAG,GAC9B,YAAY,KACZ,YAAY,KACZ,YAAY,YAAY,KAAK,YAAY,gBACzC,UAAS,mBACR;;;;;;wBAwBa,qBAAqB,8BAA8B,gCAAgC,UAAS,mBAAwB;;;;;;;wBAUpH,sBACd,mCACA,sBACA,UAAS,mBAAmB,sBAC3B;;wBAoGa,gBAAgB,2BAA2B,UAAS,mBAAwB;;;;;;wBAS5E,kBAAkB,GAChC,eAAe,KACf,UAAU,KAAK,cACf,YAAY,eAAe,gBAC3B,UAAS,mBACR;UAec,2BAA2B;;WAEjC;;WAEA;;;;;;;;;;;;;;;;wBAiBK,oBAAoB,2BAA2B,SAAS,qBAAqB;;KC9QjF;;UAGK;WACN,KAAK;;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