@mark1russell7/rigor-statistics 0.1.22 → 0.1.23
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 +4 -0
- package/build/index.d.ts +43 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +72 -1
- package/build/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -164,6 +164,7 @@ logLoss([{ p: p.a, hit: true }]); // the probability of the obser
|
|
|
164
164
|
| `bootstrap(data, statistic, options)` | A percentile bootstrap interval of any statistic. The options are `runs`, `level` or `ends`, `seed`, `method` and `against`. |
|
|
165
165
|
| The option `against` | The interval also gives `pAbove` and `pBelow`, the bootstrap p of each side of the value, from the same draws. The smallest p is 1 / (`finite` + 1). Give `holm` enough runs: with m tests at level a, `runs` is more than m / a. |
|
|
166
166
|
| `bootstrapMedian`, `bootstrapClusters` | The interval of the median, and a bootstrap that draws whole clusters (boards, seeds, sites). |
|
|
167
|
+
| `bootstrapStrata(strata, statistic, options)` | A stratified bootstrap. Each run draws inside each stratum, so each sample keeps the size of each stratum. |
|
|
167
168
|
| `bootstrapTwo(a, b, statistic, options)` | A bootstrap interval of a statistic of two independent samples, for example two arms of a benchmark. Each run draws all of `a`, then all of `b`. |
|
|
168
169
|
| `bootstrapMedianRatio(numerator, denominator, options)` | The interval of `median(numerator) / median(denominator)`. It is the uncertainty of the ratio, not the spread of the samples. |
|
|
169
170
|
| `sampleTotalInterval(values, { population, scale })` | The interval of the total of a population from a uniform sample of `m` of its `n` items without replacement. The deviations get the finite population correction `sqrt(1 - m / n)`. `scale` is `n / m` by default. When `m` is `n`, the interval is the estimate. For a small `m`, the interval is too narrow: at `m = 8` of `n = 40`, the coverage is 0.865. For a total over pairs, use `uStatisticInterval`. |
|
|
@@ -173,6 +174,7 @@ logLoss([{ p: p.a, hit: true }]); // the probability of the obser
|
|
|
173
174
|
| `ridgeSolve(gram, moment, lambda, { free })` | The ridge coefficients from the normal equations `X'X` and `X'y`, with a Cholesky factorization. The `free` coefficients have no penalty. A matrix that is not positive definite gives NaN coefficients. |
|
|
174
175
|
| `signTest(better, worse, sides)`, `signTestPower(n, level)` | The sign test, and the fewest wins out of `n` that the test calls significant. |
|
|
175
176
|
| `pairedPermutation(candidate, baseline, options)` | The paired permutation test (random sign flips). It uses the size of each difference. |
|
|
177
|
+
| `signFlipTest(terms, options)` | The sign-flip test of a sum of terms, for example a weighted mean of differences. Up to `exactMax` terms (16), it reads each sign set, so the p is exact. |
|
|
176
178
|
| `twoSamplePermutation(a, b, options)` | The two-sample permutation test (a split of the pooled values). It reads each split when their count is `runs` or less, so the p is exact. It compares groups of different sizes, and its default statistic is the difference of the medians. |
|
|
177
179
|
| `wilson(k, n, z)` | The Wilson interval of a proportion. |
|
|
178
180
|
| `wilsonSampleSize(target, expected, z, max)` | The smallest number of trials at which the Wilson lower end reaches the target, at the expected proportion. |
|
|
@@ -287,6 +289,8 @@ The tests prove that these functions give the same numbers as the copies in the
|
|
|
287
289
|
| `bootstrapMedian` of packing | `bootstrapMedian(sortedValues, { runs, level, seed })`. Give the values sorted, because packing draws from the sorted list. |
|
|
288
290
|
| `bootstrapMedian` of highways | `bootstrap(values, (s) => quantile(s, 0.5), { runs, level, seed })` |
|
|
289
291
|
| `bootstrap` of layout-contract | `bootstrapClusters(rows, (r) => r.cluster, statistic, { runs, seed, ends: [0.025, 0.975] })` |
|
|
292
|
+
| The stratified bootstrap of `verdict` of layout-contract | `bootstrapStrata(families, meanOfMeans, { runs, seed: deriveSeed(seed, "verdict.stratified"), ends })` |
|
|
293
|
+
| The permutation test of `verdict` of layout-contract | `signFlipTest(terms, { exactMax, runs, seed: deriveSeed(seed, "verdict.permutation") })` |
|
|
290
294
|
| `signTestP` of packing | `signTest(better, worse)` |
|
|
291
295
|
| `signTestPower` of highways | `signTestPower(n, level)` |
|
|
292
296
|
| `wilson` of packing | `wilson(k, n, z)`. packing rounds the ends to 4 places at the call. |
|
package/build/index.d.ts
CHANGED
|
@@ -155,6 +155,14 @@ export declare function bootstrapMedian(values: readonly number[], options?: Boo
|
|
|
155
155
|
* are in the order of their first row.
|
|
156
156
|
*/
|
|
157
157
|
export declare function bootstrapClusters<T>(rows: readonly T[], cluster: (row: T) => string, statistic: (rows: readonly T[]) => number, options?: BootstrapOptions): Interval;
|
|
158
|
+
/**
|
|
159
|
+
* A stratified bootstrap: each run draws, inside each stratum, as many items as the stratum has, with replacement.
|
|
160
|
+
* So each sample keeps the size of each stratum. Use it when the strata are fixed by the design, for example the
|
|
161
|
+
* families of the inputs of a benchmark. The draws of one run go through the strata in the order of the list. With one
|
|
162
|
+
* stratum, the draws are equal to the draws of `bootstrap` with the same seed. The estimate is the statistic of all
|
|
163
|
+
* the strata. A run whose statistic is not finite does not count.
|
|
164
|
+
*/
|
|
165
|
+
export declare function bootstrapStrata<T>(strata: readonly (readonly T[])[], statistic: (samples: readonly (readonly T[])[]) => number, options?: BootstrapOptions): Interval;
|
|
158
166
|
interface SampleTotalOptions extends BootstrapOptions {
|
|
159
167
|
/** The number of items in the whole population, `n`. It is a whole number, and it is not less than the sample. */
|
|
160
168
|
readonly population: number;
|
|
@@ -902,6 +910,40 @@ interface PermutationResult {
|
|
|
902
910
|
* the size of each difference, which the sign test does not. A pair with a difference of 0 adds nothing.
|
|
903
911
|
*/
|
|
904
912
|
export declare function pairedPermutation(candidate: readonly number[], baseline: readonly number[], options?: PermutationOptions): PermutationResult;
|
|
913
|
+
/** The default of the option `exactMax` of `signFlipTest`. */
|
|
914
|
+
export declare const SIGN_FLIP_EXACT_MAX = 16;
|
|
915
|
+
/** The largest value of the option `exactMax` of `signFlipTest`: 2^24 sign sets. */
|
|
916
|
+
export declare const SIGN_FLIP_EXACT_LIMIT = 24;
|
|
917
|
+
/** The options of `signFlipTest`. */
|
|
918
|
+
interface SignFlipOptions {
|
|
919
|
+
/** The largest count of terms for which the test reads each of the `2^n` sign sets. The default is 16. The most is 24. */
|
|
920
|
+
readonly exactMax?: number;
|
|
921
|
+
/** The count of random sign sets above `exactMax`. The default is 10 000. */
|
|
922
|
+
readonly runs?: number;
|
|
923
|
+
/** The default is 1. */
|
|
924
|
+
readonly seed?: number | string;
|
|
925
|
+
}
|
|
926
|
+
/** The result of `signFlipTest`. */
|
|
927
|
+
interface SignFlipResult {
|
|
928
|
+
/** The absolute value of the sum of the terms. */
|
|
929
|
+
readonly observed: number;
|
|
930
|
+
/** The two-sided p. */
|
|
931
|
+
readonly p: number;
|
|
932
|
+
/** This field is true when the test read each sign set, so the p has no noise from the draws. */
|
|
933
|
+
readonly exact: boolean;
|
|
934
|
+
/** The count of the sign sets that the test read: `2^n` when it is exact, otherwise the count of the draws. */
|
|
935
|
+
readonly runs: number;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* The sign-flip test of a sum of terms. Under the null, each term has the sign + or - with equal chance. The statistic
|
|
939
|
+
* is the absolute value of the sum. A weighted mean of paired differences is such a sum: give the terms `w[i] * d[i]`.
|
|
940
|
+
*
|
|
941
|
+
* Up to `exactMax` terms, the test reads each sign set. The p is the share of the sets that are as far from 0 or
|
|
942
|
+
* farther. The observed set is one of them. Above `exactMax`, the test draws `runs` sets, and the p is (1 + the extreme
|
|
943
|
+
* draws) / (1 + runs). A sum within `1e-12` of the sum of the absolute terms counts as extreme, so rounding does not
|
|
944
|
+
* hide a tie.
|
|
945
|
+
*/
|
|
946
|
+
export declare function signFlipTest(terms: readonly number[], options?: SignFlipOptions): SignFlipResult;
|
|
905
947
|
/** The options of `twoSamplePermutation`. */
|
|
906
948
|
interface TwoSamplePermutationOptions {
|
|
907
949
|
/** The largest number of splits that the test reads. The default is 10 000. */
|
|
@@ -1554,5 +1596,5 @@ interface BradleyTerryFit {
|
|
|
1554
1596
|
* outcome, a bad weight and a bad option.
|
|
1555
1597
|
*/
|
|
1556
1598
|
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 };
|
|
1599
|
+
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, SignFlipOptions, SignFlipResult, SmoothLaw, SmoothLawScore, SobolIndex, SobolIndices, SobolOptions, Summary, TableResponseModel, TieModel, TwoSamplePermutationOptions, TwoSamplePermutationResult, UStatisticInterval, UStatisticMean, UStatisticMethod, UStatisticOptions };
|
|
1558
1600
|
//# 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/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;
|
|
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;;wBAkBn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}
|
|
390
390
|
/**
|
|
391
|
+
* A stratified bootstrap: each run draws, inside each stratum, as many items as the stratum has, with replacement.
|
|
392
|
+
* So each sample keeps the size of each stratum. Use it when the strata are fixed by the design, for example the
|
|
393
|
+
* families of the inputs of a benchmark. The draws of one run go through the strata in the order of the list. With one
|
|
394
|
+
* stratum, the draws are equal to the draws of `bootstrap` with the same seed. The estimate is the statistic of all
|
|
395
|
+
* the strata. A run whose statistic is not finite does not count.
|
|
396
|
+
*/
|
|
397
|
+
function bootstrapStrata(strata, statistic, options = {}) {
|
|
398
|
+
if (strata.length === 0) throw new RangeError("bootstrapStrata: there is no stratum.");
|
|
399
|
+
for (const [i, stratum] of strata.entries()) if (stratum.length === 0) throw new RangeError(`bootstrapStrata: the stratum ${i} is empty.`);
|
|
400
|
+
const samples = strata.map((stratum) => new Array(stratum.length));
|
|
401
|
+
return percentile("bootstrapStrata", options, (r) => {
|
|
402
|
+
for (const [k, stratum] of strata.entries()) {
|
|
403
|
+
const sample = samples[k];
|
|
404
|
+
const n = stratum.length;
|
|
405
|
+
for (let i = 0; i < n; i++) sample[i] = stratum[r.below(n)];
|
|
406
|
+
}
|
|
407
|
+
return statistic(samples);
|
|
408
|
+
}, () => statistic(strata));
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
391
411
|
* A bootstrap interval of the total of a population from a uniform sample of `m` of its `n` items, drawn without
|
|
392
412
|
* replacement. The estimate is `scale * sum(values)`. Each run draws `m` values with replacement, as `bootstrap`
|
|
393
413
|
* does. The deviation of each run from the sum of the sample gets the factor `scale * sqrt(1 - m / n)`, the finite
|
|
@@ -2537,6 +2557,57 @@ function pairedPermutation(candidate, baseline, options = {}) {
|
|
|
2537
2557
|
runs
|
|
2538
2558
|
};
|
|
2539
2559
|
}
|
|
2560
|
+
/** The default of the option `exactMax` of `signFlipTest`. */
|
|
2561
|
+
const SIGN_FLIP_EXACT_MAX = 16;
|
|
2562
|
+
/** The largest value of the option `exactMax` of `signFlipTest`: 2^24 sign sets. */
|
|
2563
|
+
const SIGN_FLIP_EXACT_LIMIT = 24;
|
|
2564
|
+
/**
|
|
2565
|
+
* The sign-flip test of a sum of terms. Under the null, each term has the sign + or - with equal chance. The statistic
|
|
2566
|
+
* is the absolute value of the sum. A weighted mean of paired differences is such a sum: give the terms `w[i] * d[i]`.
|
|
2567
|
+
*
|
|
2568
|
+
* Up to `exactMax` terms, the test reads each sign set. The p is the share of the sets that are as far from 0 or
|
|
2569
|
+
* farther. The observed set is one of them. Above `exactMax`, the test draws `runs` sets, and the p is (1 + the extreme
|
|
2570
|
+
* draws) / (1 + runs). A sum within `1e-12` of the sum of the absolute terms counts as extreme, so rounding does not
|
|
2571
|
+
* hide a tie.
|
|
2572
|
+
*/
|
|
2573
|
+
function signFlipTest(terms, options = {}) {
|
|
2574
|
+
const exactMax = options.exactMax ?? 16;
|
|
2575
|
+
if (!Number.isInteger(exactMax) || exactMax < 0 || exactMax > 24) throw new RangeError(`signFlipTest: exactMax is a whole number from 0 to 24, not ${exactMax}.`);
|
|
2576
|
+
for (const [i, t] of terms.entries()) if (!Number.isFinite(t)) throw new RangeError(`signFlipTest: the term ${i} is ${t}, not a finite number.`);
|
|
2577
|
+
const n = terms.length;
|
|
2578
|
+
const observed = Math.abs(terms.reduce((sum, t) => sum + t, 0));
|
|
2579
|
+
const slack = 1e-12 * terms.reduce((sum, t) => sum + Math.abs(t), 0);
|
|
2580
|
+
if (n <= exactMax) {
|
|
2581
|
+
const total = 2 ** n;
|
|
2582
|
+
let hits = 0;
|
|
2583
|
+
for (let mask = 0; mask < total; mask++) {
|
|
2584
|
+
let sum = 0;
|
|
2585
|
+
for (let i = 0; i < n; i++) sum += mask & 1 << i ? -terms[i] : terms[i];
|
|
2586
|
+
if (Math.abs(sum) >= observed - slack) hits++;
|
|
2587
|
+
}
|
|
2588
|
+
return {
|
|
2589
|
+
observed,
|
|
2590
|
+
p: hits / total,
|
|
2591
|
+
exact: true,
|
|
2592
|
+
runs: total
|
|
2593
|
+
};
|
|
2594
|
+
}
|
|
2595
|
+
const runs = options.runs ?? 1e4;
|
|
2596
|
+
if (!Number.isSafeInteger(runs) || runs < 1) throw new RangeError(`signFlipTest: runs is a whole number of 1 or more, not ${runs}.`);
|
|
2597
|
+
const r = random(options.seed ?? 1);
|
|
2598
|
+
let hits = 0;
|
|
2599
|
+
for (let run = 0; run < runs; run++) {
|
|
2600
|
+
let sum = 0;
|
|
2601
|
+
for (let i = 0; i < n; i++) sum += r.next() < .5 ? -terms[i] : terms[i];
|
|
2602
|
+
if (Math.abs(sum) >= observed - slack) hits++;
|
|
2603
|
+
}
|
|
2604
|
+
return {
|
|
2605
|
+
observed,
|
|
2606
|
+
p: (1 + hits) / (1 + runs),
|
|
2607
|
+
exact: false,
|
|
2608
|
+
runs
|
|
2609
|
+
};
|
|
2610
|
+
}
|
|
2540
2611
|
/** This function gives the count of the ways to choose `k` of `n`, or Infinity when the count is over `limit`. */
|
|
2541
2612
|
function choices(n, k, limit) {
|
|
2542
2613
|
const small = Math.min(k, n - k);
|
|
@@ -3870,6 +3941,6 @@ function inverseDiagonal(hessian, k) {
|
|
|
3870
3941
|
}
|
|
3871
3942
|
return out;
|
|
3872
3943
|
}
|
|
3873
|
-
export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, U_STATISTIC_TIGHT_MIN_SAMPLE, Z95, bestSmoothLaw, binomialInterval, binomialTest, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapTwo, bradleyTerry, brier, calibration, cohenKappa, compareRatios, coverageMinSample, eloExpected, eloUpdate, fitResponse, glicko2Idle, glicko2Update, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, logLoss, mean, median, medianInterval, modeCount, negativeBinomialInterval, noiseFloor, noiseVerdict, optionFloor, pairProbabilities, pairedPermutation, parseResponseRecord, partialConjunction, predictResponse, quantile, quantileInterval, quantileSamples, quantileSorted, ranks, ratingToStrength, responseCells, ridgeSolve, sampleTotalInterval, sd, signTest, signTestPower, sliceResponse, smoothLawScores, sobolIndices, sorted, spearman, strengthToRating, summarize, surfaceResponse, tQuantile, twoSamplePermutation, uStatisticInterval, whenHolds, wilson, wilsonSampleSize };
|
|
3944
|
+
export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, SIGN_FLIP_EXACT_LIMIT, SIGN_FLIP_EXACT_MAX, U_STATISTIC_TIGHT_MIN_SAMPLE, Z95, bestSmoothLaw, binomialInterval, binomialTest, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapStrata, bootstrapTwo, bradleyTerry, brier, calibration, cohenKappa, compareRatios, coverageMinSample, eloExpected, eloUpdate, fitResponse, glicko2Idle, glicko2Update, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, logLoss, mean, median, medianInterval, modeCount, negativeBinomialInterval, noiseFloor, noiseVerdict, optionFloor, pairProbabilities, pairedPermutation, parseResponseRecord, partialConjunction, predictResponse, quantile, quantileInterval, quantileSamples, quantileSorted, ranks, ratingToStrength, responseCells, ridgeSolve, sampleTotalInterval, sd, signFlipTest, signTest, signTestPower, sliceResponse, smoothLawScores, sobolIndices, sorted, spearman, strengthToRating, summarize, surfaceResponse, tQuantile, twoSamplePermutation, uStatisticInterval, whenHolds, wilson, wilsonSampleSize };
|
|
3874
3945
|
|
|
3875
3946
|
//# sourceMappingURL=index.js.map
|