@mark1russell7/rigor-statistics 0.1.15 → 0.1.17
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 -1
- package/build/index.d.ts +38 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +66 -4
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,7 +106,8 @@ The default expansion has one product for each pair of levels of two dimensions.
|
|
|
106
106
|
| --- | --- |
|
|
107
107
|
| `mean`, `sd`, `median`, `summarize` | The descriptive statistics. `sd` is the sample standard deviation. |
|
|
108
108
|
| `quantile(values, p, method)`, `quantileSorted` | The `p` quantile, with the `"linear"` method (type 7, the default), the `"nearest-rank"` method (type 1) or the `"higher"` method (`sorted[Math.ceil(p * (n - 1))]`, as NumPy). |
|
|
109
|
-
| `bootstrap(data, statistic, options)` | A percentile bootstrap interval of any statistic. The options are `runs`, `level` or `ends`, `seed` and `
|
|
109
|
+
| `bootstrap(data, statistic, options)` | A percentile bootstrap interval of any statistic. The options are `runs`, `level` or `ends`, `seed`, `method` and `against`. |
|
|
110
|
+
| 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. |
|
|
110
111
|
| `bootstrapMedian`, `bootstrapClusters` | The interval of the median, and a bootstrap that draws whole clusters (boards, seeds, sites). |
|
|
111
112
|
| `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`. |
|
|
112
113
|
| `bootstrapMedianRatio(numerator, denominator, options)` | The interval of `median(numerator) / median(denominator)`. It is the uncertainty of the ratio, not the spread of the samples. |
|
|
@@ -117,6 +118,8 @@ The default expansion has one product for each pair of levels of two dimensions.
|
|
|
117
118
|
| `pairedPermutation(candidate, baseline, options)` | The paired permutation test (random sign flips). It uses the size of each difference. |
|
|
118
119
|
| `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. |
|
|
119
120
|
| `wilson(k, n, z)` | The Wilson interval of a proportion. |
|
|
121
|
+
| `wilsonSampleSize(target, expected, z, max)` | The smallest number of trials at which the Wilson lower end reaches the target, at the expected proportion. |
|
|
122
|
+
| `cohenKappa(a, b)` | The agreement of two raters beyond chance (Cohen's kappa), with the observed and the chance agreement. |
|
|
120
123
|
| `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`. |
|
|
121
124
|
| `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. |
|
|
122
125
|
| `quantileSamples(p, level)` | The fewest independent values that give a quantile an upper bound. At the level 0.95: 72 values for p95, 368 for p99 and 3,688 for p99.9. |
|
package/build/index.d.ts
CHANGED
|
@@ -93,8 +93,22 @@ interface BootstrapOptions {
|
|
|
93
93
|
* not 0.025, so a copy that writes 0.025 needs this option to give the same numbers.
|
|
94
94
|
*/
|
|
95
95
|
readonly ends?: readonly [number, number];
|
|
96
|
+
/**
|
|
97
|
+
* The value of a claim to test, for example 0 for "no difference". With this option, the interval also gives `pAbove`
|
|
98
|
+
* and `pBelow` from the same draws, so the ends do not change. The default is no value and no p.
|
|
99
|
+
*/
|
|
100
|
+
readonly against?: number;
|
|
101
|
+
}
|
|
102
|
+
/** The two bootstrap p of the option `against`. The smallest p is 1 / (finite + 1), so a family correction needs enough runs. */
|
|
103
|
+
interface SideP {
|
|
104
|
+
/** The value of the option `against`. */
|
|
105
|
+
readonly against: number;
|
|
106
|
+
/** The p of the claim "the statistic is above `against`": (1 + the finite runs at or below `against`) / (finite + 1). */
|
|
107
|
+
readonly pAbove: number;
|
|
108
|
+
/** The p of the claim "the statistic is below `against`": (1 + the finite runs at or above `against`) / (finite + 1). */
|
|
109
|
+
readonly pBelow: number;
|
|
96
110
|
}
|
|
97
|
-
interface Interval {
|
|
111
|
+
interface Interval extends Partial<SideP> {
|
|
98
112
|
/** The statistic of all the data. */
|
|
99
113
|
readonly estimate: number;
|
|
100
114
|
readonly low: number;
|
|
@@ -808,6 +822,28 @@ interface TwoSamplePermutationResult extends PermutationResult {
|
|
|
808
822
|
* 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
823
|
*/
|
|
810
824
|
export declare function twoSamplePermutation(a: readonly number[], b: readonly number[], options?: TwoSamplePermutationOptions): TwoSamplePermutationResult;
|
|
825
|
+
/**
|
|
826
|
+
* The smallest number of trials `n` at which the Wilson lower end reaches `target`, when the true proportion is
|
|
827
|
+
* `expected`. Each `n` takes `round(expected × n)` successes. The function gives `undefined` when `expected` is not
|
|
828
|
+
* above `target`, or when no `n` up to `max` reaches it. An audit of an agreement uses it to fix its size.
|
|
829
|
+
*/
|
|
830
|
+
export declare function wilsonSampleSize(target: number, expected: number, z?: number, max?: number): number | undefined;
|
|
831
|
+
/** The agreement of two raters that give one category to each item. */
|
|
832
|
+
interface Kappa {
|
|
833
|
+
/** The number of items. */
|
|
834
|
+
readonly n: number;
|
|
835
|
+
/** The part of the items where the two raters give the same category. */
|
|
836
|
+
readonly observed: number;
|
|
837
|
+
/** The part of agreement that two independent raters with the same frequencies of categories give. */
|
|
838
|
+
readonly chance: number;
|
|
839
|
+
/** Cohen's kappa: `(observed − chance) / (1 − chance)`. It is `undefined` when `chance` is 1. */
|
|
840
|
+
readonly kappa: number | undefined;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Cohen's kappa of two raters (Cohen, 1960). Item `i` has the category `a[i]` from one rater and `b[i]` from the
|
|
844
|
+
* other. Two categories are the same when they are `===`. A kappa of 1 is full agreement, and 0 is the agreement of chance.
|
|
845
|
+
*/
|
|
846
|
+
export declare function cohenKappa<T>(a: readonly T[], b: readonly T[]): Kappa;
|
|
811
847
|
/** The ranks of the values, from 1. Equal values get the mean of their ranks. */
|
|
812
848
|
export declare function ranks(values: readonly number[]): number[];
|
|
813
849
|
/**
|
|
@@ -1033,5 +1069,5 @@ interface OptionFloorOptions {
|
|
|
1033
1069
|
* @returns A whole number of 2 or more.
|
|
1034
1070
|
*/
|
|
1035
1071
|
export declare function optionFloor(options: OptionFloorOptions): number;
|
|
1036
|
-
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 };
|
|
1072
|
+
export type { BootstrapOptions, CalibrationLevel, CategoricalDimension, CompareOptions, Comparison, ContinuousDimension, Corrected, CountInterval, Effect, Forecast, Interval, Kappa, 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, SideP, SmoothLaw, SmoothLawScore, Summary, TableResponseModel, TwoSamplePermutationOptions, TwoSamplePermutationResult };
|
|
1037
1073
|
//# 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/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;;
|
|
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"],"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;;;;;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;;KCxOS;;UAGK;WACN,KAAK;;WAEL;;;UAIM;;;;;WAKN;;WAEA;;;;;;;;;;;;;;;;;;;w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W,iBAAe;UCvKrE;;WAEN;;WAEA;;;;;;WAMA;;;;;;wBAgBK,WAAW,2BAA2B,UAAS;;;;;KASnD;;UAGK;;WAEN;WACA;;WAEA;;WAEA;WACA;;WAEA;WACA,OAAO;;;;;;;;wBASF,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;;;;;;;;;;;;;;;;wBAiBK,YAAY,SAAS"}
|
package/build/index.js
CHANGED
|
@@ -273,17 +273,37 @@ function settings(name, options) {
|
|
|
273
273
|
if (!(lowEnd >= 0 && lowEnd < highEnd && highEnd <= 1)) throw new RangeError(`${name}: the ends are 0 <= low < high <= 1, not ${lowEnd} and ${highEnd}.`);
|
|
274
274
|
const level = options.ends ? highEnd - lowEnd : options.level ?? .95;
|
|
275
275
|
if (!(level > 0 && level < 1)) throw new RangeError(`${name}: level is more than 0 and less than 1, not ${level}.`);
|
|
276
|
+
const against = options.against;
|
|
277
|
+
if (against !== void 0 && !Number.isFinite(against)) throw new RangeError(`${name}: against is a finite number, not ${against}.`);
|
|
276
278
|
return {
|
|
277
279
|
runs,
|
|
278
280
|
lowEnd,
|
|
279
281
|
highEnd,
|
|
280
282
|
level,
|
|
281
|
-
method: options.method ?? "linear"
|
|
283
|
+
method: options.method ?? "linear",
|
|
284
|
+
against
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/** This function gives the two p of the option `against`, or nothing without the option. With no finite run, each p is 1. */
|
|
288
|
+
function sides(values, against) {
|
|
289
|
+
if (against === void 0) return {};
|
|
290
|
+
let atOrBelow = 0;
|
|
291
|
+
let atOrAbove = 0;
|
|
292
|
+
for (const v of values) {
|
|
293
|
+
if (v <= against) atOrBelow++;
|
|
294
|
+
if (v >= against) atOrAbove++;
|
|
295
|
+
}
|
|
296
|
+
const n = values.length + 1;
|
|
297
|
+
return {
|
|
298
|
+
against,
|
|
299
|
+
pAbove: (1 + atOrBelow) / n,
|
|
300
|
+
pBelow: (1 + atOrAbove) / n
|
|
282
301
|
};
|
|
283
302
|
}
|
|
284
303
|
/** The interval of the finite statistics of the runs. When no run is finite, low and high are equal to the estimate. */
|
|
285
304
|
function ends(values, estimate, s, seed) {
|
|
286
305
|
const { runs, level } = s;
|
|
306
|
+
const p = sides(values, s.against);
|
|
287
307
|
if (values.length === 0) return {
|
|
288
308
|
estimate,
|
|
289
309
|
low: estimate,
|
|
@@ -291,7 +311,8 @@ function ends(values, estimate, s, seed) {
|
|
|
291
311
|
level,
|
|
292
312
|
runs,
|
|
293
313
|
finite: 0,
|
|
294
|
-
seed
|
|
314
|
+
seed,
|
|
315
|
+
...p
|
|
295
316
|
};
|
|
296
317
|
const v = sorted(values);
|
|
297
318
|
return {
|
|
@@ -301,7 +322,8 @@ function ends(values, estimate, s, seed) {
|
|
|
301
322
|
level,
|
|
302
323
|
runs,
|
|
303
324
|
finite: v.length,
|
|
304
|
-
seed
|
|
325
|
+
seed,
|
|
326
|
+
...p
|
|
305
327
|
};
|
|
306
328
|
}
|
|
307
329
|
/**
|
|
@@ -2383,6 +2405,46 @@ function twoSamplePermutation(a, b, options = {}) {
|
|
|
2383
2405
|
exact: false
|
|
2384
2406
|
};
|
|
2385
2407
|
}
|
|
2408
|
+
/**
|
|
2409
|
+
* The smallest number of trials `n` at which the Wilson lower end reaches `target`, when the true proportion is
|
|
2410
|
+
* `expected`. Each `n` takes `round(expected × n)` successes. The function gives `undefined` when `expected` is not
|
|
2411
|
+
* above `target`, or when no `n` up to `max` reaches it. An audit of an agreement uses it to fix its size.
|
|
2412
|
+
*/
|
|
2413
|
+
function wilsonSampleSize(target, expected, z = Z95, max = 1e6) {
|
|
2414
|
+
if (!(target >= 0 && target <= 1 && expected >= 0 && expected <= 1)) throw new RangeError(`wilsonSampleSize: target ${target} and expected ${expected} must be from 0 to 1.`);
|
|
2415
|
+
whole$1("wilsonSampleSize", max);
|
|
2416
|
+
if (expected <= target) return void 0;
|
|
2417
|
+
for (let n = 1; n <= max; n++) if (wilson(Math.round(expected * n), n, z).low >= target) return n;
|
|
2418
|
+
}
|
|
2419
|
+
// src/agreement.ts
|
|
2420
|
+
/**
|
|
2421
|
+
* Cohen's kappa of two raters (Cohen, 1960). Item `i` has the category `a[i]` from one rater and `b[i]` from the
|
|
2422
|
+
* other. Two categories are the same when they are `===`. A kappa of 1 is full agreement, and 0 is the agreement of chance.
|
|
2423
|
+
*/
|
|
2424
|
+
function cohenKappa(a, b) {
|
|
2425
|
+
if (a.length !== b.length) throw new RangeError(`cohenKappa: the raters have ${a.length} and ${b.length} items.`);
|
|
2426
|
+
const n = a.length;
|
|
2427
|
+
if (n === 0) throw new RangeError("cohenKappa: there are no items.");
|
|
2428
|
+
const countA = /* @__PURE__ */ new Map();
|
|
2429
|
+
const countB = /* @__PURE__ */ new Map();
|
|
2430
|
+
let same = 0;
|
|
2431
|
+
for (let i = 0; i < n; i++) {
|
|
2432
|
+
const x = a[i];
|
|
2433
|
+
const y = b[i];
|
|
2434
|
+
if (x === y) same++;
|
|
2435
|
+
countA.set(x, (countA.get(x) ?? 0) + 1);
|
|
2436
|
+
countB.set(y, (countB.get(y) ?? 0) + 1);
|
|
2437
|
+
}
|
|
2438
|
+
let chance = 0;
|
|
2439
|
+
for (const [category, count] of countA) chance += count / n * ((countB.get(category) ?? 0) / n);
|
|
2440
|
+
const observed = same / n;
|
|
2441
|
+
return {
|
|
2442
|
+
n,
|
|
2443
|
+
observed,
|
|
2444
|
+
chance,
|
|
2445
|
+
kappa: chance === 1 ? void 0 : (observed - chance) / (1 - chance)
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2386
2448
|
// src/rank.ts
|
|
2387
2449
|
/**
|
|
2388
2450
|
* Rank correlation: do two measures put the same items in the same order? Use it to test that a cheap proxy (a
|
|
@@ -2874,6 +2936,6 @@ function optionFloor(options) {
|
|
|
2874
2936
|
}
|
|
2875
2937
|
throw new RangeError(`optionFloor: no count under 10,000,000 for sigma ${sigma} and delta ${delta}.`);
|
|
2876
2938
|
}
|
|
2877
|
-
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 };
|
|
2939
|
+
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, cohenKappa, 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, wilsonSampleSize };
|
|
2878
2940
|
|
|
2879
2941
|
//# sourceMappingURL=index.js.map
|