@mark1russell7/rigor-statistics 0.1.16 → 0.1.18
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 +3 -0
- package/build/index.d.ts +44 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +77 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,6 +111,7 @@ The default expansion has one product for each pair of levels of two dimensions.
|
|
|
111
111
|
| `bootstrapMedian`, `bootstrapClusters` | The interval of the median, and a bootstrap that draws whole clusters (boards, seeds, sites). |
|
|
112
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`. |
|
|
113
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. |
|
|
114
|
+
| `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. |
|
|
114
115
|
| `leastSquares(x, y, { intercept })` | The ordinary least-squares fit of `y` on the rows of `x`, with a QR decomposition. It gives the coefficients, `residualSd`, `r2`, `n` and `k`. A singular design gives NaN coefficients. |
|
|
115
116
|
| `bootstrapLeastSquares(x, y, options)` | One bootstrap interval for each coefficient of `leastSquares`, from the same draws of whole rows. A singular draw does not count. |
|
|
116
117
|
| `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. |
|
|
@@ -118,6 +119,8 @@ The default expansion has one product for each pair of levels of two dimensions.
|
|
|
118
119
|
| `pairedPermutation(candidate, baseline, options)` | The paired permutation test (random sign flips). It uses the size of each difference. |
|
|
119
120
|
| `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. |
|
|
120
121
|
| `wilson(k, n, z)` | The Wilson interval of a proportion. |
|
|
122
|
+
| `wilsonSampleSize(target, expected, z, max)` | The smallest number of trials at which the Wilson lower end reaches the target, at the expected proportion. |
|
|
123
|
+
| `cohenKappa(a, b)` | The agreement of two raters beyond chance (Cohen's kappa), with the observed and the chance agreement. |
|
|
121
124
|
| `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`. |
|
|
122
125
|
| `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. |
|
|
123
126
|
| `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
|
@@ -154,6 +154,27 @@ export declare function bootstrapMedian(values: readonly number[], options?: Boo
|
|
|
154
154
|
* are in the order of their first row.
|
|
155
155
|
*/
|
|
156
156
|
export declare function bootstrapClusters<T>(rows: readonly T[], cluster: (row: T) => string, statistic: (rows: readonly T[]) => number, options?: BootstrapOptions): Interval;
|
|
157
|
+
interface SampleTotalOptions extends BootstrapOptions {
|
|
158
|
+
/** The number of items in the whole population, `n`. It is a whole number, and it is not less than the sample. */
|
|
159
|
+
readonly population: number;
|
|
160
|
+
/** The factor from the sum of the sample to the total of the population. The default is `population / values.length`. */
|
|
161
|
+
readonly scale?: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* A bootstrap interval of the total of a population from a uniform sample of `m` of its `n` items, drawn without
|
|
165
|
+
* replacement. The estimate is `scale * sum(values)`. Each run draws `m` values with replacement, as `bootstrap`
|
|
166
|
+
* does. The deviation of each run from the sum of the sample gets the factor `scale * sqrt(1 - m / n)`, the finite
|
|
167
|
+
* population correction. When `m` is `n`, the interval is the estimate.
|
|
168
|
+
*
|
|
169
|
+
* The sample has 2 values or more, and each value is finite. With the same seed, the result is equal to the
|
|
170
|
+
* `bootstrap` of the same statistic, to the bit.
|
|
171
|
+
*
|
|
172
|
+
* The interval is narrow for a small sample. The draws give the variance of the sample with the divisor `m`, not
|
|
173
|
+
* `m - 1`, so the width gets the factor `sqrt((m - 1) / m)`. The skew of the values adds to the miss. In the tests,
|
|
174
|
+
* 400 samples of `m = 8` of `n = 40` hold the total 346 times (Wilson 0.828 to 0.895). At `m = 100` of `n = 200`,
|
|
175
|
+
* the coverage agrees with 95%.
|
|
176
|
+
*/
|
|
177
|
+
export declare function sampleTotalInterval(values: readonly number[], options: SampleTotalOptions): Interval;
|
|
157
178
|
/** The smooth laws that `smoothLawScores` compares. Each law has 2 fitted numbers. */
|
|
158
179
|
type SmoothLaw = "uniform" | "normal" | "exponential" | "log-normal" | "pareto";
|
|
159
180
|
/** The value of one law at its fit. */
|
|
@@ -822,6 +843,28 @@ interface TwoSamplePermutationResult extends PermutationResult {
|
|
|
822
843
|
* 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.
|
|
823
844
|
*/
|
|
824
845
|
export declare function twoSamplePermutation(a: readonly number[], b: readonly number[], options?: TwoSamplePermutationOptions): TwoSamplePermutationResult;
|
|
846
|
+
/**
|
|
847
|
+
* The smallest number of trials `n` at which the Wilson lower end reaches `target`, when the true proportion is
|
|
848
|
+
* `expected`. Each `n` takes `round(expected × n)` successes. The function gives `undefined` when `expected` is not
|
|
849
|
+
* above `target`, or when no `n` up to `max` reaches it. An audit of an agreement uses it to fix its size.
|
|
850
|
+
*/
|
|
851
|
+
export declare function wilsonSampleSize(target: number, expected: number, z?: number, max?: number): number | undefined;
|
|
852
|
+
/** The agreement of two raters that give one category to each item. */
|
|
853
|
+
interface Kappa {
|
|
854
|
+
/** The number of items. */
|
|
855
|
+
readonly n: number;
|
|
856
|
+
/** The part of the items where the two raters give the same category. */
|
|
857
|
+
readonly observed: number;
|
|
858
|
+
/** The part of agreement that two independent raters with the same frequencies of categories give. */
|
|
859
|
+
readonly chance: number;
|
|
860
|
+
/** Cohen's kappa: `(observed − chance) / (1 − chance)`. It is `undefined` when `chance` is 1. */
|
|
861
|
+
readonly kappa: number | undefined;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Cohen's kappa of two raters (Cohen, 1960). Item `i` has the category `a[i]` from one rater and `b[i]` from the
|
|
865
|
+
* other. Two categories are the same when they are `===`. A kappa of 1 is full agreement, and 0 is the agreement of chance.
|
|
866
|
+
*/
|
|
867
|
+
export declare function cohenKappa<T>(a: readonly T[], b: readonly T[]): Kappa;
|
|
825
868
|
/** The ranks of the values, from 1. Equal values get the mean of their ranks. */
|
|
826
869
|
export declare function ranks(values: readonly number[]): number[];
|
|
827
870
|
/**
|
|
@@ -1047,5 +1090,5 @@ interface OptionFloorOptions {
|
|
|
1047
1090
|
* @returns A whole number of 2 or more.
|
|
1048
1091
|
*/
|
|
1049
1092
|
export declare function optionFloor(options: OptionFloorOptions): number;
|
|
1050
|
-
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, SideP, SmoothLaw, SmoothLawScore, Summary, TableResponseModel, TwoSamplePermutationOptions, TwoSamplePermutationResult };
|
|
1093
|
+
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, SampleTotalOptions, SideP, SmoothLaw, SmoothLawScore, Summary, TableResponseModel, TwoSamplePermutationOptions, TwoSamplePermutationResult };
|
|
1051
1094
|
//# 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;
|
|
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;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;;;;;;;;w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are equal to the draws of the copies in highways, packing and layout-contract.
|
|
202
202
|
* `bootstrapTwo` draws two independent samples in each run: first the items of `a`, then the items of `b`.
|
|
203
203
|
* `bootstrapLeastSquares` draws whole rows, and gives one interval for each coefficient from the same draws.
|
|
204
|
+
*
|
|
205
|
+
* `sampleTotalInterval` gives the interval of a population total from a sample without replacement.
|
|
204
206
|
*/
|
|
205
207
|
/**
|
|
206
208
|
* A percentile bootstrap interval of `statistic` over `data`. A run whose statistic is not finite (NaN or an
|
|
@@ -385,6 +387,40 @@ function bootstrapClusters(rows, cluster, statistic, options = {}) {
|
|
|
385
387
|
estimate
|
|
386
388
|
};
|
|
387
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* A bootstrap interval of the total of a population from a uniform sample of `m` of its `n` items, drawn without
|
|
392
|
+
* replacement. The estimate is `scale * sum(values)`. Each run draws `m` values with replacement, as `bootstrap`
|
|
393
|
+
* does. The deviation of each run from the sum of the sample gets the factor `scale * sqrt(1 - m / n)`, the finite
|
|
394
|
+
* population correction. When `m` is `n`, the interval is the estimate.
|
|
395
|
+
*
|
|
396
|
+
* The sample has 2 values or more, and each value is finite. With the same seed, the result is equal to the
|
|
397
|
+
* `bootstrap` of the same statistic, to the bit.
|
|
398
|
+
*
|
|
399
|
+
* The interval is narrow for a small sample. The draws give the variance of the sample with the divisor `m`, not
|
|
400
|
+
* `m - 1`, so the width gets the factor `sqrt((m - 1) / m)`. The skew of the values adds to the miss. In the tests,
|
|
401
|
+
* 400 samples of `m = 8` of `n = 40` hold the total 346 times (Wilson 0.828 to 0.895). At `m = 100` of `n = 200`,
|
|
402
|
+
* the coverage agrees with 95%.
|
|
403
|
+
*/
|
|
404
|
+
function sampleTotalInterval(values, options) {
|
|
405
|
+
const name = "sampleTotalInterval";
|
|
406
|
+
const m = values.length;
|
|
407
|
+
const n = options.population;
|
|
408
|
+
if (m < 2) throw new RangeError(`${name}: the sample has 2 values or more, not ${m}.`);
|
|
409
|
+
if (!Number.isSafeInteger(n) || n < m) throw new RangeError(`${name}: population is a whole number of ${m} (the sample) or more, not ${n}.`);
|
|
410
|
+
for (const v of values) if (!Number.isFinite(v)) throw new RangeError(`${name}: each value is a finite number, not ${v}.`);
|
|
411
|
+
const scale = options.scale ?? n / m;
|
|
412
|
+
if (!(Number.isFinite(scale) && scale > 0)) throw new RangeError(`${name}: scale is a finite number more than 0, not ${scale}.`);
|
|
413
|
+
const all = sum(values);
|
|
414
|
+
const estimate = scale * all;
|
|
415
|
+
const spread = Math.sqrt(1 - m / n) * scale;
|
|
416
|
+
return bootstrap(values, (drawn) => estimate + spread * (sum(drawn) - all), options);
|
|
417
|
+
}
|
|
418
|
+
/** The sum of the values from the first to the last, as `values.reduce((s, t) => s + t, 0)`. */
|
|
419
|
+
function sum(values) {
|
|
420
|
+
let s = 0;
|
|
421
|
+
for (const v of values) s += v;
|
|
422
|
+
return s;
|
|
423
|
+
}
|
|
388
424
|
// src/distribution.ts
|
|
389
425
|
/**
|
|
390
426
|
* The shape of a sample: the count of its modes, and the smooth law with the highest likelihood. Use them to read the
|
|
@@ -2405,6 +2441,46 @@ function twoSamplePermutation(a, b, options = {}) {
|
|
|
2405
2441
|
exact: false
|
|
2406
2442
|
};
|
|
2407
2443
|
}
|
|
2444
|
+
/**
|
|
2445
|
+
* The smallest number of trials `n` at which the Wilson lower end reaches `target`, when the true proportion is
|
|
2446
|
+
* `expected`. Each `n` takes `round(expected × n)` successes. The function gives `undefined` when `expected` is not
|
|
2447
|
+
* above `target`, or when no `n` up to `max` reaches it. An audit of an agreement uses it to fix its size.
|
|
2448
|
+
*/
|
|
2449
|
+
function wilsonSampleSize(target, expected, z = Z95, max = 1e6) {
|
|
2450
|
+
if (!(target >= 0 && target <= 1 && expected >= 0 && expected <= 1)) throw new RangeError(`wilsonSampleSize: target ${target} and expected ${expected} must be from 0 to 1.`);
|
|
2451
|
+
whole$1("wilsonSampleSize", max);
|
|
2452
|
+
if (expected <= target) return void 0;
|
|
2453
|
+
for (let n = 1; n <= max; n++) if (wilson(Math.round(expected * n), n, z).low >= target) return n;
|
|
2454
|
+
}
|
|
2455
|
+
// src/agreement.ts
|
|
2456
|
+
/**
|
|
2457
|
+
* Cohen's kappa of two raters (Cohen, 1960). Item `i` has the category `a[i]` from one rater and `b[i]` from the
|
|
2458
|
+
* other. Two categories are the same when they are `===`. A kappa of 1 is full agreement, and 0 is the agreement of chance.
|
|
2459
|
+
*/
|
|
2460
|
+
function cohenKappa(a, b) {
|
|
2461
|
+
if (a.length !== b.length) throw new RangeError(`cohenKappa: the raters have ${a.length} and ${b.length} items.`);
|
|
2462
|
+
const n = a.length;
|
|
2463
|
+
if (n === 0) throw new RangeError("cohenKappa: there are no items.");
|
|
2464
|
+
const countA = /* @__PURE__ */ new Map();
|
|
2465
|
+
const countB = /* @__PURE__ */ new Map();
|
|
2466
|
+
let same = 0;
|
|
2467
|
+
for (let i = 0; i < n; i++) {
|
|
2468
|
+
const x = a[i];
|
|
2469
|
+
const y = b[i];
|
|
2470
|
+
if (x === y) same++;
|
|
2471
|
+
countA.set(x, (countA.get(x) ?? 0) + 1);
|
|
2472
|
+
countB.set(y, (countB.get(y) ?? 0) + 1);
|
|
2473
|
+
}
|
|
2474
|
+
let chance = 0;
|
|
2475
|
+
for (const [category, count] of countA) chance += count / n * ((countB.get(category) ?? 0) / n);
|
|
2476
|
+
const observed = same / n;
|
|
2477
|
+
return {
|
|
2478
|
+
n,
|
|
2479
|
+
observed,
|
|
2480
|
+
chance,
|
|
2481
|
+
kappa: chance === 1 ? void 0 : (observed - chance) / (1 - chance)
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2408
2484
|
// src/rank.ts
|
|
2409
2485
|
/**
|
|
2410
2486
|
* Rank correlation: do two measures put the same items in the same order? Use it to test that a cheap proxy (a
|
|
@@ -2896,6 +2972,6 @@ function optionFloor(options) {
|
|
|
2896
2972
|
}
|
|
2897
2973
|
throw new RangeError(`optionFloor: no count under 10,000,000 for sigma ${sigma} and delta ${delta}.`);
|
|
2898
2974
|
}
|
|
2899
|
-
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 };
|
|
2975
|
+
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, sampleTotalInterval, sd, signTest, signTestPower, sliceResponse, smoothLawScores, sorted, spearman, summarize, surfaceResponse, tQuantile, twoSamplePermutation, whenHolds, wilson, wilsonSampleSize };
|
|
2900
2976
|
|
|
2901
2977
|
//# sourceMappingURL=index.js.map
|