@mark1russell7/rigor-statistics 0.1.18 → 0.1.19
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 +2 -1
- package/build/index.d.ts +121 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +181 -5
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,7 +111,8 @@ 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
|
+
| `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`. |
|
|
115
|
+
| `uStatisticInterval(totals, { order, population, method, level, range })` | The interval of a total over all sets of `r` units of a population, for example the crossings of all pairs. The input is the total of each unit of a sample without replacement. The estimate is `S * C(n, r) / C(m, r)`. The method `"conservative"` uses the Hoeffding bound of a U-statistic with `floor(m / r)` draws and the `range` of the kernel. It holds at each `m`. The method `"tight"` uses the jackknife variance times `1 - m / n`, and the t quantile with `m - 1` degrees of freedom. This variance is exact for a linear kernel and larger for others. When all the totals are equal, the method `"tight"` uses the method `"conservative"`, or it throws without `range`. The result gives the `method` that it used. At `m = 8`, the coverage of `"tight"` is 0.885 to 0.915 for a skewed kernel. The method `"auto"` needs `range`. It uses `"tight"` from `m = U_STATISTIC_TIGHT_MIN_SAMPLE`. No measured `m` gets 0.95 in each cell, so this constant is infinite. |
|
|
115
116
|
| `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. |
|
|
116
117
|
| `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. |
|
|
117
118
|
| `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. |
|
package/build/index.d.ts
CHANGED
|
@@ -172,7 +172,7 @@ interface SampleTotalOptions extends BootstrapOptions {
|
|
|
172
172
|
* The interval is narrow for a small sample. The draws give the variance of the sample with the divisor `m`, not
|
|
173
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
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%.
|
|
175
|
+
* the coverage agrees with 95%. For a total over the pairs of the items, use `uStatisticInterval`.
|
|
176
176
|
*/
|
|
177
177
|
export declare function sampleTotalInterval(values: readonly number[], options: SampleTotalOptions): Interval;
|
|
178
178
|
/** The smooth laws that `smoothLawScores` compares. Each law has 2 fitted numbers. */
|
|
@@ -1090,5 +1090,124 @@ interface OptionFloorOptions {
|
|
|
1090
1090
|
* @returns A whole number of 2 or more.
|
|
1091
1091
|
*/
|
|
1092
1092
|
export declare function optionFloor(options: OptionFloorOptions): number;
|
|
1093
|
-
|
|
1093
|
+
/** The methods of `uStatisticInterval`. The method `"auto"` selects one of the other two for each sample. */
|
|
1094
|
+
type UStatisticMethod = "conservative" | "tight" | "auto";
|
|
1095
|
+
/**
|
|
1096
|
+
* The smallest sample `m` at which the method `"auto"` uses the method `"tight"`. The value comes from the pinned
|
|
1097
|
+
* counts of the tests. No measured `m` obeys the rule, so the value is infinite. The TSDoc of `uStatisticInterval`
|
|
1098
|
+
* gives the rule and the counts.
|
|
1099
|
+
*/
|
|
1100
|
+
export declare const U_STATISTIC_TIGHT_MIN_SAMPLE: number;
|
|
1101
|
+
/** The options of `uStatisticInterval`. */
|
|
1102
|
+
interface UStatisticOptions {
|
|
1103
|
+
/** The order `r` of the kernel: the number of units in each set. It is a whole number of 1 or more. */
|
|
1104
|
+
readonly order: number;
|
|
1105
|
+
/** The number of units in the whole population, `n`. It is a whole number, and it is not less than the sample. */
|
|
1106
|
+
readonly population: number;
|
|
1107
|
+
/** The method of the interval. The methods `"conservative"` and `"auto"` need `range`. */
|
|
1108
|
+
readonly method: UStatisticMethod;
|
|
1109
|
+
/** The level of the interval. The default is 0.95. */
|
|
1110
|
+
readonly level?: number;
|
|
1111
|
+
/** The smallest and the largest value of the kernel. With it, the interval stays in this range. */
|
|
1112
|
+
readonly range?: readonly [low: number, high: number];
|
|
1113
|
+
}
|
|
1114
|
+
/** The mean of the kernel over all the sets of `r` units of the population, with its interval. */
|
|
1115
|
+
interface UStatisticMean {
|
|
1116
|
+
/** The U-statistic: the mean of the kernel over the sets of `r` units of the sample. */
|
|
1117
|
+
readonly estimate: number;
|
|
1118
|
+
readonly low: number;
|
|
1119
|
+
readonly high: number;
|
|
1120
|
+
}
|
|
1121
|
+
/** The result of `uStatisticInterval`. The total is the mean of the kernel times `subsets`. */
|
|
1122
|
+
interface UStatisticInterval {
|
|
1123
|
+
/** The estimate of the total of the population: `S * C(n, r) / C(m, r)`, with `S` the total of the sample. */
|
|
1124
|
+
readonly estimate: number;
|
|
1125
|
+
readonly low: number;
|
|
1126
|
+
readonly high: number;
|
|
1127
|
+
readonly level: number;
|
|
1128
|
+
/** The method that made the interval. It is not `requested` after a fallback or a choice of the method `"auto"`. */
|
|
1129
|
+
readonly method: "conservative" | "tight";
|
|
1130
|
+
/** The method of the options. */
|
|
1131
|
+
readonly requested: UStatisticMethod;
|
|
1132
|
+
/** The mean of the kernel, with its interval. */
|
|
1133
|
+
readonly mean: UStatisticMean;
|
|
1134
|
+
/** The number of sets of `r` units in the population, `C(n, r)`. */
|
|
1135
|
+
readonly subsets: number;
|
|
1136
|
+
/** The standard error of the total. Only an interval of the method `"tight"` has it. */
|
|
1137
|
+
readonly standardError?: number;
|
|
1138
|
+
/** The degrees of freedom of the t quantile, `m - 1`. Only an interval of the method `"tight"` has it. */
|
|
1139
|
+
readonly df?: number;
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* This function gives the interval of a total over all the sets of `r` units of a population. The data is a uniform
|
|
1143
|
+
* sample of `m` of the `n` units, without replacement. An example is the count of crossings between all pairs of
|
|
1144
|
+
* routes. The input is the total of each sampled unit: the sum of the kernel over the sets of `r` sampled units
|
|
1145
|
+
* that hold the unit. Thus the sum of the totals is `r * S`, with `S` the total of the sample. The kernel is
|
|
1146
|
+
* symmetric.
|
|
1147
|
+
*
|
|
1148
|
+
* The estimate is `S * C(n, r) / C(m, r)`. It is the U-statistic `U = S / C(m, r)` times `C(n, r)`. At `r = 1`,
|
|
1149
|
+
* the estimate is `n / m` times the sum of the sample. When `m` is `n`, the interval is the estimate.
|
|
1150
|
+
*
|
|
1151
|
+
* The method `"conservative"` uses the inequality of Hoeffding (1963) for U-statistics, with `k = floor(m / r)`. The
|
|
1152
|
+
* half width of the mean is `(b - a) * sqrt(ln(2 / (1 - level)) / (2 k))`, with `[a, b]` the range of the kernel.
|
|
1153
|
+
* The bound is also true for a sample without replacement (Ai, Kuželka and Wang 2022, Blanc 2023 Theorem 6).
|
|
1154
|
+
* Thus the interval holds at each `m`. It is wide at a small `m`.
|
|
1155
|
+
*
|
|
1156
|
+
* The method `"tight"` uses the jackknife variance of `U`, from the totals only, times the finite population
|
|
1157
|
+
* correction `1 - m / n`. The interval is `U` plus or minus the t quantile with `m - 1` degrees of freedom, times
|
|
1158
|
+
* the standard error.
|
|
1159
|
+
*
|
|
1160
|
+
* The correction comes from the inclusion probabilities of a sample without replacement. The variance of the linear
|
|
1161
|
+
* part of `U` (its Hájek projection) gets exactly the factor `1 - m / n`. The variance of the remainder gets a
|
|
1162
|
+
* smaller factor, near `(1 - m / n)^2`, relative to an independent sample. For `r = 2` this factor is
|
|
1163
|
+
* `(n - m)(n - m - 1) / ((n - 2)(n - 3))`. Thus this estimate of the variance is exact for a linear kernel, and
|
|
1164
|
+
* larger than the variance for other kernels. The tests read the two facts over all samples of small populations.
|
|
1165
|
+
*
|
|
1166
|
+
* The method `"tight"` does not give an interval of width 0 when `m` is less than `n`. When all the totals are
|
|
1167
|
+
* equal, the jackknife variance is 0. Then the function uses the method `"conservative"` for the sample, and the
|
|
1168
|
+
* result has `method: "conservative"`. Without `range`, the function throws a `RangeError` for this sample.
|
|
1169
|
+
*
|
|
1170
|
+
* The method `"tight"` has no proof of its coverage. The tests use 200 samples of made-up populations at the level
|
|
1171
|
+
* 0.95. The table gives the hits of 200 for each population `n` and sample `m`. Each count includes the fallback.
|
|
1172
|
+
*
|
|
1173
|
+
* | n / m | sparse | crossings | skewed |
|
|
1174
|
+
* | --- | --- | --- | --- |
|
|
1175
|
+
* | 40 / 8 | 200 | 200 | 183 |
|
|
1176
|
+
* | 40 / 10 | 200 | 200 | 187 |
|
|
1177
|
+
* | 40 / 12 | 200 | 183 | 189 |
|
|
1178
|
+
* | 40 / 20 | 180 | 183 | 188 |
|
|
1179
|
+
* | 40 / 36 | 192 | 189 | 193 |
|
|
1180
|
+
* | 60 / 8 | 200 | 200 | 181 |
|
|
1181
|
+
* | 60 / 10 | 200 | 200 | 180 |
|
|
1182
|
+
* | 60 / 12 | 200 | 195 | 186 |
|
|
1183
|
+
* | 60 / 20 | 184 | 190 | 183 |
|
|
1184
|
+
* | 60 / 40 | 186 | 193 | 180 |
|
|
1185
|
+
* | 120 / 8 | 200 | 200 | 177 |
|
|
1186
|
+
* | 120 / 10 | 200 | 192 | 175 |
|
|
1187
|
+
* | 120 / 12 | 200 | 189 | 178 |
|
|
1188
|
+
* | 120 / 20 | 191 | 193 | 182 |
|
|
1189
|
+
* | 120 / 40 | 194 | 192 | 185 |
|
|
1190
|
+
* | 120 / 60 | 195 | 189 | 185 |
|
|
1191
|
+
* | 120 / 108 | 187 | 185 | 190 |
|
|
1192
|
+
*
|
|
1193
|
+
* The sparse kernel holds 2% to 3% of the pairs. The skewed kernel has a few large values. At `m = 8`, the skewed
|
|
1194
|
+
* kernel gets 177 to 183 of 200, a coverage of 0.885 to 0.915. No row has 190 or more in each kernel.
|
|
1195
|
+
*
|
|
1196
|
+
* The method `"auto"` needs `range`. It uses the method `"tight"` when `m` is `U_STATISTIC_TIGHT_MIN_SAMPLE` or more
|
|
1197
|
+
* and the variance is more than 0. Otherwise, it uses the method `"conservative"`.
|
|
1198
|
+
*
|
|
1199
|
+
* The rule for `U_STATISTIC_TIGHT_MIN_SAMPLE` is the smallest `m` of the table with 190 of 200 or more in each cell.
|
|
1200
|
+
* No `m` of the table obeys the rule. The last `m` with a count below 190 is 108, the largest `m` of the table. The
|
|
1201
|
+
* table has no larger `m`, so the constant is infinite. Thus the method `"auto"` uses the method `"conservative"` at
|
|
1202
|
+
* each `m` less than `n`.
|
|
1203
|
+
*
|
|
1204
|
+
* With `range`, the interval of the mean stays in `[a, b]`, and each total is in the range of a sum of
|
|
1205
|
+
* `C(m - 1, r - 1)` kernel values.
|
|
1206
|
+
*
|
|
1207
|
+
* @param totals - The total of each unit of the sample. The sample has more units than `r`.
|
|
1208
|
+
* @param options - The order, the population, the method, the level and the range of the kernel.
|
|
1209
|
+
* @returns The estimate and the interval of the total, and of the mean of the kernel.
|
|
1210
|
+
*/
|
|
1211
|
+
export declare function uStatisticInterval(totals: readonly number[], options: UStatisticOptions): UStatisticInterval;
|
|
1212
|
+
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, UStatisticInterval, UStatisticMean, UStatisticMethod, UStatisticOptions };
|
|
1094
1213
|
//# 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/agreement.ts","../src/rank.ts","../src/discrete.ts","../src/compare.ts","../src/power.ts"],"mappings":";;;;;;KAOY;;wBAmBI,OAAO;wBAIP,KAAK;;;;;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BASF,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"}
|
|
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","../src/u-statistic.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;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;KC9FzB;;;;;;qBAOC;;UAGI;;WAEN;;WAEA;;WAEA,QAAQ;;WAER;;WAEA,kBAAkB,aAAa;;;UAIzB;;WAEN;WACA;WACA;;;UAIM;;WAEN;WACA;WACA;WACA;;WAEA;;WAEA,WAAW;;WAEX,MAAM;;WAEN;;WAEA;;WAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyEK,mBAAmB,2BAA2B,SAAS,oBAAoB"}
|
package/build/index.js
CHANGED
|
@@ -303,7 +303,7 @@ function sides(values, against) {
|
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
305
|
/** The interval of the finite statistics of the runs. When no run is finite, low and high are equal to the estimate. */
|
|
306
|
-
function ends(values, estimate, s, seed) {
|
|
306
|
+
function ends$1(values, estimate, s, seed) {
|
|
307
307
|
const { runs, level } = s;
|
|
308
308
|
const p = sides(values, s.against);
|
|
309
309
|
if (values.length === 0) return {
|
|
@@ -341,7 +341,7 @@ function percentile(name, options, run, all) {
|
|
|
341
341
|
const v = run(r);
|
|
342
342
|
if (Number.isFinite(v)) values.push(v);
|
|
343
343
|
}
|
|
344
|
-
return ends(values, all(), s, r.seed);
|
|
344
|
+
return ends$1(values, all(), s, r.seed);
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
347
347
|
* The percentile bootstrap of `k` statistics from the same draws. Each run gives `k` statistics. Each statistic
|
|
@@ -356,7 +356,7 @@ function percentiles(name, options, k, run, all) {
|
|
|
356
356
|
for (let j = 0; j < k; j++) if (Number.isFinite(v[j])) values[j].push(v[j]);
|
|
357
357
|
}
|
|
358
358
|
const estimate = all();
|
|
359
|
-
return values.map((list, j) => ends(list, estimate[j], s, r.seed));
|
|
359
|
+
return values.map((list, j) => ends$1(list, estimate[j], s, r.seed));
|
|
360
360
|
}
|
|
361
361
|
/** A bootstrap interval of the median. */
|
|
362
362
|
function bootstrapMedian(values, options = {}) {
|
|
@@ -399,7 +399,7 @@ function bootstrapClusters(rows, cluster, statistic, options = {}) {
|
|
|
399
399
|
* The interval is narrow for a small sample. The draws give the variance of the sample with the divisor `m`, not
|
|
400
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
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%.
|
|
402
|
+
* the coverage agrees with 95%. For a total over the pairs of the items, use `uStatisticInterval`.
|
|
403
403
|
*/
|
|
404
404
|
function sampleTotalInterval(values, options) {
|
|
405
405
|
const name = "sampleTotalInterval";
|
|
@@ -2972,6 +2972,182 @@ function optionFloor(options) {
|
|
|
2972
2972
|
}
|
|
2973
2973
|
throw new RangeError(`optionFloor: no count under 10,000,000 for sigma ${sigma} and delta ${delta}.`);
|
|
2974
2974
|
}
|
|
2975
|
-
|
|
2975
|
+
// src/u-statistic.ts
|
|
2976
|
+
/**
|
|
2977
|
+
* The interval of a U-statistic from a uniform sample of `m` of `n` units, drawn without replacement. A kernel `h`
|
|
2978
|
+
* gives a value to each set of `r` units. The total of the population is the sum of `h` over all its sets of `r`.
|
|
2979
|
+
*/
|
|
2980
|
+
/**
|
|
2981
|
+
* The smallest sample `m` at which the method `"auto"` uses the method `"tight"`. The value comes from the pinned
|
|
2982
|
+
* counts of the tests. No measured `m` obeys the rule, so the value is infinite. The TSDoc of `uStatisticInterval`
|
|
2983
|
+
* gives the rule and the counts.
|
|
2984
|
+
*/
|
|
2985
|
+
const U_STATISTIC_TIGHT_MIN_SAMPLE = Number.POSITIVE_INFINITY;
|
|
2986
|
+
/**
|
|
2987
|
+
* This function gives the interval of a total over all the sets of `r` units of a population. The data is a uniform
|
|
2988
|
+
* sample of `m` of the `n` units, without replacement. An example is the count of crossings between all pairs of
|
|
2989
|
+
* routes. The input is the total of each sampled unit: the sum of the kernel over the sets of `r` sampled units
|
|
2990
|
+
* that hold the unit. Thus the sum of the totals is `r * S`, with `S` the total of the sample. The kernel is
|
|
2991
|
+
* symmetric.
|
|
2992
|
+
*
|
|
2993
|
+
* The estimate is `S * C(n, r) / C(m, r)`. It is the U-statistic `U = S / C(m, r)` times `C(n, r)`. At `r = 1`,
|
|
2994
|
+
* the estimate is `n / m` times the sum of the sample. When `m` is `n`, the interval is the estimate.
|
|
2995
|
+
*
|
|
2996
|
+
* The method `"conservative"` uses the inequality of Hoeffding (1963) for U-statistics, with `k = floor(m / r)`. The
|
|
2997
|
+
* half width of the mean is `(b - a) * sqrt(ln(2 / (1 - level)) / (2 k))`, with `[a, b]` the range of the kernel.
|
|
2998
|
+
* The bound is also true for a sample without replacement (Ai, Kuželka and Wang 2022, Blanc 2023 Theorem 6).
|
|
2999
|
+
* Thus the interval holds at each `m`. It is wide at a small `m`.
|
|
3000
|
+
*
|
|
3001
|
+
* The method `"tight"` uses the jackknife variance of `U`, from the totals only, times the finite population
|
|
3002
|
+
* correction `1 - m / n`. The interval is `U` plus or minus the t quantile with `m - 1` degrees of freedom, times
|
|
3003
|
+
* the standard error.
|
|
3004
|
+
*
|
|
3005
|
+
* The correction comes from the inclusion probabilities of a sample without replacement. The variance of the linear
|
|
3006
|
+
* part of `U` (its Hájek projection) gets exactly the factor `1 - m / n`. The variance of the remainder gets a
|
|
3007
|
+
* smaller factor, near `(1 - m / n)^2`, relative to an independent sample. For `r = 2` this factor is
|
|
3008
|
+
* `(n - m)(n - m - 1) / ((n - 2)(n - 3))`. Thus this estimate of the variance is exact for a linear kernel, and
|
|
3009
|
+
* larger than the variance for other kernels. The tests read the two facts over all samples of small populations.
|
|
3010
|
+
*
|
|
3011
|
+
* The method `"tight"` does not give an interval of width 0 when `m` is less than `n`. When all the totals are
|
|
3012
|
+
* equal, the jackknife variance is 0. Then the function uses the method `"conservative"` for the sample, and the
|
|
3013
|
+
* result has `method: "conservative"`. Without `range`, the function throws a `RangeError` for this sample.
|
|
3014
|
+
*
|
|
3015
|
+
* The method `"tight"` has no proof of its coverage. The tests use 200 samples of made-up populations at the level
|
|
3016
|
+
* 0.95. The table gives the hits of 200 for each population `n` and sample `m`. Each count includes the fallback.
|
|
3017
|
+
*
|
|
3018
|
+
* | n / m | sparse | crossings | skewed |
|
|
3019
|
+
* | --- | --- | --- | --- |
|
|
3020
|
+
* | 40 / 8 | 200 | 200 | 183 |
|
|
3021
|
+
* | 40 / 10 | 200 | 200 | 187 |
|
|
3022
|
+
* | 40 / 12 | 200 | 183 | 189 |
|
|
3023
|
+
* | 40 / 20 | 180 | 183 | 188 |
|
|
3024
|
+
* | 40 / 36 | 192 | 189 | 193 |
|
|
3025
|
+
* | 60 / 8 | 200 | 200 | 181 |
|
|
3026
|
+
* | 60 / 10 | 200 | 200 | 180 |
|
|
3027
|
+
* | 60 / 12 | 200 | 195 | 186 |
|
|
3028
|
+
* | 60 / 20 | 184 | 190 | 183 |
|
|
3029
|
+
* | 60 / 40 | 186 | 193 | 180 |
|
|
3030
|
+
* | 120 / 8 | 200 | 200 | 177 |
|
|
3031
|
+
* | 120 / 10 | 200 | 192 | 175 |
|
|
3032
|
+
* | 120 / 12 | 200 | 189 | 178 |
|
|
3033
|
+
* | 120 / 20 | 191 | 193 | 182 |
|
|
3034
|
+
* | 120 / 40 | 194 | 192 | 185 |
|
|
3035
|
+
* | 120 / 60 | 195 | 189 | 185 |
|
|
3036
|
+
* | 120 / 108 | 187 | 185 | 190 |
|
|
3037
|
+
*
|
|
3038
|
+
* The sparse kernel holds 2% to 3% of the pairs. The skewed kernel has a few large values. At `m = 8`, the skewed
|
|
3039
|
+
* kernel gets 177 to 183 of 200, a coverage of 0.885 to 0.915. No row has 190 or more in each kernel.
|
|
3040
|
+
*
|
|
3041
|
+
* The method `"auto"` needs `range`. It uses the method `"tight"` when `m` is `U_STATISTIC_TIGHT_MIN_SAMPLE` or more
|
|
3042
|
+
* and the variance is more than 0. Otherwise, it uses the method `"conservative"`.
|
|
3043
|
+
*
|
|
3044
|
+
* The rule for `U_STATISTIC_TIGHT_MIN_SAMPLE` is the smallest `m` of the table with 190 of 200 or more in each cell.
|
|
3045
|
+
* No `m` of the table obeys the rule. The last `m` with a count below 190 is 108, the largest `m` of the table. The
|
|
3046
|
+
* table has no larger `m`, so the constant is infinite. Thus the method `"auto"` uses the method `"conservative"` at
|
|
3047
|
+
* each `m` less than `n`.
|
|
3048
|
+
*
|
|
3049
|
+
* With `range`, the interval of the mean stays in `[a, b]`, and each total is in the range of a sum of
|
|
3050
|
+
* `C(m - 1, r - 1)` kernel values.
|
|
3051
|
+
*
|
|
3052
|
+
* @param totals - The total of each unit of the sample. The sample has more units than `r`.
|
|
3053
|
+
* @param options - The order, the population, the method, the level and the range of the kernel.
|
|
3054
|
+
* @returns The estimate and the interval of the total, and of the mean of the kernel.
|
|
3055
|
+
*/
|
|
3056
|
+
function uStatisticInterval(totals, options) {
|
|
3057
|
+
const name = "uStatisticInterval";
|
|
3058
|
+
const { order: r, population: n, method: requested } = options;
|
|
3059
|
+
const m = totals.length;
|
|
3060
|
+
const level = options.level ?? .95;
|
|
3061
|
+
if (!Number.isSafeInteger(r) || r < 1) throw new RangeError(`${name}: order is a whole number of 1 or more, not ${r}.`);
|
|
3062
|
+
if (m <= r) throw new RangeError(`${name}: the sample has more units than the order ${r}, not ${m}.`);
|
|
3063
|
+
if (!Number.isSafeInteger(n) || n < m) throw new RangeError(`${name}: population is a whole number of ${m} (the sample) or more, not ${n}.`);
|
|
3064
|
+
if (requested !== "conservative" && requested !== "tight" && requested !== "auto") throw new RangeError(`${name}: method is "conservative", "tight" or "auto", not ${String(requested)}.`);
|
|
3065
|
+
if (!(level > 0 && level < 1)) throw new RangeError(`${name}: level is more than 0 and less than 1, not ${level}.`);
|
|
3066
|
+
for (const t of totals) if (!Number.isFinite(t)) throw new RangeError(`${name}: each total is a finite number, not ${t}.`);
|
|
3067
|
+
const range = options.range;
|
|
3068
|
+
if (range !== void 0) {
|
|
3069
|
+
const [a, b] = range;
|
|
3070
|
+
if (!(Number.isFinite(a) && Number.isFinite(b) && a < b)) throw new RangeError(`${name}: range is two finite numbers a < b, not ${a} and ${b}.`);
|
|
3071
|
+
const sets = choose(m - 1, r - 1);
|
|
3072
|
+
const slack = 1e-9 * Math.max(Math.abs(a), Math.abs(b)) * sets;
|
|
3073
|
+
for (const t of totals) if (t < a * sets - slack || t > b * sets + slack) throw new RangeError(`${name}: each total is from ${a * sets} to ${b * sets} for this range, not ${t}.`);
|
|
3074
|
+
} else if (requested !== "tight") throw new RangeError(`${name}: the method "${requested}" needs the range of the kernel.`);
|
|
3075
|
+
let sum = 0;
|
|
3076
|
+
for (const t of totals) sum += t;
|
|
3077
|
+
const s = sum / r;
|
|
3078
|
+
const subsets = choose(n, r);
|
|
3079
|
+
const sampleSets = choose(m, r);
|
|
3080
|
+
const estimate = s * subsets / sampleSets;
|
|
3081
|
+
const u = s / sampleSets;
|
|
3082
|
+
const base = {
|
|
3083
|
+
estimate,
|
|
3084
|
+
level,
|
|
3085
|
+
requested,
|
|
3086
|
+
subsets
|
|
3087
|
+
};
|
|
3088
|
+
const centre = sum / m;
|
|
3089
|
+
let squares = 0;
|
|
3090
|
+
for (const t of totals) squares += (t - centre) ** 2;
|
|
3091
|
+
const variance = totals.every((t) => t === totals[0]) ? 0 : (1 - m / n) * ((m - 1) / m) * squares / choose(m - 1, r) ** 2;
|
|
3092
|
+
if (m === n) {
|
|
3093
|
+
const method = requested === "conservative" || requested === "auto" && m < U_STATISTIC_TIGHT_MIN_SAMPLE ? "conservative" : "tight";
|
|
3094
|
+
return {
|
|
3095
|
+
...base,
|
|
3096
|
+
low: estimate,
|
|
3097
|
+
high: estimate,
|
|
3098
|
+
method,
|
|
3099
|
+
mean: {
|
|
3100
|
+
estimate: u,
|
|
3101
|
+
low: u,
|
|
3102
|
+
high: u
|
|
3103
|
+
},
|
|
3104
|
+
...method === "tight" ? {
|
|
3105
|
+
standardError: 0,
|
|
3106
|
+
df: m - 1
|
|
3107
|
+
} : {}
|
|
3108
|
+
};
|
|
3109
|
+
}
|
|
3110
|
+
if ((requested === "tight" || requested === "auto" && m >= U_STATISTIC_TIGHT_MIN_SAMPLE) && variance > 0) {
|
|
3111
|
+
const df = m - 1;
|
|
3112
|
+
const se = Math.sqrt(variance);
|
|
3113
|
+
const half = tQuantile(1 - (1 - level) / 2, df) * se;
|
|
3114
|
+
return {
|
|
3115
|
+
...base,
|
|
3116
|
+
method: "tight",
|
|
3117
|
+
...ends(u, u - half, u + half, range, subsets),
|
|
3118
|
+
standardError: se * subsets,
|
|
3119
|
+
df
|
|
3120
|
+
};
|
|
3121
|
+
}
|
|
3122
|
+
if (range === void 0) throw new RangeError(`${name}: the jackknife variance is 0, because all the totals are equal. Give the range, or use the method "conservative".`);
|
|
3123
|
+
const k = Math.floor(m / r);
|
|
3124
|
+
const half = (range[1] - range[0]) * Math.sqrt(Math.log(2 / (1 - level)) / (2 * k));
|
|
3125
|
+
return {
|
|
3126
|
+
...base,
|
|
3127
|
+
method: "conservative",
|
|
3128
|
+
...ends(u, u - half, u + half, range, subsets)
|
|
3129
|
+
};
|
|
3130
|
+
}
|
|
3131
|
+
/** This function gives the interval of the mean in the range, if there is a range, and scales it to the total. */
|
|
3132
|
+
function ends(u, lowMean, highMean, range, subsets) {
|
|
3133
|
+
const low = range ? Math.max(range[0], lowMean) : lowMean;
|
|
3134
|
+
const high = range ? Math.min(range[1], highMean) : highMean;
|
|
3135
|
+
return {
|
|
3136
|
+
low: low * subsets,
|
|
3137
|
+
high: high * subsets,
|
|
3138
|
+
mean: {
|
|
3139
|
+
estimate: u,
|
|
3140
|
+
low,
|
|
3141
|
+
high
|
|
3142
|
+
}
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
/** The binomial coefficient `C(n, k)`, as a product. Each step is a whole number, so it is exact below 2^53. */
|
|
3146
|
+
function choose(n, k) {
|
|
3147
|
+
let c = 1;
|
|
3148
|
+
for (let j = 0; j < k; j++) c = c * (n - j) / (j + 1);
|
|
3149
|
+
return c;
|
|
3150
|
+
}
|
|
3151
|
+
export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, U_STATISTIC_TIGHT_MIN_SAMPLE, 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, uStatisticInterval, whenHolds, wilson, wilsonSampleSize };
|
|
2976
3152
|
|
|
2977
3153
|
//# sourceMappingURL=index.js.map
|