@mark1russell7/rigor-statistics 0.1.22 → 0.1.24

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 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. |
@@ -188,6 +190,7 @@ logLoss([{ p: p.a, hit: true }]); // the probability of the obser
188
190
  | `spearman`, `kendallTau`, `ranks` | The rank correlations, with mean ranks for ties. |
189
191
  | `compareRatios`, `noiseFloor`, `noiseVerdict` | The comparison with a baseline, the noise floor of the 5-seed rule with a margin of practical effect, and the state of a difference over the seeds. |
190
192
  | `optionFloor({ sigma, delta, tests, alpha, power })`, `tQuantile(p, df)` | The fewest values for each of two options, so that one test of a Bonferroni family finds a difference of `delta` with the stated power, from the Student t law. It assumes unpaired groups of equal size and equal `sigma`. The quantile of the Student t law. |
193
+ | `normalCdf(x)`, `normalQuantile(p)` | The distribution function of the standard normal law and its quantile (AS 241 of Wichura). Both keep their relative digits in the lower tail, to `p = 1e-300`. |
191
194
  | `modeCount(values, { minShare, valleyRatio })` | The count of the modes of a sample, from a kernel density estimate. |
192
195
  | `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. |
193
196
  | `brier`, `calibration` | The Brier score of predictions, and the hit rate of each stated level. |
@@ -287,6 +290,9 @@ The tests prove that these functions give the same numbers as the copies in the
287
290
  | `bootstrapMedian` of packing | `bootstrapMedian(sortedValues, { runs, level, seed })`. Give the values sorted, because packing draws from the sorted list. |
288
291
  | `bootstrapMedian` of highways | `bootstrap(values, (s) => quantile(s, 0.5), { runs, level, seed })` |
289
292
  | `bootstrap` of layout-contract | `bootstrapClusters(rows, (r) => r.cluster, statistic, { runs, seed, ends: [0.025, 0.975] })` |
293
+ | The stratified bootstrap of `verdict` of layout-contract | `bootstrapStrata(families, meanOfMeans, { runs, seed: deriveSeed(seed, "verdict.stratified"), ends })` |
294
+ | The permutation test of `verdict` of layout-contract | `signFlipTest(terms, { exactMax, runs, seed: deriveSeed(seed, "verdict.permutation") })` |
295
+ | `normalQuantile` of lag (Acklam, relative error below 1.2e-9) | `normalQuantile(p)`. The values change by 1.2e-9 or less, because the new function is more exact. A `p` out of 0 to 1 throws. |
290
296
  | `signTestP` of packing | `signTest(better, worse)` |
291
297
  | `signTestPower` of highways | `signTestPower(n, level)` |
292
298
  | `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. */
@@ -1194,6 +1236,20 @@ interface OptionFloorOptions {
1194
1236
  * @returns A whole number of 2 or more.
1195
1237
  */
1196
1238
  export declare function optionFloor(options: OptionFloorOptions): number;
1239
+ /**
1240
+ * This function gives the distribution function of the standard normal law, `P(Z <= x)`. Its relative error is below
1241
+ * 1e-14, also in the lower tail: `normalCdf(-37)` is approximately 5.7e-300, not 0.
1242
+ *
1243
+ * @param x - A number. `-Infinity` gives 0 and `Infinity` gives 1.
1244
+ */
1245
+ export declare function normalCdf(x: number): number;
1246
+ /**
1247
+ * This function gives the quantile of the standard normal law, the `x` with `normalCdf(x) = p`. It uses PPND16 of
1248
+ * Wichura (algorithm AS 241). Its relative error is near 1e-16 for each `p` from 1e-300 to 1 - 1e-16.
1249
+ *
1250
+ * @param p - The share of the law below the result, from 0 to 1. A `p` of 0 gives `-Infinity` and 1 gives `Infinity`.
1251
+ */
1252
+ export declare function normalQuantile(p: number): number;
1197
1253
  /** One cell of a coverage study: the hits of a method on the true value in `draws` seeded samples of size `sample`. */
1198
1254
  interface CoverageCell {
1199
1255
  /** The name of the cell, for example `"skewed 120/108"`. The result names the rejected cells with it. */
@@ -1554,5 +1610,5 @@ interface BradleyTerryFit {
1554
1610
  * outcome, a bad weight and a bad option.
1555
1611
  */
1556
1612
  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 };
1613
+ 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
1614
  //# sourceMappingURL=index.d.ts.map
@@ -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;;;;;;;;wB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;;wBAuEnG,YAAY,QAAQ,gBAAgB;;UAQnC;;WAEN;;WAEA;;WAEA;;;;;;;wBAuBK,kBAAkB,YAAY,YAAY,eAAU;;;;;wBAWpD,iBAAiB,kBAAkB,UAAS;;wBAO5C,iBAAiB,gBAAgB,UAAS;;KCtO9C;;UAGK;WACN;WACA;WACA,SAAS;;WAET;;;KAIC;;UAGK;;WAEN;;WAEA;;;;;WAKA,OAAO;;;;;WAKP;;WAEA;;WAEA;;;UAIM;;WAEN;;;;;WAKA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;wBA6CK,aAAa,eAAe,sBAAsB,kBAAkB,UAAS,sBAA2B"}
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/normal.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;;;;;;wB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AAS,oBAAoB;;;;;;;UCrI1E;;WAEN;;WAEA;;WAEA;;;UAIM,mBAAmB;;WAEzB;;;UAIM;;WAEN;;WAEA;;WAEA;;;;;;wBAyBK,YAAY,YAAY,YAAY,UAAS;;;;;;wBAY7C,UAAU,YAAY,YAAY,eAAe,UAAS,aAAkB;;UAU3E;WACN;;WAEA;;WAEA;;;UAIM;WACN;WACA;;WAEA;;;UAIM;;WAEN;;WAEA;;;;;;;wBAmBK,cAAc,QAAQ,eAAe,gBAAgB,eAAe,UAAS,iBAAsB;;;;;wBAuEnG,YAAY,QAAQ,gBAAgB;;UAQnC;;WAEN;;WAEA;;WAEA;;;;;;;wBAuBK,kBAAkB,YAAY,YAAY,eAAU;;;;;wBAWpD,iBAAiB,kBAAkB,UAAS;;wBAO5C,iBAAiB,gBAAgB,UAAS;;KCtO9C;;UAGK;WACN;WACA;WACA,SAAS;;WAET;;;KAIC;;UAGK;;WAEN;;WAEA;;;;;WAKA,OAAO;;;;;WAKP;;WAEA;;WAEA;;;UAIM;;WAEN;;;;;WAKA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;wBA6CK,aAAa,eAAe,sBAAsB,kBAAkB,UAAS,sBAA2B"}
package/build/index.js CHANGED
@@ -388,6 +388,26 @@ function bootstrapClusters(rows, cluster, statistic, options = {}) {
388
388
  };
389
389
  }
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);
@@ -3180,6 +3251,162 @@ function optionFloor(options) {
3180
3251
  }
3181
3252
  throw new RangeError(`optionFloor: no count under 10,000,000 for sigma ${sigma} and delta ${delta}.`);
3182
3253
  }
3254
+ // src/normal.ts
3255
+ /**
3256
+ * The standard normal law: its distribution function `normalCdf` and its quantile `normalQuantile`. The two functions
3257
+ * keep their relative digits in the far tails, so a small tail probability does not become 0.
3258
+ */
3259
+ const SQRT_PI = Math.sqrt(Math.PI);
3260
+ /** The series of `erf(z)` with positive terms, `2/√π · e^(-z²) · Σ (2z²)^n · z / (1·3·…·(2n+1))`, for a small `z` of 0 or more. */
3261
+ function erfSeries(z) {
3262
+ const twoZ2 = 2 * z * z;
3263
+ let term = z;
3264
+ let sum = z;
3265
+ for (let n = 1; n < 500 && term > sum * 1e-17; n++) {
3266
+ term *= twoZ2 / (2 * n + 1);
3267
+ sum += term;
3268
+ }
3269
+ return 2 / SQRT_PI * expMinusSquare(z) * sum;
3270
+ }
3271
+ /**
3272
+ * The continued fraction of `erfc(z)`, `e^(-z²)/√π · 1/(z + (1/2)/(z + 1/(z + (3/2)/(z + …))))`, by the method of
3273
+ * Lentz, for a `z` of 1.5 or more.
3274
+ */
3275
+ function erfcFraction(z) {
3276
+ const tiny = 1e-300;
3277
+ let f = z;
3278
+ let c = z;
3279
+ let d = 0;
3280
+ for (let n = 1; n < 5e3; n++) {
3281
+ const a = n / 2;
3282
+ d = z + a * d;
3283
+ d = 1 / (Math.abs(d) < tiny ? tiny : d);
3284
+ c = z + a / c;
3285
+ if (Math.abs(c) < tiny) c = tiny;
3286
+ const delta = c * d;
3287
+ f *= delta;
3288
+ if (Math.abs(delta - 1) < 1e-16) break;
3289
+ }
3290
+ return expMinusSquare(z) / (SQRT_PI * f);
3291
+ }
3292
+ /**
3293
+ * The value of `e^(-z²)` with its relative digits for a large `z`. The rounding of `z²` costs `z²` ulps, so the
3294
+ * function splits `z` into `hi + lo`. `hi` has 4 bits after the point, so `hi²` is exact.
3295
+ */
3296
+ function expMinusSquare(z) {
3297
+ const hi = Math.round(z * 16) / 16;
3298
+ const lo = z - hi;
3299
+ return Math.exp(-hi * hi) * Math.exp(-lo * (z + hi));
3300
+ }
3301
+ /** The complementary error function `erfc(z) = 1 - erf(z)`, with its relative digits for a large `z`. */
3302
+ function erfc(z) {
3303
+ if (z < 0) return 2 - erfc(-z);
3304
+ return z < 1.5 ? 1 - erfSeries(z) : erfcFraction(z);
3305
+ }
3306
+ /**
3307
+ * This function gives the distribution function of the standard normal law, `P(Z <= x)`. Its relative error is below
3308
+ * 1e-14, also in the lower tail: `normalCdf(-37)` is approximately 5.7e-300, not 0.
3309
+ *
3310
+ * @param x - A number. `-Infinity` gives 0 and `Infinity` gives 1.
3311
+ */
3312
+ function normalCdf(x) {
3313
+ if (Number.isNaN(x)) throw new RangeError("normalCdf: x is NaN.");
3314
+ if (x === Number.NEGATIVE_INFINITY) return 0;
3315
+ if (x === Number.POSITIVE_INFINITY) return 1;
3316
+ return erfc(-x / Math.SQRT2) / 2;
3317
+ }
3318
+ const A = [
3319
+ 3.3871328727963665,
3320
+ 133.14166789178438,
3321
+ 1971.5909503065513,
3322
+ 13731.69376550946,
3323
+ 45921.95393154987,
3324
+ 67265.7709270087,
3325
+ 33430.57558358813,
3326
+ 2509.0809287301227
3327
+ ];
3328
+ const B = [
3329
+ 1,
3330
+ 42.31333070160091,
3331
+ 687.1870074920579,
3332
+ 5394.196021424751,
3333
+ 21213.794301586597,
3334
+ 39307.89580009271,
3335
+ 28729.085735721943,
3336
+ 5226.495278852854
3337
+ ];
3338
+ const C = [
3339
+ 1.4234371107496835,
3340
+ 4.630337846156546,
3341
+ 5.769497221460691,
3342
+ 3.6478483247632045,
3343
+ 1.2704582524523684,
3344
+ .2417807251774506,
3345
+ .022723844989269184,
3346
+ .0007745450142783414
3347
+ ];
3348
+ const D = [
3349
+ 1,
3350
+ 2.053191626637759,
3351
+ 1.6763848301838038,
3352
+ .6897673349851,
3353
+ .14810397642748008,
3354
+ .015198666563616457,
3355
+ .0005475938084995345,
3356
+ 1.0507500716444169e-9
3357
+ ];
3358
+ const E = [
3359
+ 6.657904643501103,
3360
+ 5.463784911164114,
3361
+ 1.7848265399172913,
3362
+ .29656057182850487,
3363
+ .026532189526576124,
3364
+ .0012426609473880784,
3365
+ 27115555687434876e-21,
3366
+ 2.0103343992922881e-7
3367
+ ];
3368
+ const F = [
3369
+ 1,
3370
+ .599832206555888,
3371
+ .1369298809227358,
3372
+ .014875361290850615,
3373
+ .0007868691311456133,
3374
+ 18463183175100548e-21,
3375
+ 1.421511758316446e-7,
3376
+ 20442631033899397e-31
3377
+ ];
3378
+ /** The value of a polynomial with the coefficients `c[0] + c[1] x + …`, by the rule of Horner. */
3379
+ function poly(c, x) {
3380
+ let value = 0;
3381
+ for (let i = c.length - 1; i >= 0; i--) value = value * x + c[i];
3382
+ return value;
3383
+ }
3384
+ /**
3385
+ * This function gives the quantile of the standard normal law, the `x` with `normalCdf(x) = p`. It uses PPND16 of
3386
+ * Wichura (algorithm AS 241). Its relative error is near 1e-16 for each `p` from 1e-300 to 1 - 1e-16.
3387
+ *
3388
+ * @param p - The share of the law below the result, from 0 to 1. A `p` of 0 gives `-Infinity` and 1 gives `Infinity`.
3389
+ */
3390
+ function normalQuantile(p) {
3391
+ if (!(p >= 0 && p <= 1)) throw new RangeError(`normalQuantile: p is from 0 to 1, not ${p}.`);
3392
+ if (p === 0) return Number.NEGATIVE_INFINITY;
3393
+ if (p === 1) return Number.POSITIVE_INFINITY;
3394
+ const q = p - .5;
3395
+ if (Math.abs(q) <= .425) {
3396
+ const r = .180625 - q * q;
3397
+ return q * poly(A, r) / poly(B, r);
3398
+ }
3399
+ let r = Math.sqrt(-Math.log(q < 0 ? p : 1 - p));
3400
+ let value;
3401
+ if (r <= 5) {
3402
+ r -= 1.6;
3403
+ value = poly(C, r) / poly(D, r);
3404
+ } else {
3405
+ r -= 5;
3406
+ value = poly(E, r) / poly(F, r);
3407
+ }
3408
+ return q < 0 ? -value : value;
3409
+ }
3183
3410
  // src/coverage.ts
3184
3411
  /**
3185
3412
  * The rule that finds the smallest sample at which an interval method keeps its level. The input is the hits of the
@@ -3870,6 +4097,6 @@ function inverseDiagonal(hessian, k) {
3870
4097
  }
3871
4098
  return out;
3872
4099
  }
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 };
4100
+ 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, normalCdf, normalQuantile, 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
4101
 
3875
4102
  //# sourceMappingURL=index.js.map