@mark1russell7/rigor-statistics 0.1.12 → 0.1.14

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
@@ -115,6 +115,7 @@ The default expansion has one product for each pair of levels of two dimensions.
115
115
  | `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. |
116
116
  | `signTest(better, worse, sides)`, `signTestPower(n, level)` | The sign test, and the fewest wins out of `n` that the test calls significant. |
117
117
  | `pairedPermutation(candidate, baseline, options)` | The paired permutation test (random sign flips). It uses the size of each difference. |
118
+ | `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. |
118
119
  | `wilson(k, n, z)` | The Wilson interval of a proportion. |
119
120
  | `medianInterval(values, level)` | The distribution-free interval of a median, from two order statistics. It gives `low`, `high`, the `rank` of `low` and the `coverage`. |
120
121
  | `quantileInterval(values, p, level)` | The distribution-free interval of a quantile, from two order statistics. A side with no rank is infinite. The values must be independent draws. |
@@ -124,6 +125,7 @@ The default expansion has one product for each pair of levels of two dimensions.
124
125
  | `partialConjunction(pValues, need)` | The p of the claim that at least `need` of these tests have a real effect. |
125
126
  | `spearman`, `kendallTau`, `ranks` | The rank correlations, with mean ranks for ties. |
126
127
  | `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. |
128
+ | `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. |
127
129
  | `modeCount(values, { minShare, valleyRatio })` | The count of the modes of a sample, from a kernel density estimate. |
128
130
  | `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. |
129
131
  | `brier`, `calibration` | The Brier score of predictions, and the hit rate of each stated level. |
package/build/index.d.ts CHANGED
@@ -786,6 +786,28 @@ interface PermutationResult {
786
786
  * the size of each difference, which the sign test does not. A pair with a difference of 0 adds nothing.
787
787
  */
788
788
  export declare function pairedPermutation(candidate: readonly number[], baseline: readonly number[], options?: PermutationOptions): PermutationResult;
789
+ /** The options of `twoSamplePermutation`. */
790
+ interface TwoSamplePermutationOptions {
791
+ /** The largest number of splits that the test reads. The default is 10 000. */
792
+ readonly runs?: number;
793
+ /** The default is 1. */
794
+ readonly seed?: number | string;
795
+ /** The statistic of the two groups. The default is the median of `a` minus the median of `b`. */
796
+ readonly statistic?: (a: readonly number[], b: readonly number[]) => number;
797
+ }
798
+ /** The result of `twoSamplePermutation`. */
799
+ interface TwoSamplePermutationResult extends PermutationResult {
800
+ /** This field is true when the test read each split, so the p has no noise from the draws. */
801
+ readonly exact: boolean;
802
+ }
803
+ /**
804
+ * The two-sample permutation test (a split of the pooled values). It needs no normal distribution and no pairs, so it
805
+ * compares groups of different sizes. The p holds only if the values of the two groups can change places under the null.
806
+ *
807
+ * When the count of the splits is `runs` or less, the test reads each split, and the p is exact. Otherwise it draws `runs`
808
+ * random splits. A drawn p has noise: a level of 0.001 is 10 counts at 10 000 runs. So give enough runs for a small level.
809
+ */
810
+ export declare function twoSamplePermutation(a: readonly number[], b: readonly number[], options?: TwoSamplePermutationOptions): TwoSamplePermutationResult;
789
811
  /** The ranks of the values, from 1. Equal values get the mean of their ranks. */
790
812
  export declare function ranks(values: readonly number[]): number[];
791
813
  /**
@@ -976,5 +998,37 @@ interface CalibrationLevel {
976
998
  }
977
999
  /** The hit rate of each stated level, from the lowest level. */
978
1000
  export declare function calibration(forecasts: readonly Forecast[]): CalibrationLevel[];
979
- export type { BootstrapOptions, CalibrationLevel, CategoricalDimension, CompareOptions, Comparison, ContinuousDimension, Corrected, CountInterval, Effect, Forecast, Interval, LeastSquaresFit, LeastSquaresOptions, MedianInterval, ModeOptions, NoiseOptions, NoiseState, NoiseVerdict, OrdinalDimension, ParsedResponseRecord, PermutationOptions, PermutationResult, Proportion, QuantileInterval, QuantileMethod, 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, SmoothLaw, SmoothLawScore, Summary, TableResponseModel };
1001
+ /**
1002
+ * This function gives the quantile of the Student t law, from a bisection of its distribution function.
1003
+ *
1004
+ * @param p - The share of the law below the result, above 0 and below 1.
1005
+ * @param df - The degrees of freedom, above 0.
1006
+ */
1007
+ export declare function tQuantile(p: number, df: number): number;
1008
+ /** The options of `optionFloor`. */
1009
+ interface OptionFloorOptions {
1010
+ /** The standard deviation of one value about the mean of its option. All options have the same value. */
1011
+ readonly sigma: number;
1012
+ /** The smallest difference between the means of two options that the comparison finds. */
1013
+ readonly delta: number;
1014
+ /** The count of tests in the family. The level of each test is `alpha / tests`. */
1015
+ readonly tests: number;
1016
+ /** The two-sided level of the family. The default is 0.05. */
1017
+ readonly alpha?: number;
1018
+ /** The share of comparisons that find a difference of `delta`. The default is 0.8. */
1019
+ readonly power?: number;
1020
+ }
1021
+ /**
1022
+ * This function gives the smallest count of values for each of two options. With it, one test finds a difference of
1023
+ * `delta` with the stated power. The form is `n = 2 ((t(1 - alpha / (2 tests), df) + t(power, df)) sigma / delta)^2`,
1024
+ * with `df = 2 n - 2`. The count is on both sides of that form, so the function takes the first count that meets it.
1025
+ *
1026
+ * The function assumes independent values, unpaired groups of equal size, equal `sigma`, and a Bonferroni family.
1027
+ * A value of `sigma` from an older run gives a count for that run. Read `sigma` again on the new values.
1028
+ *
1029
+ * @param options - The spread, the difference, the family and the targets.
1030
+ * @returns A whole number of 2 or more.
1031
+ */
1032
+ export declare function optionFloor(options: OptionFloorOptions): number;
1033
+ export type { BootstrapOptions, CalibrationLevel, CategoricalDimension, CompareOptions, Comparison, ContinuousDimension, Corrected, CountInterval, Effect, Forecast, Interval, LeastSquaresFit, LeastSquaresOptions, MedianInterval, ModeOptions, NoiseOptions, NoiseState, NoiseVerdict, OptionFloorOptions, OrdinalDimension, ParsedResponseRecord, PermutationOptions, PermutationResult, Proportion, QuantileInterval, QuantileMethod, 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, SmoothLaw, SmoothLawScore, Summary, TableResponseModel, TwoSamplePermutationOptions, TwoSamplePermutationResult };
980
1034
  //# 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/tests.ts","../src/rank.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AU;;;wBAIL,YAAY,oBAAoB,aAAa"}
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/rank.ts","../src/discrete.ts","../src/compare.ts","../src/power.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;UC/BzG;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;;;;WAMT;;UAGM;;WAEN;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;;wBAmFa,gBAAgB,2BAA2B,UAAS,mBAAwB;;;;;;wBAS5E,kBAAkB,GAChC,eAAe,KACf,UAAU,KAAK,cACf,YAAY,eAAe,gBAC3B,UAAS,mBACR;;KCxMS;;UAGK;WACN,KAAK;;WAEL;;;UAIM;;;;;WAKN;;WAEA;;;;;;;;;;;;;;;;;;;wBA0MK,UAAU,2BAA2B,UAA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,aAAa,2BAA2B,UAAS;WAA0B;IAAqC;UAW/G;;WAEN;;WAEA;;WAEA;;;UAIM;WACN;WACA;;WAEA;;WAEA;;UAGM;;WAEN;WACA;;WAEA;;WAEA;;WAEA;;WAEA,QAAQ;;WAER;;WAEA;;WAEA;WACA,cAAc;;WAEd;WACA,cAAc;;;;;;;;wBAST,cAAc,2BAA2B,UAAS,iBAAsB;;UA6CvE;WACN;WACA;;;wBASK,MAAM,oBAAoB;;UAQzB;WACN;WACA;WACA;;WAEA;;WAEA,UAAU;;;wBAIL,YAAY,oBAAoB,aAAa;;;;;;;wBChJ7C,UAAU,WAAW;;UAgBpB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;;;;;;;wBAcK,YAAY,SAAS"}
package/build/index.js CHANGED
@@ -2317,6 +2317,72 @@ function pairedPermutation(candidate, baseline, options = {}) {
2317
2317
  runs
2318
2318
  };
2319
2319
  }
2320
+ /** This function gives the count of the ways to choose `k` of `n`, or Infinity when the count is over `limit`. */
2321
+ function choices(n, k, limit) {
2322
+ const small = Math.min(k, n - k);
2323
+ let count = 1;
2324
+ for (let i = 1; i <= small; i++) {
2325
+ count = count * (n - small + i) / i;
2326
+ if (count > limit) return Number.POSITIVE_INFINITY;
2327
+ }
2328
+ return count;
2329
+ }
2330
+ /** This function counts the splits of `pool` into a first group of `size` values that pass the test `extreme`, over each split. */
2331
+ function countEachSplit(pool, size, extreme) {
2332
+ const chosen = Array.from({ length: size }, (_, i) => i);
2333
+ let count = 0;
2334
+ for (;;) {
2335
+ const a = [];
2336
+ const b = [];
2337
+ for (const [i, value] of pool.entries()) (chosen[a.length] === i ? a : b).push(value);
2338
+ if (extreme(a, b)) count++;
2339
+ let place = size - 1;
2340
+ while (place >= 0 && chosen[place] === pool.length - size + place) place--;
2341
+ if (place < 0) return count;
2342
+ let index = chosen[place] + 1;
2343
+ for (let j = place; j < size; j++) chosen[j] = index++;
2344
+ }
2345
+ }
2346
+ /**
2347
+ * The two-sample permutation test (a split of the pooled values). It needs no normal distribution and no pairs, so it
2348
+ * compares groups of different sizes. The p holds only if the values of the two groups can change places under the null.
2349
+ *
2350
+ * When the count of the splits is `runs` or less, the test reads each split, and the p is exact. Otherwise it draws `runs`
2351
+ * random splits. A drawn p has noise: a level of 0.001 is 10 counts at 10 000 runs. So give enough runs for a small level.
2352
+ */
2353
+ function twoSamplePermutation(a, b, options = {}) {
2354
+ if (a.length === 0 || b.length === 0) throw new RangeError(`twoSamplePermutation: the groups have ${a.length} and ${b.length} values, and each group needs one or more.`);
2355
+ const statistic = options.statistic ?? ((x, y) => median(x) - median(y));
2356
+ const runs = options.runs ?? 1e4;
2357
+ if (!Number.isSafeInteger(runs) || runs < 1) throw new RangeError(`twoSamplePermutation: runs is a whole number of 1 or more, not ${runs}.`);
2358
+ const observed = statistic(a, b);
2359
+ const pool = [...a, ...b];
2360
+ const isExtreme = (x, y) => Math.abs(statistic(x, y)) >= Math.abs(observed) * (1 - 1e-12);
2361
+ const splits = choices(pool.length, a.length, runs);
2362
+ if (Number.isFinite(splits)) return {
2363
+ observed,
2364
+ p: countEachSplit(pool, a.length, isExtreme) / splits,
2365
+ runs: splits,
2366
+ exact: true
2367
+ };
2368
+ const r = random(options.seed ?? 1);
2369
+ let extreme = 0;
2370
+ for (let run = 0; run < runs; run++) {
2371
+ for (let i = 0; i < a.length; i++) {
2372
+ const j = i + Math.floor(r.next() * (pool.length - i));
2373
+ const held = pool[i];
2374
+ pool[i] = pool[j];
2375
+ pool[j] = held;
2376
+ }
2377
+ if (isExtreme(pool.slice(0, a.length), pool.slice(a.length))) extreme++;
2378
+ }
2379
+ return {
2380
+ observed,
2381
+ p: (1 + extreme) / (1 + runs),
2382
+ runs,
2383
+ exact: false
2384
+ };
2385
+ }
2320
2386
  // src/rank.ts
2321
2387
  /**
2322
2388
  * Rank correlation: do two measures put the same items in the same order? Use it to test that a cheap proxy (a
@@ -2704,6 +2770,107 @@ function calibration(forecasts) {
2704
2770
  interval: wilson(hits, n)
2705
2771
  }));
2706
2772
  }
2707
- export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, Z95, bestSmoothLaw, binomialInterval, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapTwo, brier, calibration, compareRatios, fitResponse, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, mean, median, medianInterval, modeCount, negativeBinomialInterval, noiseFloor, noiseVerdict, pairedPermutation, parseResponseRecord, partialConjunction, predictResponse, quantile, quantileInterval, quantileSamples, quantileSorted, ranks, responseCells, ridgeSolve, sd, signTest, signTestPower, sliceResponse, smoothLawScores, sorted, spearman, summarize, surfaceResponse, whenHolds, wilson };
2773
+ // src/power.ts
2774
+ /**
2775
+ * The count of values that a comparison of options needs before it starts. The Student t law gives this count, because the
2776
+ * normal formula is too low at a small count. These functions make no draws, so a caller reads the count with no bench.
2777
+ */
2778
+ /** The log of the gamma function, by the form of Lanczos with 6 terms. The argument is above 0. */
2779
+ function logGamma(x) {
2780
+ const terms = [
2781
+ 76.18009172947146,
2782
+ -86.50532032941678,
2783
+ 24.01409824083091,
2784
+ -1.231739572450155,
2785
+ .001208650973866179,
2786
+ -5395239384953e-18
2787
+ ];
2788
+ const base = x + 5.5 - (x + .5) * Math.log(x + 5.5);
2789
+ let series = 1.000000000190015;
2790
+ terms.forEach((term, i) => {
2791
+ series += term / (x + i + 1);
2792
+ });
2793
+ return -base + Math.log(2.5066282746310007 * series / x);
2794
+ }
2795
+ /** The continued fraction of the incomplete beta function, by the method of Lentz. */
2796
+ function betaFraction(x, a, b) {
2797
+ const tiny = 1e-300;
2798
+ const guard = (value) => Math.abs(value) < tiny ? tiny : value;
2799
+ let c = 1;
2800
+ let d = 1 / guard(1 - (a + b) * x / (a + 1));
2801
+ let h = d;
2802
+ for (let m = 1; m <= 500; m++) {
2803
+ const twice = 2 * m;
2804
+ const even = m * (b - m) * x / ((a + twice - 1) * (a + twice));
2805
+ d = 1 / guard(1 + even * d);
2806
+ c = guard(1 + even / c);
2807
+ h *= d * c;
2808
+ const odd = -(a + m) * (a + b + m) * x / ((a + twice) * (a + twice + 1));
2809
+ d = 1 / guard(1 + odd * d);
2810
+ c = guard(1 + odd / c);
2811
+ const step = d * c;
2812
+ h *= step;
2813
+ if (Math.abs(step - 1) < 1e-15) return h;
2814
+ }
2815
+ return h;
2816
+ }
2817
+ /** The regularized incomplete beta function at `x`, from 0 to 1. */
2818
+ function incompleteBeta(x, a, b) {
2819
+ if (x <= 0) return 0;
2820
+ if (x >= 1) return 1;
2821
+ const front = Math.exp(logGamma(a + b) - logGamma(a) - logGamma(b) + a * Math.log(x) + b * Math.log(1 - x));
2822
+ return x < (a + 1) / (a + b + 2) ? front * betaFraction(x, a, b) / a : 1 - front * betaFraction(1 - x, b, a) / b;
2823
+ }
2824
+ /** The share of the Student t law with `df` degrees of freedom below `t`, for `t` of 0 or more. */
2825
+ function upperHalf(t, df) {
2826
+ return 1 - .5 * incompleteBeta(df / (df + t * t), df / 2, .5);
2827
+ }
2828
+ /**
2829
+ * This function gives the quantile of the Student t law, from a bisection of its distribution function.
2830
+ *
2831
+ * @param p - The share of the law below the result, above 0 and below 1.
2832
+ * @param df - The degrees of freedom, above 0.
2833
+ */
2834
+ function tQuantile(p, df) {
2835
+ if (!(p > 0 && p < 1)) throw new RangeError(`tQuantile: p is above 0 and below 1, not ${p}.`);
2836
+ if (!(df > 0 && Number.isFinite(df))) throw new RangeError(`tQuantile: df is a finite number above 0, not ${df}.`);
2837
+ if (p < .5) return -tQuantile(1 - p, df);
2838
+ let high = 1;
2839
+ while (upperHalf(high, df) < p) high *= 2;
2840
+ let low = 0;
2841
+ for (let step = 0; step < 200 && high - low > 1e-12 * high; step++) {
2842
+ const middle = (low + high) / 2;
2843
+ if (upperHalf(middle, df) < p) low = middle;
2844
+ else high = middle;
2845
+ }
2846
+ return (low + high) / 2;
2847
+ }
2848
+ /**
2849
+ * This function gives the smallest count of values for each of two options. With it, one test finds a difference of
2850
+ * `delta` with the stated power. The form is `n = 2 ((t(1 - alpha / (2 tests), df) + t(power, df)) sigma / delta)^2`,
2851
+ * with `df = 2 n - 2`. The count is on both sides of that form, so the function takes the first count that meets it.
2852
+ *
2853
+ * The function assumes independent values, unpaired groups of equal size, equal `sigma`, and a Bonferroni family.
2854
+ * A value of `sigma` from an older run gives a count for that run. Read `sigma` again on the new values.
2855
+ *
2856
+ * @param options - The spread, the difference, the family and the targets.
2857
+ * @returns A whole number of 2 or more.
2858
+ */
2859
+ function optionFloor(options) {
2860
+ const { sigma, delta, tests, alpha = .05, power = .8 } = options;
2861
+ if (!(sigma > 0 && Number.isFinite(sigma))) throw new RangeError(`optionFloor: sigma is a finite number above 0, not ${sigma}.`);
2862
+ if (!(delta > 0 && Number.isFinite(delta))) throw new RangeError(`optionFloor: delta is a finite number above 0, not ${delta}.`);
2863
+ if (!Number.isSafeInteger(tests) || tests < 1) throw new RangeError(`optionFloor: tests is a whole number of 1 or more, not ${tests}.`);
2864
+ if (!(alpha > 0 && alpha < 1)) throw new RangeError(`optionFloor: alpha is above 0 and below 1, not ${alpha}.`);
2865
+ if (!(power > .5 && power < 1)) throw new RangeError(`optionFloor: power is above 0.5 and below 1, not ${power}.`);
2866
+ const level = 1 - alpha / (2 * tests);
2867
+ for (let n = 2; n < 1e7; n++) {
2868
+ const df = 2 * n - 2;
2869
+ const need = 2 * ((tQuantile(level, df) + tQuantile(power, df)) * sigma / delta) ** 2;
2870
+ if (n >= need) return n;
2871
+ }
2872
+ throw new RangeError(`optionFloor: no count under 10,000,000 for sigma ${sigma} and delta ${delta}.`);
2873
+ }
2874
+ export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, Z95, bestSmoothLaw, binomialInterval, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapTwo, brier, calibration, compareRatios, fitResponse, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, mean, median, medianInterval, modeCount, negativeBinomialInterval, noiseFloor, noiseVerdict, optionFloor, pairedPermutation, parseResponseRecord, partialConjunction, predictResponse, quantile, quantileInterval, quantileSamples, quantileSorted, ranks, responseCells, ridgeSolve, sd, signTest, signTestPower, sliceResponse, smoothLawScores, sorted, spearman, summarize, surfaceResponse, tQuantile, twoSamplePermutation, whenHolds, wilson };
2708
2875
 
2709
2876
  //# sourceMappingURL=index.js.map