@mark1russell7/rigor-statistics 0.1.21 → 0.1.22

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
@@ -1,6 +1,6 @@
1
1
  # @mark1russell7/rigor-statistics
2
2
 
3
- The statistics of measured work. It gives quantiles, bootstrap intervals, the sign test, the paired permutation test, Wilson intervals and the Holm correction. It gives the interval of a median from order statistics, and the central interval of a binomial count. It also gives least squares, rank correlation, the comparison with a baseline beyond the noise, and the Brier score and the log-loss of predictions. It rates items from pairwise results with Elo, Glicko-2 and a Bradley-Terry fit. It fits response records that a browser can evaluate from plain JSON.
3
+ The statistics of measured work. It gives quantiles, bootstrap intervals, the sign test, the paired permutation test, Wilson intervals and the Holm correction. It gives the interval of a median from order statistics, and the central interval of a binomial count. It also gives least squares, rank correlation, the comparison with a baseline beyond the noise, and the Brier score and the log-loss of predictions. It rates items from pairwise results with Elo, Glicko-2 and a Bradley-Terry fit. It fits response records that a browser can evaluate from plain JSON, and it gives the Sobol indices of their models.
4
4
 
5
5
  ```sh
6
6
  npm install @mark1russell7/rigor-statistics
@@ -100,6 +100,28 @@ A measure with `null` has no value. To tell why, declare the reasons in the fiel
100
100
 
101
101
  The default expansion has one product for each pair of levels of two dimensions. Two dimensions with 76 and 33 levels thus give 2508 products, and the limit `RESPONSE_MAX_TERMS` refuses them. With the option `interactions: "seen"`, a ridge fit keeps only the terms that are not 0 at one point or more. This choice looks only at the inputs of the points. A term with no point has the weight 0, so the choice does not change a prediction. The limit applies after the choice.
102
102
 
103
+ ### The Sobol indices of a model
104
+
105
+ `sobolIndices(record, measure, options)` tells how much of the variance of a fitted model comes from each dimension. The first-order index `first` is the share of one dimension alone. The total index `total` also includes its interactions.
106
+
107
+ ```ts
108
+ import { sobolIndices } from "@mark1russell7/rigor-statistics";
109
+
110
+ const sobol = sobolIndices(record, "ms", { n: 4096, seed: 1 });
111
+ sobol.indices; // [{ dimension: "size", first: 0.71, total: 0.74 }, ...]
112
+ sobol.variance; // the variance of the prediction over the input distribution
113
+ sobol.evaluations; // n * (dimensions + 2) evaluations of the model
114
+ ```
115
+
116
+ - Each dimension is independent and uniform over its range or its levels. A dimension with `log` is uniform in log space.
117
+ - A conditional dimension gets an independent draw. The model gets `null` for it where `whenHolds` fails.
118
+ - The method is Monte Carlo with the matrices A, B and AB_i of Saltelli (2010). The first-order index uses the estimator of Saltelli (2010), and the total index uses the estimator of Jansen (1999).
119
+ - A constant model has the variance 0. Then each index is 0, not NaN.
120
+ - The option `scale: "model"` gives the indices on the scale of the model, for example the logarithm of a measure with a log scale.
121
+ - The option `interval` adds a percentile bootstrap interval over the N rows to each index.
122
+
123
+ A test examines models with known indices. At N = 16384, the root mean square error of an index is approximately 0.01.
124
+
103
125
  ## Rate items from pairwise results
104
126
 
105
127
  A pairwise result is a comparison of two items: the first item wins, the second item wins, or a tie. Each function of this section is pure, so a log of results gives the same ratings each time.
@@ -179,6 +201,7 @@ logLoss([{ p: p.a, hit: true }]); // the probability of the obser
179
201
  | `parseResponseRecord(value)` | The examination of unknown data. It gives the record, or one fault with a path for each error. |
180
202
  | `predictResponse(model, inputs)`, `heldOutError(record, measure)` | The value of a model at one set of inputs, and the error of the folds of a measure. |
181
203
  | `heldOutErrorAt(record, measure, ids)` | The held-out error of a chosen set of points, from the predictions of the option `outOfFold`. |
204
+ | `sobolIndices(record, measure, options)` | The first-order and the total Sobol index of each dimension, for the model of a measure. The default N is 4096. |
182
205
  | `responseCells(record, vary, steps)` | The number of fitted places of a view, level axes included. It lets a caller bound the time of a view before the view starts. |
183
206
  | `whenHolds(dimension, values)` | True when a place has the condition of a dimension. A dimension with no `when` is always present. |
184
207
  | `sliceResponse(record, measure, options)`, `surfaceResponse(record, measure, options)` | A fitted curve over one dimension, or a fitted surface over two, with the matching measured points, the matching points with no value, a band and the distance to the nearest measurement. |
package/build/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import "@mark1russell7/rigor-generators";
1
2
  /**
2
3
  * The descriptive statistics: the mean, the standard deviation, the median, the quantiles and a summary of a list.
3
4
  * Each function throws a RangeError for an empty list or for a value that is NaN. Thus a missing value cannot make a
@@ -757,6 +758,86 @@ export declare const RESPONSE_MAX_TERMS = 1024;
757
758
  * or less on a log scale with no `logFloor`. It throws for more than `RESPONSE_MAX_TERMS` terms.
758
759
  */
759
760
  export declare function fitResponse(data: ResponseData, options?: ResponseFitOptions): ResponseRecord;
761
+ /** The options of `sobolIndices`. */
762
+ interface SobolOptions {
763
+ /** The number N of rows of each base matrix. The default is 4096. */
764
+ readonly n?: number;
765
+ /** The seed of the draws. The default is 1. */
766
+ readonly seed?: number | string;
767
+ /**
768
+ * The scale of the output. The value `measure` uses `predictResponse`. The value `model` uses the scale of the
769
+ * model, so a model with a log scale gives the indices of the logarithm. The default is `measure`.
770
+ */
771
+ readonly scale?: "measure" | "model";
772
+ /**
773
+ * With this option, each index also gets a percentile bootstrap interval over the N rows. Each run draws N rows
774
+ * with replacement, and it calculates all the indices from these rows. The default is no interval.
775
+ */
776
+ readonly interval?: BootstrapOptions;
777
+ }
778
+ /** The two Sobol indices of one dimension. */
779
+ interface SobolIndex {
780
+ /** The id of the dimension. */
781
+ readonly dimension: string;
782
+ /** The first-order index S_i: the estimator of Saltelli (2010). */
783
+ readonly first: number;
784
+ /** The total index ST_i: the estimator of Jansen (1999). */
785
+ readonly total: number;
786
+ /** The bootstrap interval of `first`. Only the option `interval` writes this field. */
787
+ readonly firstInterval?: Interval;
788
+ /** The bootstrap interval of `total`. Only the option `interval` writes this field. */
789
+ readonly totalInterval?: Interval;
790
+ }
791
+ /** The result of `sobolIndices`. */
792
+ interface SobolIndices {
793
+ /** The id of the measure. */
794
+ readonly measure: string;
795
+ /** The scale of the output. */
796
+ readonly scale: "measure" | "model";
797
+ /** The number N of rows of each base matrix. */
798
+ readonly n: number;
799
+ /** The number of model evaluations: N * (d + 2). */
800
+ readonly evaluations: number;
801
+ /** The seed as a 32-bit number. */
802
+ readonly seed: number;
803
+ /** The mean of the outputs of A and B. */
804
+ readonly mean: number;
805
+ /** The variance of the outputs of A and B, with the divisor 2N. */
806
+ readonly variance: number;
807
+ /** The indices of each dimension of the record, in the order of the record. */
808
+ readonly indices: readonly SobolIndex[];
809
+ }
810
+ /**
811
+ * This function gives the first-order and the total Sobol index of each dimension of a record, for the model of
812
+ * `measure`. The indices are of the prediction of the model, not of the measured points.
813
+ *
814
+ * The input distribution:
815
+ * - Each dimension is independent of the other dimensions.
816
+ * - A continuous dimension is uniform over its range. With `log`, the logarithm of the value is uniform.
817
+ * - An ordinal or a categorical dimension is uniform over its levels.
818
+ * - A conditional dimension gets an independent draw. The model gets `null` for it where `whenHolds` fails for the drawn parent.
819
+ *
820
+ * Thus the inputs stay independent, and the indices have their usual meaning. A parent gets the effect of the absence of its child.
821
+ *
822
+ * The estimators:
823
+ * - The first-order index is `mean(f(B) * (f(AB_i) - f(A))) / V` (Saltelli, 2010).
824
+ * - The total index is `mean((f(A) - f(AB_i)) ** 2) / 2 / V` (Jansen, 1999).
825
+ * - V is the variance of the outputs of A and B together.
826
+ * - The variance uses the outputs of A and B less their mean. The first-order sum uses `f(B)` less that mean.
827
+ * - The total sum uses differences of outputs, so it uses no mean.
828
+ * - This step keeps the estimators unbiased, and it decreases their error when the mean is large.
829
+ *
830
+ * A model with a constant output has the variance 0. Then each index is 0, not NaN. An estimate can be a little
831
+ * below 0 or above 1, from the Monte Carlo error. The function does not clip it.
832
+ *
833
+ * The draws fill A row by row, then B row by row. Each row has one draw for each dimension, in the order of the
834
+ * record. Thus the same seed gives the same indices. The model can ignore a dimension. Then that dimension gets 0 for both
835
+ * indices exactly, unless it is the parent of a dimension that the model reads.
836
+ *
837
+ * The function throws a RangeError when the record has no model of `measure`, and when N is not a whole number of 2 or more.
838
+ * `predictResponse` throws for a value that the model refuses, for example a level that the model does not know.
839
+ */
840
+ export declare function sobolIndices(record: Pick<ResponseRecord, "dimensions" | "models">, measure: string, options?: SobolOptions): SobolIndices;
760
841
  /**
761
842
  * The sign test of paired results: `better` inputs where the candidate wins and `worse` where it loses. The ties
762
843
  * do not count. One-sided (the default), it is the p of `better` wins or more if the two are equal. Two-sided, it is
@@ -1473,5 +1554,5 @@ interface BradleyTerryFit {
1473
1554
  * outcome, a bad weight and a bad option.
1474
1555
  */
1475
1556
  export declare function bradleyTerry(items: number, comparisons: readonly PairComparison[], options?: BradleyTerryOptions): BradleyTerryFit;
1476
- export type { BinomialSide, BootstrapOptions, BradleyTerryFit, BradleyTerryOptions, CalibrationLevel, CategoricalDimension, CompareOptions, Comparison, ContinuousDimension, Corrected, CountInterval, CoverageBar, CoverageCell, CoverageMinSample, CoverageReason, CoverageStep, Effect, EloOptions, EloUpdate, Forecast, Glicko2Game, Glicko2Options, Glicko2Rating, Interval, Kappa, LeastSquaresFit, LeastSquaresOptions, MedianInterval, ModeOptions, NoiseOptions, NoiseState, NoiseVerdict, OptionFloorOptions, OrdinalDimension, PairComparison, PairOutcome, PairProbabilities, ParsedResponseRecord, PermutationOptions, PermutationResult, Proportion, QuantileInterval, QuantileMethod, RatingScale, ResponseAbsentPoint, ResponseBand, ResponseCurvePoint, ResponseData, ResponseDimension, ResponseDimensionBase, ResponseFactor, ResponseFault, ResponseFitOptions, ResponseFold, ResponseFoldError, ResponseHeldOutError, ResponseInputValue, ResponseMeasure, ResponseModel, ResponseModelBase, ResponsePoint, ResponseReason, ResponseRecord, ResponseSlice, ResponseSliceOptions, ResponseSlicePoint, ResponseSurface, ResponseSurfaceAbsentPoint, ResponseSurfaceOptions, ResponseSurfacePoint, ResponseTableCell, ResponseValue, ResponseViewOptions, ResponseWhen, RidgeInput, RidgeInputBase, RidgeLevelInput, RidgeNumberInput, RidgeOptions, RidgeRankInput, RidgeResponseModel, RidgeTerm, SampleTotalOptions, SideP, SmoothLaw, SmoothLawScore, Summary, TableResponseModel, TieModel, TwoSamplePermutationOptions, TwoSamplePermutationResult, UStatisticInterval, UStatisticMean, UStatisticMethod, UStatisticOptions };
1557
+ export type { BinomialSide, BootstrapOptions, BradleyTerryFit, BradleyTerryOptions, CalibrationLevel, CategoricalDimension, CompareOptions, Comparison, ContinuousDimension, Corrected, CountInterval, CoverageBar, CoverageCell, CoverageMinSample, CoverageReason, CoverageStep, Effect, EloOptions, EloUpdate, Forecast, Glicko2Game, Glicko2Options, Glicko2Rating, Interval, Kappa, LeastSquaresFit, LeastSquaresOptions, MedianInterval, ModeOptions, NoiseOptions, NoiseState, NoiseVerdict, OptionFloorOptions, OrdinalDimension, PairComparison, PairOutcome, PairProbabilities, ParsedResponseRecord, PermutationOptions, PermutationResult, Proportion, QuantileInterval, QuantileMethod, RatingScale, ResponseAbsentPoint, ResponseBand, ResponseCurvePoint, ResponseData, ResponseDimension, ResponseDimensionBase, ResponseFactor, ResponseFault, ResponseFitOptions, ResponseFold, ResponseFoldError, ResponseHeldOutError, ResponseInputValue, ResponseMeasure, ResponseModel, ResponseModelBase, ResponsePoint, ResponseReason, ResponseRecord, ResponseSlice, ResponseSliceOptions, ResponseSlicePoint, ResponseSurface, ResponseSurfaceAbsentPoint, ResponseSurfaceOptions, ResponseSurfacePoint, ResponseTableCell, ResponseValue, ResponseViewOptions, ResponseWhen, RidgeInput, RidgeInputBase, RidgeLevelInput, RidgeNumberInput, RidgeOptions, RidgeRankInput, RidgeResponseModel, RidgeTerm, SampleTotalOptions, SideP, SmoothLaw, SmoothLawScore, SobolIndex, SobolIndices, SobolOptions, Summary, TableResponseModel, TieModel, TwoSamplePermutationOptions, TwoSamplePermutationResult, UStatisticInterval, UStatisticMean, UStatisticMethod, UStatisticOptions };
1477
1558
  //# 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/agreement.ts","../src/rank.ts","../src/discrete.ts","../src/compare.ts","../src/power.ts","../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;;;;;;;;;;;;;;;;;;;;;;;wBAmFK,mBAAmB,2BAA2B,SAAS,oBAAoB;;;;;;;UCrI1E;;WAEN;;WAEA;;WAEA;;;UAIM,mBAAmB;;WAEzB;;;UAIM;;WAEN;;WAEA;;WAEA;;;;;;wBAyBK,YAAY,YAAY,YAAY,UAAS;;;;;;wBAY7C,UAAU,YAAY,YAAY,eAAe,UAAS,aAAkB;;UAU3E;WACN;;WAEA;;WAEA;;;UAIM;WACN;WACA;;WAEA;;;UAIM;;WAEN;;WAEA;;;;;;;wBAmBK,cAAc,QAAQ,eAAe,gBAAgB,eAAe,UAAS,iBAAsB;;;;;wBAuEnG,YAAY,QAAQ,gBAAgB;;UAQnC;;WAEN;;WAEA;;WAEA;;;;;;;wBAuBK,kBAAkB,YAAY,YAAY,eAAU;;;;;wBAWpD,iBAAiB,kBAAkB,UAAS;;wBAO5C,iBAAiB,gBAAgB,UAAS;;KCtO9C;;UAGK;WACN;WACA;WACA,SAAS;;WAET;;;KAIC;;UAGK;;WAEN;;WAEA;;;;;WAKA,OAAO;;;;;WAKP;;WAEA;;WAEA;;;UAIM;;WAEN;;;;;WAKA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;wBA6CK,aAAa,eAAe,sBAAsB,kBAAkB,UAAS,sBAA2B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/describe.ts","../src/regression.ts","../src/bootstrap.ts","../src/distribution.ts","../src/ridge.ts","../src/response.ts","../src/response-parse.ts","../src/response-fit.ts","../src/response-sobol.ts","../src/tests.ts","../src/agreement.ts","../src/rank.ts","../src/discrete.ts","../src/compare.ts","../src/power.ts","../src/coverage.ts","../src/u-statistic.ts","../src/rating.ts","../src/bradley-terry.ts"],"mappings":";;;;;;;KAOY;;wBAmBI,OAAO;wBAIP,KAAK;;;;;wBAgBL,GAAG;;;;;;;wBAgBH,eAAe,iCAAiC,WAAW,SAAQ;;wBAkBnE,SAAS,2BAA2B,WAAW,SAAQ;;;;;wBASvD,OAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAmFK,mBAAmB,2BAA2B,SAAS,oBAAoB;;;;;;;UCrI1E;;WAEN;;WAEA;;WAEA;;;UAIM,mBAAmB;;WAEzB;;;UAIM;;WAEN;;WAEA;;WAEA;;;;;;wBAyBK,YAAY,YAAY,YAAY,UAAS;;;;;;wBAY7C,UAAU,YAAY,YAAY,eAAe,UAAS,aAAkB;;UAU3E;WACN;;WAEA;;WAEA;;;UAIM;WACN;WACA;;WAEA;;;UAIM;;WAEN;;WAEA;;;;;;;wBAmBK,cAAc,QAAQ,eAAe,gBAAgB,eAAe,UAAS,iBAAsB;;;;;wBAuEnG,YAAY,QAAQ,gBAAgB;;UAQnC;;WAEN;;WAEA;;WAEA;;;;;;;wBAuBK,kBAAkB,YAAY,YAAY,eAAU;;;;;wBAWpD,iBAAiB,kBAAkB,UAAS;;wBAO5C,iBAAiB,gBAAgB,UAAS;;KCtO9C;;UAGK;WACN;WACA;WACA,SAAS;;WAET;;;KAIC;;UAGK;;WAEN;;WAEA;;;;;WAKA,OAAO;;;;;WAKP;;WAEA;;WAEA;;;UAIM;;WAEN;;;;;WAKA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;wBA6CK,aAAa,eAAe,sBAAsB,kBAAkB,UAAS,sBAA2B"}
package/build/index.js CHANGED
@@ -2242,6 +2242,168 @@ function fitResponse(data, options = {}) {
2242
2242
  folds: foldRecords
2243
2243
  };
2244
2244
  }
2245
+ // src/response-sobol.ts
2246
+ /**
2247
+ * The Sobol indices of a fitted model of a record of the format `response-records/1`. The first-order index of a
2248
+ * dimension is the share of the variance of the prediction that the dimension causes alone. The total index also
2249
+ * includes each interaction of the dimension with the other dimensions.
2250
+ *
2251
+ * The method is Monte Carlo with two independent matrices A and B of N rows, and one matrix `AB_i` for each dimension `i`.
2252
+ * `AB_i` is A with the column `i` of B (Saltelli and others, 2010). The first-order index uses the estimator of Saltelli
2253
+ * (2010), and the total index uses the estimator of Jansen (1999). The model gets N * (d + 2) evaluations for d dimensions.
2254
+ *
2255
+ * This file uses no Node import, no clock and no `Math.random`, the same as `response.ts`.
2256
+ */
2257
+ /** This function draws one value of a dimension. Each dimension uses the same number of draws: one. */
2258
+ function drawValue(dimension, r) {
2259
+ if (dimension.kind !== "continuous") return dimension.levels[r.below(dimension.levels.length)];
2260
+ const [low, high] = dimension.range;
2261
+ if (dimension.log !== true) return r.range(low, high);
2262
+ const value = 10 ** r.range(Math.log10(low), Math.log10(high));
2263
+ return Math.min(high, Math.max(low, value));
2264
+ }
2265
+ /** This function draws a matrix of `n` rows, row by row, with one draw for each dimension in the order of the record. */
2266
+ function drawMatrix(dimensions, n, r) {
2267
+ return Array.from({ length: n }, () => dimensions.map((d) => drawValue(d, r)));
2268
+ }
2269
+ /** This function gives the inputs of a row. A conditional dimension gets `null` where its condition fails. */
2270
+ function inputsOf(dimensions, row) {
2271
+ const drawn = {};
2272
+ dimensions.forEach((d, i) => {
2273
+ drawn[d.id] = row[i];
2274
+ });
2275
+ const inputs = {};
2276
+ for (const d of dimensions) inputs[d.id] = whenHolds(d, drawn) ? drawn[d.id] : null;
2277
+ return inputs;
2278
+ }
2279
+ /**
2280
+ * This function gives the variance and the indices from the rows `rows`. A variance of 0 gives each index as 0.
2281
+ * The value `constant` is true when each output is equal to the first output.
2282
+ */
2283
+ function estimate(outputs, rows, n, constant) {
2284
+ const d = outputs.ab.length;
2285
+ const at = (j) => rows === null ? j : rows[j];
2286
+ let sum = 0;
2287
+ for (let j = 0; j < n; j++) sum += outputs.a[at(j)] + outputs.b[at(j)];
2288
+ const mean = sum / (2 * n);
2289
+ let square = 0;
2290
+ for (let j = 0; j < n; j++) {
2291
+ const ea = outputs.a[at(j)] - mean;
2292
+ const eb = outputs.b[at(j)] - mean;
2293
+ square += ea * ea + eb * eb;
2294
+ }
2295
+ const variance = constant ? 0 : square / (2 * n);
2296
+ const first = [];
2297
+ const total = [];
2298
+ for (let i = 0; i < d; i++) {
2299
+ const abi = outputs.ab[i];
2300
+ let s = 0;
2301
+ let t = 0;
2302
+ for (let j = 0; j < n; j++) {
2303
+ const fa = outputs.a[at(j)];
2304
+ const fb = outputs.b[at(j)];
2305
+ const fab = abi[at(j)];
2306
+ s += (fb - mean) * (fab - fa);
2307
+ t += (fa - fab) * (fa - fab);
2308
+ }
2309
+ first.push(variance > 0 ? s / n / variance : 0);
2310
+ total.push(variance > 0 ? t / (2 * n) / variance : 0);
2311
+ }
2312
+ return {
2313
+ mean,
2314
+ variance,
2315
+ first,
2316
+ total
2317
+ };
2318
+ }
2319
+ /**
2320
+ * This function gives the first-order and the total Sobol index of each dimension of a record, for the model of
2321
+ * `measure`. The indices are of the prediction of the model, not of the measured points.
2322
+ *
2323
+ * The input distribution:
2324
+ * - Each dimension is independent of the other dimensions.
2325
+ * - A continuous dimension is uniform over its range. With `log`, the logarithm of the value is uniform.
2326
+ * - An ordinal or a categorical dimension is uniform over its levels.
2327
+ * - A conditional dimension gets an independent draw. The model gets `null` for it where `whenHolds` fails for the drawn parent.
2328
+ *
2329
+ * Thus the inputs stay independent, and the indices have their usual meaning. A parent gets the effect of the absence of its child.
2330
+ *
2331
+ * The estimators:
2332
+ * - The first-order index is `mean(f(B) * (f(AB_i) - f(A))) / V` (Saltelli, 2010).
2333
+ * - The total index is `mean((f(A) - f(AB_i)) ** 2) / 2 / V` (Jansen, 1999).
2334
+ * - V is the variance of the outputs of A and B together.
2335
+ * - The variance uses the outputs of A and B less their mean. The first-order sum uses `f(B)` less that mean.
2336
+ * - The total sum uses differences of outputs, so it uses no mean.
2337
+ * - This step keeps the estimators unbiased, and it decreases their error when the mean is large.
2338
+ *
2339
+ * A model with a constant output has the variance 0. Then each index is 0, not NaN. An estimate can be a little
2340
+ * below 0 or above 1, from the Monte Carlo error. The function does not clip it.
2341
+ *
2342
+ * The draws fill A row by row, then B row by row. Each row has one draw for each dimension, in the order of the
2343
+ * record. Thus the same seed gives the same indices. The model can ignore a dimension. Then that dimension gets 0 for both
2344
+ * indices exactly, unless it is the parent of a dimension that the model reads.
2345
+ *
2346
+ * The function throws a RangeError when the record has no model of `measure`, and when N is not a whole number of 2 or more.
2347
+ * `predictResponse` throws for a value that the model refuses, for example a level that the model does not know.
2348
+ */
2349
+ function sobolIndices(record, measure, options = {}) {
2350
+ const model = record.models.find((m) => m.measure === measure);
2351
+ if (model === void 0) throw new RangeError(`sobolIndices: the record has no model of the measure "${measure}".`);
2352
+ const n = options.n ?? 4096;
2353
+ if (!Number.isSafeInteger(n) || n < 2) throw new RangeError(`sobolIndices: n is a whole number of 2 or more, not ${n}.`);
2354
+ const scale = options.scale ?? "measure";
2355
+ const dimensions = record.dimensions;
2356
+ const d = dimensions.length;
2357
+ const r = random(options.seed ?? 1);
2358
+ const a = drawMatrix(dimensions, n, r);
2359
+ const b = drawMatrix(dimensions, n, r);
2360
+ const f = (row) => {
2361
+ const inputs = inputsOf(dimensions, row);
2362
+ return scale === "model" ? predictScaled(model, inputs) : predictResponse(model, inputs);
2363
+ };
2364
+ const fa = Float64Array.from(a, f);
2365
+ const fb = Float64Array.from(b, f);
2366
+ const outputs = {
2367
+ a: fa,
2368
+ b: fb,
2369
+ ab: dimensions.map((_, i) => Float64Array.from(a, (row, j) => f(row.map((v, k) => k === i ? b[j][i] : v))))
2370
+ };
2371
+ const first = fa[0];
2372
+ const constant = fa.every((v) => v === first) && fb.every((v) => v === first);
2373
+ const all = estimate(outputs, null, n, constant);
2374
+ let intervals;
2375
+ if (options.interval !== void 0) {
2376
+ const rows = new Array(n);
2377
+ const flat = (e) => [...e.first, ...e.total];
2378
+ intervals = percentiles("sobolIndices", options.interval, 2 * d, (rr) => {
2379
+ for (let j = 0; j < n; j++) rows[j] = rr.below(n);
2380
+ return flat(estimate(outputs, rows, n, constant));
2381
+ }, () => flat(all));
2382
+ }
2383
+ const indices = dimensions.map((dimension, i) => {
2384
+ const index = {
2385
+ dimension: dimension.id,
2386
+ first: all.first[i],
2387
+ total: all.total[i]
2388
+ };
2389
+ if (intervals === void 0) return index;
2390
+ return {
2391
+ ...index,
2392
+ firstInterval: intervals[i],
2393
+ totalInterval: intervals[d + i]
2394
+ };
2395
+ });
2396
+ return {
2397
+ measure,
2398
+ scale,
2399
+ n,
2400
+ evaluations: n * (d + 2),
2401
+ seed: r.seed,
2402
+ mean: constant ? first : all.mean,
2403
+ variance: all.variance,
2404
+ indices
2405
+ };
2406
+ }
2245
2407
  // src/tests.ts
2246
2408
  /**
2247
2409
  * The tests of a difference: the sign test, the paired permutation test, the Wilson interval of a proportion and
@@ -3708,6 +3870,6 @@ function inverseDiagonal(hessian, k) {
3708
3870
  }
3709
3871
  return out;
3710
3872
  }
3711
- export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, U_STATISTIC_TIGHT_MIN_SAMPLE, Z95, bestSmoothLaw, binomialInterval, binomialTest, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapTwo, bradleyTerry, brier, calibration, cohenKappa, compareRatios, coverageMinSample, eloExpected, eloUpdate, fitResponse, glicko2Idle, glicko2Update, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, logLoss, mean, median, medianInterval, modeCount, negativeBinomialInterval, noiseFloor, noiseVerdict, optionFloor, pairProbabilities, pairedPermutation, parseResponseRecord, partialConjunction, predictResponse, quantile, quantileInterval, quantileSamples, quantileSorted, ranks, ratingToStrength, responseCells, ridgeSolve, sampleTotalInterval, sd, signTest, signTestPower, sliceResponse, smoothLawScores, sorted, spearman, strengthToRating, summarize, surfaceResponse, tQuantile, twoSamplePermutation, uStatisticInterval, whenHolds, wilson, wilsonSampleSize };
3873
+ export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, U_STATISTIC_TIGHT_MIN_SAMPLE, Z95, bestSmoothLaw, binomialInterval, binomialTest, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapTwo, bradleyTerry, brier, calibration, cohenKappa, compareRatios, coverageMinSample, eloExpected, eloUpdate, fitResponse, glicko2Idle, glicko2Update, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, logLoss, mean, median, medianInterval, modeCount, negativeBinomialInterval, noiseFloor, noiseVerdict, optionFloor, pairProbabilities, pairedPermutation, parseResponseRecord, partialConjunction, predictResponse, quantile, quantileInterval, quantileSamples, quantileSorted, ranks, ratingToStrength, responseCells, ridgeSolve, sampleTotalInterval, sd, signTest, signTestPower, sliceResponse, smoothLawScores, sobolIndices, sorted, spearman, strengthToRating, summarize, surfaceResponse, tQuantile, twoSamplePermutation, uStatisticInterval, whenHolds, wilson, wilsonSampleSize };
3712
3874
 
3713
3875
  //# sourceMappingURL=index.js.map