rStats.js v1.3.0
    Preparing search index...

    Function mcreg

    • Method comparison regression of y (test method) on x (reference method): Deming, weighted Deming or Passing-Bablok regression with analytical, jackknife or bootstrap intervals. Equivalent to mcr::mcreg() in R.

      • Deming ("Deming"): the slope minimises the squared distances in the metric of the error variances, λ = errorRatio = σ²(x)/σ²(y) (mcr's convention; λ → 0 gives the least-squares slope of y on x). The analytical standard errors are Strike's (1991), with t intervals on n - 2 degrees of freedom.
      • Weighted Deming ("WDeming"): Linnet's (1990) iteration for errors proportional to the level (constant coefficient of variation), stopped as mcr when both coefficients change by less than threshold (absolute), with a warning when iterMax iterations are reached. No analytical interval (jackknife by default). Values must be positive. Since the threshold is absolute, data of very large magnitude (around 1e150) may not converge and data of very small magnitude (around 1e-150) stop after the first iteration; choose threshold in the units of the data.
      • Passing-Bablok ("PaBa"): the shifted median of the n(n - 1)/2 pairwise slopes and the rank interval of Passing and Bablok (1983); the intercept is the median of y - b x and its limits those of the slope's limits. Differences below a relative 1e-12 count as ties (mcr's rule; a pair tied in x only is vertical), so data with a large offset (1e12 + O(1)) have most differences set to 0; the mean of two middle slopes is tan of the mean angle (slopeMeasure: "radian", mcr's default; it changes when y is rescaled, as angles do not scale) or the mean slope ("tangent"). Where the interval is not defined (too few points, always for n <= 4) its limits and the intercept's are -Infinity and Infinity, with a warning. Values must not be negative. The result has the CUSUM statistic of linearity (cusum; no test decision).
      • jackknife: the leave-one-out estimates, the standard error sd(pseudo-values)/sqrt(n) and the interval estimate ± t se on n - 2 degrees of freedom (Linnet 1993); the estimates are those of all the data.
      • bootstrap: nsamples resamples of the pairs with replacement; "quantile" the percentile interval, "Student" estimate ± t sd(B), "BCa" the bias-corrected and accelerated interval (jackknife acceleration), "tBoot" the bootstrap-t interval with the analytical standard errors (Deming) or, with "nestedbootstrap", the standard deviation of nnested inner resamples of each resample. Resamples with constant x or y are dropped with mcr's warning (an error when more than 5% are). The resamples are drawn as R's sample(1:n, n, replace = TRUE) from the current random stream, or from set.seed(rngSeed) as mcr's rng.seed (the generator's state is then restored if it had one), so the values are mcr's for the same seed. With very few points (n = 5) the bootstrap-t limits can be infinite or huge, because resamples of 2 or 3 distinct points have standard errors 0.

      Unlike mcr, the default interval is "analytical" ("jackknife" for weighted Deming) rather than a random bootstrap; confLevel replaces mcr's alpha (= 1 - confLevel); 2 or fewer points, constant x or y, infinite values and data whose Deming covariance is 0 are errors. Passing-Bablok's odd-position slopes are dy/dx (mcr: tan of its angle, a few ulps off). PaBaLarge, LinReg, WLinReg, PBequi and TS are not offered.

      Parameters

      Returns McregResult

      See McregResult.

      TypeError if x and y differ in length; RangeError for missing values without naRm, infinite values, fewer than 3 pairs, constant x or y, negative values (Passing-Bablok), values that are not positive (weighted Deming), more than 5793 points (Passing-Bablok), an analytical interval for weighted Deming, a bootstrap-t interval without nested resamples for Passing-Bablok or weighted Deming, too many degenerate resamples, a zero covariance (Deming), or an invalid option.

      const x = [1, 2, 3, 4, 5, 6, 7];
      const y = [1.2, 1.9, 3.2, 3.8, 5.1, 6.4, 6.6];
      const d = mcreg(x, y, { methodReg: "Deming" });
      d.slope.estimate; // 0.97547950725034482
      d.slope.confInt; // [0.83267195599246846, 1.1182870585082212]
      const pb = mcreg(x, y); // Passing-Bablok
      pb.slope.estimate; // 0.95
      pb.intercept.confInt; // [-0.8524794459077718, 0.80365513709218339]