| English | 日本語 |
rStats.js aims to return the same results as R. This page lists the cases where it does not,
either because R itself is inaccurate or fails there, or because rStats.js deliberately behaves
differently. In the tests these cases are marked knownDifference with a reason (see
test/helpers/suite.ts and the individual test files). How cases are compared is described in
accuracy.md.
When a test case does not match R, it is compared with a high-precision reference value computed with Rmpfr (256 to 1300 bits) or gmp (exact rationals). If rStats.js matches the reference, the case passes as “more accurate than R”.
pbeta, dbeta and pgamma can be off by
1e-13 to 1e-11. plnorm/dlnorm with, for example, meanlog = 700 and sdlog = 20 are off by
about 1e-13.pf switches to a chi-squared
approximation for df2 > 1e8 (relative error about 1e-9), and the non-central qt and
qchisq invert with low accuracy and are cut off in the tails. With ncp = 0, R’s F
distribution uses the non-central algorithm and loses accuracy (e.g.
pf(1e5, 4, 5, ncp = 0, lower.tail = FALSE) is off by 4e-5); rStats.js returns values as
accurate as the central distribution for ncp: 0 (edge cases follow R’s non-central
behaviour).dsignrank/psignrank are off by about 1e-14 for n = 500
and 1000; for n = 1100 the central dsignrank is Inf and psignrank(1000, 1100) is 0 (truth
2.27e-308). dwilcox(·, 200, 200) is off by 1.4e-14 throughout, and R 4.6’s dwilcox/pwilcox
(Löffler’s formula) by 1e-14 already at m = n = 49.ptukey is accurate to about 8 digits and qtukey to about 4;
upper tails below 1e-15 become 0. For large df (such as 1e5) R returns the df = ∞ value;
rStats.js computes the value for the given df.| Call | R | Truth (Rmpfr) | rStats.js |
|---|---|---|---|
dgamma(110000.00000000001, 1e5) |
2.4166502895221053e-207 | 2.4166502895188551e-207 | 2.416650289518855e-207 |
pgamma(1e-100, 3, lower.tail = FALSE, log.p = TRUE) |
-1.6666666666665175e-301 | -1.6666666666666667e-301 | -1.666666666666667e-301 |
pbeta(0.99, 1e5, 100) |
4.127552829240118e-296 | 4.1275528292396704e-296 | 4.1275528292396705e-296 |
pnbinom(1e5, 1e-10, 0.001, lower.tail = FALSE) |
3.5003255336351424e-56 | 3.5003255336350864e-56 | 3.500325533635079e-56 |
pnbinom(1e8, 10, mu = 1e6, lower.tail = FALSE, log.p = TRUE) |
-879.62 | -950.61809786317 | -950.6180978631712 |
phyper(0, 3, 1e6, 2, log.p = TRUE) |
-5.999993999861e-6 | -5.999994000011999976e-6 | same as truth |
ptukey(30, 3, 10, lower.tail = FALSE) |
2.880e-9 | 3.3124453334e-9 | same as truth |
ptukey(3, 1000, 10) |
0 | 1.3584e-5 | same as truth |
ptukey(0.5, 20, 2) |
0 | 3.427e-8 | same as truth |
qtukey(0.999, 3, 2) |
42.41 (ptukey of it gives 0.99797) |
60.418 | |
qtukey(-20, 10, 10, log.p = TRUE) |
4.05e-5 | 0.2084 | |
pchisq(1000, 5, ncp = 10, lower.tail = FALSE) |
1.64e-180 | 1.7925e-176 | same as truth |
pbeta(1 - 1e-10, 2, 3, ncp = 1, lower.tail = FALSE) |
1.7e-10 | 7.52e-30 | same as truth |
pt(-1, 5, ncp = 10) |
0 | 1.3248e-26 | same as truth |
pt(1, 5, ncp = 40) |
1.009e-303 | 1.0887e-287 | same as truth |
pt(1, 1e-300, ncp = 1e4) |
0 | 3.3623538933995988e-298 (mpmath) | 3.362353893399793e-298 |
pt(1, 10, ncp = 1e9, log.p = TRUE) |
-4.7619047526190466e17 | -4.5454545454545440e17 (Rmpfr) | same as truth |
dt(1, 10, ncp = 1e9, log = TRUE) |
-Inf | -4.5454545454545436e17 (Rmpfr) | same as truth |
qt(1e-300, 1e-300, ncp = 1e4) |
18961.503816218225 | 2.4637413705646497e-146 (mpmath) | 2.463741370564455e-146 |
qt(1e-300, 1e-100, ncp = 1e4) |
1.8961503816217974e104 | 3.3196830107614348e-48 (mpmath) | 3.3196830107614347e-48 |
qt(-1419.5258582683982, 2, ncp = 0.5, lower.tail = FALSE, log.p = TRUE) |
Inf | 1.7976931348623157e308 (P[T > t] = c/t², c = (1 + δ²) Φ(δ) + δ φ(δ)) | 1.7976931348622732e308 |
dchisq(1e4, 5, ncp = 10, log = TRUE) |
-2975.1 | -4688.08 | same as truth |
dchisq(1e-300, 0, ncp = 1), dchisq(1.5e-323, 0, ncp = 1) |
0 | 0.1516 | same as truth |
dchisq(1.5e-323, 2e-323, ncp = 1) (subnormal x and df) |
0.6065306597126334 | 0.55598643806991397 (Rmpfr) | 0.5559864380699139 |
df(1e10, 5, Inf, ncp = 0, log = TRUE) |
-1.25e11 | -2.5e10 | same as truth |
qchisq(-1e10, 5, ncp = 1, lower.tail = FALSE, log.p = TRUE) |
2.29e10 | 2.00e10 (checked with the distribution function) | same as truth |
dbeta(1.05e-231, 0.194, 141.1, ncp = 1.39e-303) (a noncentral density at a tiny ncp) |
9.3999238814454927e185 | 9.399923881445698e185 (mpmath) | same as truth (the central density) |
df(2.86e-257, 0.0275, 3, ncp = 5e-324) |
1.3617011778446392e251 | 1.3617011778446561e251 (mpmath) | 1.3617011778446567e251 (the central density) |
df(1e100, 1e-200, 1e200, ncp = 1, log = TRUE) (df1/df2 underflows) |
Inf | -462.40331295992905 (the χ² limit, R’s dchisq) | same as truth |
pf(1e290, 1, 1e290, ncp = 1, lower.tail = FALSE, log.p = TRUE), df(..., log = TRUE) (m q comparable to n beyond 1e290) |
-Inf, NaN | -3.4657359027997265e289 (−n log(2)/2 to leading order; the central F’s value) | -3.4657359027997267e289, the same |
df(5e299, 2, 1e308, ncp = 1e300) (a huge df2 with a huge noncentrality; issue #202) |
NaN | about 3.98942279e-151 (the noncentral χ² limit 1e-150 / sqrt(2π) less the relative 2.5e-9 of χ²_df2/df2’s spread) | 3.9894228040144464e-151 (the noncentral χ² limit, taken where pf takes it; before: 0) |
qf(1.89e-13, 0.0885, 6.01e302) |
4.6113445353195029e-287 | 4.6113445353197333e-287 (mpmath, the χ² limit) | 4.611344535319733e-287 |
pbeta(0.973, 0.130, 8.15e-322, log.p = TRUE) |
-736.93128475074695 | -736.93155014878607 (mpmath) | same as truth |
dchisq(1.005e-308, 294.4, ncp = 2.91e304, log = TRUE) |
-1.0243631212370614e307 | -1.4537765239560228e304 (−λ/2; the rest is of order 1e5) | same as truth |
dnorm(-1.59e-321, sd = 3e-323) |
0 | 5.2576630112522621e-304 (mpmath) | 5.257663011252932e-304 (as truth for x / sd rounded, as in the log density) |
dcauchy(-2.16543841389836e-309, scale = 1.57817263326e-312) |
1.0713040120126725e305 | 1.0713040120123239e305 (mpmath) | same as truth |
dcauchy(1e-10, scale = 5e-324) |
0 | 1.5726597949504821e-304 (mpmath) | same as truth |
log(dlogis(-3.5667197e-316, scale = 4.81926e-319)) |
-7.1442431635500565 | -7.1442419008923714 (mpmath) | same as truth |
dnbinom(57, 3.941094207e-315, 0.1246, log = TRUE) |
-735.57086040999684 | -735.57086038617797 (mpmath) | same as truth |
dnbinom(1, 1e-200, mu = 1e200, log = TRUE) (size / (size + mu) below the doubles) |
-Inf | -460.51701859880914 (Rmpfr) | same as truth |
dweibull(x, shape, scale, log = TRUE) with shape and scale within 2^-20 of each other (dweibull(2^52 - 0.5, 2^52, 2^52 - 0.5, log = TRUE)) |
log(shape/scale) takes the rounding of the ratio: -0.99999999999999978 | -0.99999999999999989 (log1p of the exact difference) | same as truth |
pnbinom(0, 5e-324, mu = 1.797693e308) and qnbinom(0.5, ...) (size / (size + mu) below the doubles) |
0 and NaN | 1 and 0 (the incomplete beta from the exact log of the ratio) | same as truth |
qexp(-720.6156070081367, 7.378938265185878e-258, log.p = TRUE) |
1.4880736486358194e-56 | 1.4880736486357560e-56 (mpmath) | 1.4880736486357558e-56 |
qweibull(-720.6156070081367, 1, 1.3552e257, log.p = TRUE) |
1.4880642941554512e-56 | 1.4880642941553880e-56 (mpmath) | same as truth |
The comparison values for these come from mpmath (100 to 800 digits) rather than Rmpfr.
choose and lchoose with a non-integer n and large k: R is off by up to 2.6e-10
(choose(10.3, 1e5)).choose with small k near overflow: R multiplies n by (n - 1)/2 and so on, two roundings per step, and
choose(1.5e154, 2) is 1.125e308, 0.91 ulp from the exact value; rStats.js gives 1.1250000000000002e308 (0.09
ulp), from the product in double-double (taken in the coordinates n / 2^s where it overflows on the way).factorial near overflow: factorial(170) is off by 1.2e-13 in R.dmultinom with large counts: R sums lgamma values and loses digits (2.8e-6 relative for
a count of 1e9; rStats.js multiplies binomial probabilities).digamma, trigamma, psigamma for large negative x (trigamma(-100000.25) is off by
1.2e-11), near the positive zero of digamma and for very large x (trigamma(1e300) by 2.4e-14).sum of values in three or more bands of magnitude that later cancel: R’s long double keeps 64 bits and
rStats.js’s double-double 106, so a band far below the others is rounded away. sum(c(1e308, 1e100, 1, -1e308,
-1e100)) is -1e100 in R and sum(c(1e20, 1e3, 1e-10, -1e20, -1e3)) -1000; the exact values are 1 and 1e-10.
rStats.js keeps a bound on what its double-double lost and, only where that could change the rounded result,
forms the sum exactly (BigInt) and rounds it once: 1 and 1e-10 (issue #374). Other sums are unchanged.mean of the same kind of values: R’s mean(c(1e308, 1e100, 1, -1e308, -1e100)) is -2.2e99 and
mean(c(1e20, 1e3, 1e-10, -1e20, -1e3)) -360; the exact means are 0.2 and 2e-11. rStats.js applies the same bound
to its mean (and so to every statistic built on it) and, only where it could change the rounded mean, forms the mean
from the exact sum: 0.2 and 2.0000000000000002e-11 (issue #473). Other means are unchanged.For calls such as qpois(0.999999999999999, 1e5), where 1 − p is below 1e-12, R compares
distribution-function values close to 1, and the rounding of 1 − (small value) shifts the answer
by a few units. rStats.js compares the small probabilities of the opposite tail and is not
affected.
| Case | R | rStats.js | ||||
|---|---|---|---|---|---|---|
| Variance and correlation of data with a large mean and small spread (1e8 + noise of 1e-3) | variance off by 1.4e-11, cor by 2e-10 |
sums in double-double | ||||
| Variance of values around 1e200 | squares overflow: variance Inf, t = 0, p = 1 | deviations rescaled by powers of two; finite result | ||||
| Correlation of values around 1e-200 | underflow, NA | finite result (as above) | ||||
fisher.test (2 x 2) and mantelhaen.test(exact = TRUE): the conditional MLE and the confidence limits |
uniroot on psi in [0, 1] or 1/psi in [eps, 1] with the absolute tolerance eps^0.25: for [[3, 1], [1, 3]] the estimate is 1.7e-6 off, the 95% limits 1.3e-5 and 0.7% (621.93 for 626.24), the 99% upper limit 6%, and the 99.99% limit the end 1/eps (4.5e15 for 3.2e5) | the roots on the log scale of psi to the precision of the doubles (the tail equals alpha at the limits, the mean equals the count at the estimate) | ||||
DescTools’ BinomCI(method = "midp") |
uniroot on (0, p) and (p, 1) with the absolute tolerance 1.22e-4: limits 1e-6 to 1e-4 off, and those below 1e-4 grossly wrong (BinomCI(5, 1e7, method = "midp"): [0, 1.168e-4] for [1.832e-7, 1.108e-6]) |
binomCI: the roots on the log scale of p, to the precision of the doubles |
||||
DescTools’ BinomCI(method = "wilson") and "wilsoncc": the lower limit for small x, and Newcombe’s BinomDiffCI(method = "score") built on it |
centre - half, which cancels in proportion to centre / lower: 1/1e15 at the level 1 - 2^-53 gives 1.4134451872531834e-17 for 1.4134451872532935e-17 (350 ulps), "wilsoncc" 1/1000 at 95% 28 ulps |
binomCI: the lower limit from the product of the two roots of the quadratic where centre - half would lose more than one bit (within a few ulps) |
||||
DescTools’ BinomDiffCI(method = "mn") and "mee", epiR’s score interval of the attributable risk |
mn: a bisection stopped at 1e-7 (about 1e-7 relative off); mee: uniroot with the tolerance 1.22e-4 (up to 8% for small differences); epiR: the bisection of mn, times 100 | binomDiffCI: the roots of the score statistic (the restricted MLE as the root of the score equation, started from Farrington and Manning’s closed form, which alone holds only an absolute precision of eps and loses the digits of small proportions; p1 - p2 in double-double) |
||||
DescTools’ BinomRatioCI(method = "koopman"), epiR’s score interval of the risk ratio at a = N1 or c = N0 |
uniroot with the tolerance 1.22e-4, or steps of 1.0001 at the boundaries (about 1e-4 relative); 1/1 against 0/1 gives the lower limit 2 instead of 0.5206 |
binomRatioCI: the roots of Koopman’s statistic |
||||
epitools’ oddsratio(method = "midp") |
the median-unbiased estimate and mid-p limits by uniroot on [0, 1000] with the tolerance 1.22e-4: the upper limit of [[30, 2], [1, 40]] is 11606 instead of 12475 | oddsRatio: the roots on the log scale of the odds ratio |
||||
epitools’ midp.exact p-value where it is below about 1e-16 |
2 min(m, 1 - m) with 1 - m formed from m: 0 for [[1000, 2000], [3000, 4000]] | both tails summed directly: the true small value | ||||
epiR’s score interval of the odds ratio (OR.strata.score of epi.2by2) |
steps of 0.1% from 1.1 times (or 1/1.1 times) the estimate, so that for large tables the interval is exactly [est/1.1, 1.1 est] ([[1000, 2000], [3000, 4000]]: [0.60606, 0.73333], true [0.60962, 0.72905]) | oddsRatio(method = "score"): the roots of the statistic |
||||
exact2x2’s fisher.exact(midp = TRUE): the confidence limits |
uniroot on psi in (0, 1) or 1/psi in (eps, 1) with the tolerance 1.22e-4: the upper 95% limit of [[3, 1], [1, 3]] is 311.44 instead of 308.56, that of [[100, 1], [1, 100]] the end 1/eps (4.5036e15) instead of 198848 | fisherTest(midp: true): the roots of the mid-p tails on the log scale of psi |
||||
| Boschloo’s test: the p-value, a supremum over the nuisance parameter pi | Exact (exact.test(method = "boschloo")): the maximum over 100 points refined by optimise and rounded to 12 digits, up to 6.3e-9 relative below the supremum (80/200 against 100/200); exact2x2 (boschloo()): the maximum over 98 points, 1e-6 to 2e-4 below |
boschlooTest: the supremum (a grid uniform on the arcsine scale of max(1000, 32 sqrt(n1 + n2)) points and Brent’s method at every candidate maximum; within a few ulps of a 999-point grid refined to 1e-13) |
||||
Exact’s two-sided "square" Boschloo test |
the region is completed by Barnard’s convexity, which the two-sided statistic does not have: for 20/60 against 9/25 it contains the tables (6, 2) and (54, 23), whose Fisher p-value is 1, and the p-value is 0.785623 instead of 0.785614 | the region evaluated table by table | ||||
DescTools’ GTest of a table: the p-value |
1 - pchisq(G, df), 0 below about 1.1e-16: 0 for [[500, 300], [300, 500]] (true 8.885160398737880e-24) |
gTest: the upper tail |
||||
DescTools’ GTest: the statistic where G is small against the counts |
the plain sum of x log(x / E), which cancels: c(50, 49) gives 0.01010118187639042 for 0.01010118187637941 (1.1e-12 relative; a few 1e-15 in ordinary tables) | gTest: the deviance sum of x log(x / E) + E - x (nonnegative terms) with E in double-double |
||||
coin’s lbl_test (asymptotic) |
Z up to 2.3e-14 relative off ([[0, 0, 0], [1, 2, 3], [4, 5, 6]]: -0.5089133578079946 for -0.50891335780798256) and the p-values about 1e-16 absolute: 1.3022916078853086e-13 for 1.3023688113411116e-13 ("greater", the 5 x 4 table of the fixture) |
lblTest: Z from the correlation of the scores, the normal tails directly |
||||
clinfun’s jonckheere.test and DescTools’ JonckheereTerpstraTest with ties (normal approximation) |
the null variance without ties (sum n_i m_i (n_i + m_i + 1) / 12), too large: p = 0.0086 for c(1, 1, 2, 2, 3, 3) in three groups | the permutation variance with the ties (Hollander & Wolfe): p = 0.0061; without ties as the packages | ||||
clinfun’s jonckheere.test and DescTools’ JonckheereTerpstraTest, normal approximation with a large positive statistic |
the upper tail as 1 - pnorm(z): 0 beyond z ~ 8.3 (1:101 in ordered groups of 34, 34, 33: p 0 for increasing and two-sided) | where 1 - pnorm(z) is below 1e-8, the upper tail pnorm(z, lower.tail = FALSE): 1.4902389037944e-26 (Rmpfr 1.4902389037944002e-26); above 1e-8 the packages’ value (#280) | ||||
wilcox.test(x, exact = FALSE) (also paired; two samples too), two-sided, with a small p-value from a large positive statistic |
2 (1 - F) with 1 - F formed from the lower tail F, which loses the digits: wilcox.test(1:300, exact = FALSE) gives p = 0 (-(1:300) gives 6.1141368593044447e-51, and alternative = "greater" 3.0570684296522223e-51) |
the upper tail itself where it is below 1/64: 6.1141368593044446e-51 (twice R’s own one-sided value). Above 1/64 R’s 2 (1 - F); the values differ from R’s by the rounding of 1 - F (a few 1e-17 absolute), beyond 1e-12 relative only below about p = 1e-4 | ||||
wilcox.test(x, conf.int = TRUE) (one sample or paired), exact with ties or zeros (the conditional interval of R 4.6) |
the lower end where P(V > v) <= alpha’ (a strict tail; the two-sample interval uses P(W >= w)), so it is one Walsh average too high and never -Inf, and an end at the first or last Walsh average is reported with tail 0: x = c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30) with mu = 0.5 (a zero) gives [1.19, 2.37] at 0.9609375, where the data have no ties and the classical interval is [1.165, 2.37]; c(1, 2, 2, 3) gives [1, Inf] at level 1 |
the lower end from P(V >= v) and the tails rejected at the ends: the classical interval for data without ties ([1.165, 2.37] at 0.9609375), (-Inf, Inf) for c(1, 2, 2, 3), and the level that is achieved (the test compares both rules with exact counts) |
||||
wilcox.test(x, y, conf.int = TRUE), exact with ties (the conditional interval of R 4.6) |
an end at the first or last difference is reported with tail 0, which overstates the level: wilcox.test(c(1, 2, 3), c(3, 4, 5), conf.int = TRUE, alternative = "greater", conf.level = 0.92) gives [-4, Inf] at level 1 |
the same ends, with the tail rejected beyond them (P(W >= 9) = 1/20 below -4): level 0.95 (the test compares both rules with exact counts) | ||||
oneway.test (Welch, the default) with one constant group |
NaN throughout (the weight n / 0 is infinite): oneway.test on [1, 1, 1] and [2, 3, 4] |
the limit as that group’s variance tends to 0: F = sum over the other groups of w_i (m_i - m_z)^2 / ((k - 1)(1 + 2 (k - 2) c)) with c = sum 1 / (n_i - 1) / (k^2 - 1) over them, df2 = 1 / (3 c); F 12, df (1, 2), p 0.0742, as t.test (Welch) on the same data. With two or more constant groups the limit depends on how the variances tend to 0, so it is an error “Welch’s test is not defined with two or more constant groups” (R NaN) (#313) |
||||
mcnemar.test (2 x 2, continuity correction) with fractional counts whose discordant cells differ by less than 1 |
(abs(b - c) - 1)^2 / (b + c) squares the negative corrected difference, so the correction makes the statistic larger: 0.7 instead of 0.129 for b = 0.5, c = 0.2, and 0.1 (as without the correction) for b = 1.5, c = 1 | the corrected difference max(0, abs(b - c) - 1): statistic 0, p 1 there (R’s chisq.test and prop.test clamp their corrections likewise); integer counts unchanged |
||||
chisq.test(x)$stdres (contingency table) with a margin small against the total |
E (1 - r / n)(1 - c / n) in doubles loses the small margins: [[2^52, 0], [0, 0.1]] gives NaN, -Inf, -Inf, 2^26 (true: 2^26 in absolute value in all four cells); integer tables such as [[1e15, 7], [3, 11]] are off by 2e-14 relative | the complements 1 - r / n and 1 - c / n as the other rows’ and columns’ sums over n, and O - E and the variance in double-double, rounded once: 2^26 in all four cells, 21912524.504463962 for the second (the exact value rounded); in ordinary tables the last bits may differ from R’s (#382) | ||||
mcr’s mcreg(method.reg = "Deming"): the slope for a small error ratio, the analytical standard errors, data of order 2^±500; method.reg = "WDeming" with data spanning more than about 1e154 |
(λq - u + sqrt((u - λq)² + 4λp²))/(2λp) cancels when λq < u: error.ratio = 1e-300 gives slope 0 (true 0.96786), 1e-12 a relative error of 7e-4, 1e300 Inf; 1 - p²/(uq) and the jackknife pseudo-values lose up to 7e-14; the sums overflow (NaN at 2^520) or its check sd(x) > 0 underflows (an error at 2^-540); the weights 1/m² of weighted Deming overflow |
mcreg: the same root as 2p/(R - (λq - u)) where λq < u (and the equation divided by λ for λ > 1), (uq - p²)/(uq) in double-double, the jackknife standard error as (n - 1) sd of the leave-one-out estimates; x and y each scaled by a power of 2 (the error ratio with them), so that data in very different units keep their sums of squares; weighted Deming’s sums formed from dx/m and dy/m and its weights divided by the largest (the reported 1/m² Infinity where beyond the range) |
||||
irr’s icc (two-way) with subject and rater effects much larger than the interaction |
the residual mean square from the total, subject and rater sums of squares cancels: effects of 1e8 with an interaction of ±1 give ICC 1, F Inf, bounds NaN (true MSE 3/2) | where that subtraction is below 2^-20 of the total sum of squares (or 0 or less), the MSE is the sum of the squared residuals x - row mean - column mean + grand mean in double-double: ICC 0.9999999999999999, F 2e16; elsewhere the same bits as before (#392) | ||||
oneway.test (Welch), var.test and car’s leveneTest with groups on very different scales (a group’s spread below 2^-1022 times the largest value) |
oneway.test on [1e200, 2e200], [0, 1e-100], [5, 7]: NaN (the variance of the first overflows); var.test(c(1e308, 1e308), c(0, 1e-100)): F Inf, p 0 (var of the first is Inf); leveneTest on [1e308, 1e308] and [0, 1e-100]: F 6.2e31, p 1.6e-32 |
each group on its own scale only where its variance (or deviations) would fall below the normal range on the common one (as bartlettTest, #270): F 15, df2 4/3; ratio 0, F 0, p 0; F Inf, p 0 (the deviations are 0 in one group only). Elsewhere the same bits (#393) |
||||
dunn.test’s step-wise adjustments (holm, hs, hochberg, bh, by) with tied p-values |
ties ranked in the order of the comparisons: the same p-value gets different adjusted values (1, 0.828, 0.414 with holm), which change when the groups are relabelled |
a run of ties takes the rank of its first, the one the stopping rule decides on: the same value whatever the order, the same decisions; without ties as dunn.test | ||||
glm where an IRLS step increases the deviance (binomial y ~ x with all weights 1000) |
glm.fit accepts the step: the deviance went 7564, 89255, 144175 and stopped there, “converged”, with coefficients of 1e15 (the maximum is 4956) |
the step is halved while the deviance rises by epsilon (1e-8 by default) relative or more (glm2’s rule): the maximum, the same as with weights 1; “step size truncated due to increasing deviance” | ||||
glm with the logit link where |eta| exceeds 30 |
the C code clamps the inverse link and its derivative to the values at eps (a jump from 1 − 9.4e-14 at 30 to 1 − 2.2e-16 just beyond): the binomial fit of the counts (1e15, 1) and (1, 2) on x = 1, 2 stops at deviance 2139, not converged (the solution has eta = log 1e15) | the exact values beyond 30, up to the largest double below 1 and down to the least double: deviance 0.013 (1 − y = 1/(1e15 + 1) limits it); within 30 as R | ||||
pexp(q, rate, log.p = TRUE) where rate × q is subnormal (pexp(1e-20, 1e-300, log.p = TRUE)) |
the log of the rounded subnormal product: -736.8272408909739 (1.1e-5 off) | log rate + log q: -736.8272297580946 | ||||
glm with the probit, cauchit, cloglog and power links at the ends |
make.link clamps eta (or mu) to the values at eps and the derivatives to eps: Phi(−10) = 7.6e-24, 1 − exp(−e^-40) = 4.2e-18 and a mean of 1e-16 (power 0.5) become 2.2e-16, the cauchit derivative 3.2e-19 at −1e9 becomes 2.2e-16 |
the exact values, kept within (0, 1) by the least double and the largest double below 1; within R’s range as R | ||||
The cloglog link log(-log(1 - mu)) of a small mean |
1 − mu rounds to 1: −Inf for mu = 1e-20 (glm stops: “NA/NaN/Inf in ‘y’”) |
log(-log1p(-mu)): finite |
||||
The derivative of a power link where 1/lambda is out of range (power(5e-324)$mu.eta(0.5), power(.Machine$double.xmax)$mu.eta(5e-324)) |
NaN (Inf × 0) and Inf (eta^-1 overflows) | the least double (the derivative is below the double range) and 1.1258999068426242e15 (eta^(1/lambda)/(lambda eta)) | ||||
The inverse Gaussian deviance contribution (also quasi with variance mu^3) where (y − mu)² or y mu² is out of range (inverse.gaussian()$dev.resids(1e-308, 1e308, 1), (0.5, 1e300, 1), (1e-200, 2e-200, 1)) |
NaN or Inf | ((y − mu)/mu)²/y: 1e308, 2, 2.5e199; where that overflows too ((1e200, 1e-200, 1e-300), (1e200, 1e-50, 1e-300); R Inf), w (y − mu)² / (y mu²) from the mantissas of w, y − mu, y and mu with their powers of 2 added back last: 1e300, 1 (issue #480) |
||||
The poisson deviance contribution beyond 10% of the mean where y/mu, y log(y/mu) or its product with the weight leaves the doubles (also quasipoisson and quasi with variance mu): poisson()$dev.resids(1e308, 1e-308, 1e-320), (1e308, 1e-10, 1e-10), (3e-320, 1e-320, 1e308) |
Inf | 2.83e-9, 1.46e301, 2.59e-12: y and mu in units of a power of 2, log(y/mu) from the logarithms where the ratio is out of range, and the weight’s exponent taken out; elsewhere R’s form and bits | ||||
The Gamma deviance contribution beyond 10% of the mean where y/mu overflows or underflows, or 2 w overflows (also quasi with variance mu^2): Gamma()$dev.resids(1e308, 1e-308, 1e-320), (1e-308, 1e300, 1e-300), (5, 2, 1e308) |
NaN, Inf, Inf | 2e296, 2.8e-297, 1.17e308: 2 w (r - 1 - log r) with r = y/mu as a mantissa and a power of 2, and the weight’s exponent taken out; elsewhere R’s form and bits | ||||
The binomial deviance contribution near the mean with a tiny mean or a weight above half the largest double (also quasibinomial and quasi with variance mu(1-mu)): binomial()$dev.resids(y, 1e-300, 1e308) with y one ulp above 1e-300, (0.3, 0.3003, 1e308) |
Inf (the direct form; before this fix rStats.js gave NaN and Inf) | 2.748e-24, 4.284e301: where the deviance or 2 w times it leaves the doubles, bd0 with y and mu in units of a power of 2 and the weight’s exponent taken out; elsewhere as before | ||||
The poisson deviance contribution near the mean with a tiny mean or a weight above half the largest double (also quasipoisson and quasi with variance mu): poisson()$dev.resids(y, 1e-300, 1e308) with y one ulp above 1e-300, (5.1, 5, 1e308) |
1.1e-8 (the direct form cancels) and Inf (before this fix rStats.js gave NaN and Inf) | 2.748e-24, 1.987e305: where 2 w bd0(y, mu) leaves the doubles or bd0 is subnormal, bd0 with y and mu in units of a power of 2 and the weight’s exponent taken out; elsewhere as before | ||||
A given dispersion below the normal range in summary.glm and predict.glm (summary(glm(y ~ x), dispersion = 2^-1074) with x = 0:3) |
standard errors 2^-537 and 0, the square roots of the rounded subnormal products 0.7 × 2^-1074 and 0.2 × 2^-1074 (predict(se.fit = TRUE): 0) |
sqrt(0.7) 2^-537 and sqrt(0.2) 2^-537: the dispersion held as m 4^s (m in [1, 4)) wherever its value in the units of the fit (rStats.js fits a gaussian response divided by a power of 2) is out of range, and the powers of 2 applied to the result; this also keeps dispersion 1 for a response of 1e308 (which R cannot fit) | ||||
The binomial, poisson and Gamma deviance contributions near y = mu (also quasibinomial, quasipoisson and quasi with variances mu(1-mu), mu and mu^2): binomial()$dev.resids(0.5, 0.5 + 2^-52, 1), poisson()$dev.resids(1, 1 + 2^-52, 1), Gamma()$dev.resids(1, 1 + 2^-52, 1), and (1000, 1001), (0.3, 0.3003) |
the first-order terms cancel, about 2 eps / abs(t) relative off with t = (y - mu)/mu: -9.86e-32, 0, 9.86e-32 (true 1.97e-31, 4.93e-32, 4.93e-32); 6.8e-11 and 9.0e-11 off at t = 1e-3 | where abs(y - mu) < 0.1 mu (binomial: 0.1 min(mu, 1 - mu)) as 2 bd0(y, mu), 2 (bd0(y, mu) + bd0(1 - y, 1 - mu)) and -2 log1pmx(t), as R’s dpois_raw and dbinom_raw switch to bd0: within a few ulp of the truth; beyond 10% R’s form and bits. Deviances and deviance residuals of fits near a perfect fit change in the last digits (the glm fixture: 512 values of 69 cases, mostly 1e-15 to 1e-10 relative), and the rounding residue of a perfect fit is no longer negative | ||||
The binomial deviance contribution of y = 0 with a small mean (also quasibinomial and quasi with variance mu(1-mu)): binomial()$dev.resids(0, 1e-20, 1) |
-2 log(1 − mu) with 1 − mu rounded: 0 for mu below 1.1e-16 (true 2e-20), about eps/(2 mu) relative off above | -2 log1p(−mu) for mu < 0.1: 2e-20; from mu = 0.1 on, R’s form and bits. In the glm fixture the deviance residuals of 31 cases change, mostly in the last digit; the deviances of two separated fits (about 2e-10) change by 6e-7 relative | ||||
AIC of a gaussian glm with rows of weight 0 |
Inf: the family’s aic takes log(0) of their weights and counts them in n |
the rows left out of the likelihood (every family): the AIC of the fit without them (5.84 for weights 1, 1, 1, 0) | ||||
residuals(glm, "deviance") without residual degrees of freedom |
0 for every row, also for a fit that has not converged (deviance 0.34 with residuals 0) | each row’s contribution: their squares sum to the deviance (rounding residue for a converged saturated fit) | ||||
glm with the log link where eta < −36 |
pmax(exp(eta), eps): a mean of e^-100 is 2.2e-16 |
exp(eta) down to the least double | ||||
glm on separated data (binomial y = 0, 0, 0, 1, 1, 1 on x = 1..6; a saturated Poisson fit with a count of 0) |
converged, with coefficients (−165, 47) that are only where the iterations stopped; at most “fitted probabilities numerically 0 or 1 occurred” | the same converged, with the warning “the linear predictor was still changing at convergence: the data may be separated (no finite maximum likelihood estimates)” (the last step moved eta by more than 0.1); the coefficients go on further with the exact logit link |
||||
coxph with a nearly aliased column (x2 = x1 + 1e-6 e) dropped by the Cholesky factorisation |
survival’s cholesky2 leaves the column’s residual cross-products, which chsolve2 and chinv2 still use: coefficients and variances 4e-12 off the fit without the column | the dropped column zeroed: the fit without it, bit for bit | ||||
optim(method = "CG") |
cgmin overwrites the start’s value with the accepted one before fitting the parabola, so its trial point is always the midpoint of the accepted step (quadratic of 3 variables: 46 function evaluations, value 5.6e-14; Rosenbrock from (-1.2, 1): value 3.1 at maxit 100) | the minimum of the parabola through the start and the accepted point (8 evaluations, value 1.8e-25; Rosenbrock 5.3e-8); the path differs from R’s | ||||
Perfect correlation (e.g. 1:5 with itself) |
r = 1 − 2 ulp; 1 − r² cancels, so t and p are far off (p = 4e-24 instead of 0; with noise of 1e-4 the p-value is off by 14%) | r and 1 − r² in double-double | ||||
| Kendall’s exact upper tail | computed as 1 − (lower tail): 5.6e-16 instead of 3.8e-33 for perfect correlation with n = 30 | upper tail summed directly | ||||
| Spearman, perfect correlation with n = 2 | S = 2.2e-16 (should be 0) | 0 | ||||
| Spearman’s t approximation with rho ≈ ±1 | p = 1e-62 for perfect correlation with n = 10 (should be 0) | 0 | ||||
| Fisher’s exact test for r × c tables | FEXACT rounding errors around 1e-11 relative (changing workspace changes the value by 2e-13) |
matches exact enumeration | ||||
var.test, ansari.test, mood.test and lawstat’s brunner.munzel.test: upper tails |
formed as 1 − P, so small p-values lose their relative accuracy (var.test returns 0 for p = 4e-58) |
tails computed directly | ||||
Exact ansari.test p-values |
R’s sums of probabilities carry rounding of up to 1e-8 relative in small p-values (8.8e-9 for m = 60, n = 70) | agree with exact subset counts | ||||
ks.test, asymptotic two-sided p-value |
Kolmogorov’s limiting series summed to a tolerance of 1e-6 (off by up to 1e-5) | agrees with scipy.special.kolmogorov |
||||
pchisq and pf with a huge noncentrality (1e13 and more) far from the quantile |
0 and 1, correct (but R does not converge near the centre of such a distribution) | 0 and 1 (a Chernoff bound decides); near the centre not supported | ||||
ks.test two-sample statistic that is 0 |
rounding residue of cumulative sums of 1/m and −1/n (±1e-16, sometimes negative) | 0 | ||||
fligner.test and prop.test statistics that are 0 |
rounding residue (1e-31) | 0 | ||||
skewness, kurtosis and cv of data with a large mean and small spread |
e1071 subtracts a mean rounded to double: skewness off by 8e-5, kurtosis by 2e-6 relative (1e8 + noise of 1e-3) | deviations from the double-double mean; agree with 60-digit values | ||||
aov (one way) with a large mean and small spread, or all values equal; summary(aov(...)) (also with Error(), in each stratum) and anova(lm(...)) of an exact fit |
R fits through a QR decomposition: sums of squares off by 6e-8 (1e6 + noise of 1e-3); F = 1 or 0.6 from rounding residue when all values are equal, 5.9e30 or 3.4e64 when the groups are constant (aov(y ~ g) with y = 1, 1, 2, 2) |
sums of squares within a few ulps (the QR of the fit on the response scaled to [1, 2)); a residual sum of squares below 1e-24 times the (weighted, uncentred) sum of squares of the response, as in Anova, is taken as 0 with the sums of squares of the terms at that level: F = Inf and p = 0, or NaN when all values are equal (aovSummary, also in each stratum of a fit with Error(), and the sequential table of anova) |
||||
TukeyHSD |
R’s ptukey and qtukey (see above); the p-value is off by 3e-6 with df = 5 (two groups, where it follows from the t distribution) |
agrees with high-precision values | ||||
lm with nearly collinear columns (1e6 + noise, with an intercept) |
coefficients off by 1.7e-9 from 60-digit values | 3.6e-11 (both within eps times the condition number) | ||||
lm and anova from a formula with a large mean (1e6 + noise) |
coefficients off by up to 1.5e-11 and R² by 2.8e-12 from exact rational values; sums of squares near 0 off by 1.6e-10 relative | fit in double-double; within 7e-15 of the exact values | ||||
mauchly.test on contrasts given by M and X |
W off by up to 4e-12 from the exact value, and the p-value near W = 1 by 1.3e-12 | W in double-double; within 1e-15 of the exact value | ||||
contr.poly(k) (in rStats.js, lmer’s contrasts: "contr.poly") |
the QR of the powers of the scores: elements off by up to 3e-13 for k <= 15, 1.3e-12 at k = 16 and 6e-11 at k = 20, and from k = 23 the high-degree columns are other vectors altogether (error 0.9; at k = 24 the QR’s numerical rank is 22) | for every k, the orthonormal polynomials by the three-term recurrence with full re-orthogonalisation: within 6e-16 of the exact values (k = 2 to 26), so the last bits differ from R’s even for few levels | ||||
Power calculations with noncentral distributions (power.t.test, power.anova.test, pwr.*) |
R’s noncentral t is accurate to about 1e-12 and its noncentral F to about 1e-9 (and t with more than 4e5 degrees of freedom uses an approximation), so computed powers and the sample sizes solved from them are off by up to 3e-8 | accurate noncentral distributions; the solved quantities follow R’s uniroot calls (same interval and tolerance), so they keep R’s tolerance |
||||
effectsize’s confidence intervals (cohens_d, hedges_g, eta_squared, …) |
the noncentrality parameters are found with Nelder-Mead (optim): limits off by about 1e-9, up to 3e-3 relative (a partial eta² upper limit of 0.25181 instead of 0.25111) |
the exact limits | ||||
Dunnett-type p-values (multcomp’s Dunnett, PMCMRplus’s dunnettTest and single-step kwManyOneDunnTest and manyOneUTest) |
mvtnorm’s randomised integration: about 1e-3 absolute, different from run to run (seeded) | exact one-dimensional integral | ||||
| Studentized-range p-values of post-hoc tests (Steel-Dwass, Games-Howell, Tukey) | R’s ptukey, about 8 digits (off by up to 3.4e-8 in the tests) |
full precision | ||||
| irr’s kappa p-values | formed as 2 (1 − Φ( | z | )), losing small ones (2.2e-16 instead of 1.7e-16) | 2 Φ(− | z | ) |
psych’s ICC with lmer = TRUE (the default) |
the mean squares from lme4’s REML fit, whose optimiser stops early: every value about 1e-5 to 1e-4 relative off | the REML estimates of the balanced two-way model in closed form (the ANOVA mean squares, or where a variance component would be negative, the residual mean square pooled with that one: Robertson, Wright and Dykstra’s isotonic regression of the mean squares) | ||||
psych’s ICC with lmer = FALSE on data scaled by 2^±520, with a large offset (1e6) or with a residual mean square of 0 |
aov’s sums of squares: NaN, 3e-10 relative off, F about 1e31 |
sums of squares in double-double from the exact differences of the ratings from the first row, the first column or both (which row and column offsets do not change), each scaled by a power of 2, so that an offset of a rater or subject far beyond the spread (1e100) does not swamp them; F Infinity and p 0 where the ratings differ between raters by constants (the residual is exactly 0) | ||||
TOSTER’s noncentral-t limits of the standardised mean difference (smd_ci = "nct") |
found by an optimiser (optimize, nlm): about 1e-9 relative off (up to 7e-9 in the tests) |
the roots of the noncentral t, as cohensD; for a noncentrality above 37.62 R’s own pt uses a normal approximation (Abramowitz and Stegun 26.7.10), so roots of R’s pt are off there (1% at ncp 50: an upper limit 15.80 for 15.96 for a one-sample g of 11.2 with 8 values) |
||||
polycor’s maximum-likelihood estimates and standard errors (ML = TRUE, std.err = TRUE) |
Nelder-Mead or BFGS stops early and the Hessian is taken by finite differences: off by up to 1e-3 relative; on strongly associated tables the two-step BFGS runs past 1 and reports 0.9999 with an infinite variance | the exact maximum (within 4e-15 of 160-bit values) and the analytic Hessian | ||||
nortest’s pearson.test with a value whose pnorm rounds to 1 (an outlier about 8.3 sd or more above the mean) |
the value falls in class k + 1, which tabulate drops: the counts sum to less than n (1176.13 for 99 zeros and 1e6) |
counted in the last class: 1174.26 | ||||
psych’s omega (minres) with a uniqueness at the lower bound 0.005 (a Heywood case) |
fa passes L-BFGS-B the gradient of the residual sum of squares with the diagonal, not that of the off-diagonal objective; the two minima agree in the interior but not at the bound, so the fit stops above the minimum, mostly with convergence 0 (0.5% to 3.4% above it in the tests; uniquenesses off by up to 0.05) |
from that point, L-BFGS-B goes on with the objective’s own gradient (factr 1e3) to the minimum; without a uniqueness at the bound as psych, bit for bit | ||||
psych’s alpha with a singular item correlation matrix (a repeated item, an item that is the sum of others, or at least as many items as subjects; issue #468) |
G6 from smc, whose pseudo-inverse and clamp to [0, 1] give an item that the others predict exactly an SMC of 0 instead of 1: G6 0.5 for two copies of one item, 0.712 for a = b next to c (the R^2 gives 0.956), negative values with more items than subjects (rStats.js before: an error, also for raw and standardized alpha) |
each SMC as the R^2 of lm(x_i ~ x_-i) (R’s QR, tol 1e-7): G6 1 and 0.956. Where the matrix is nonsingular, the SMC from its inverse as before (psych’s value, except for nearly dependent items, where psych’s Pinv drops small singular values). With at least as many items as subjects the centred items span at most n - 1 dimensions, so every item is predicted exactly by the others and G6 is always 1 (correct for the sample, but it carries no information) |
||||
pROC’s coords (ret = "all") |
the counts rebuilt as se · m and sp · n, not always integers (32/49 · 49 = 31.999999999999996); fpr = 1 − sp, lr_pos = se/(1 − sp) and closest.topleft cancel near sp = 1 (one false positive among 10000 controls: fpr 9.9999999999989e-05, lr_pos 10000.0000000011) | coords: every column from the integer counts, rounded once (fp/n, (tp n)/(m fp), …) |
||||
pROC’s coords(x = "best") |
the criteria (se + r sp, the distance to the corner) compared with == after rounding: thresholds tied mathematically are lost (controls 7, 10, 12, 6, 10, 6 and cases 5, 2, 3, 1, 12, 14, 12, 14, 3, 14, 8, 13: only 11 for 11 and 12.5, both se + sp = 4/3) |
coords: the criteria compared exactly (integer cross-products with the exact rational of the weights); every tied row |
||||
epiR’s epi.tests(method = "exact") |
the Clopper-Pearson limits as 1 − qbeta(…), which loses digits for small limits (se = 1e-7: lower limit off by 4e-9 relative) | diagnosticTests: qbeta directly (binomCI’s "clopper-pearson") |
||||
epiR’s epi.tests: the positive likelihood ratio and its limits when the specificity is near 1 |
se/(1 − sp) with 1 − sp formed from sp: 180000.89999939842 for 180000.9 ([[9e5, 10], [1e5, 2e6]]) | diagnosticTests: 1 − sp = b/(b + d) from the counts (likewise 1 − se for LR−) |
||||
epiR’s epi.tests(method = "wilson"): the lower limit at x = 0 |
−2.8e-17 (rounding of centre − half) | 0 (binomCI’s Wilson limits) |
The R references are extraDistr (invgamma, kumar, pareto, triang, laplace), R’s beta functions (arcsine) and
closed forms written in R (distSummary). The values here agree with 50-digit mpmath values
(scripts/mpmath/extradist.py, scripts/mpmath/distsummary.py).
| Case | R | rStats.js |
|---|---|---|
Tails of pinvgamma, pkumar, ppareto, plaplace, ptriang |
extraDistr evaluates the textbook formulas: 1 − x^a and 1 − p cancel and log probabilities are taken after the probability underflowed (pkumar(1e-10, 1, 1) is off by 8e-8, pinvgamma(1e-300, 1, 1, log.p = TRUE) is −Inf instead of −1e300) |
tails computed directly |
Log tails of the order of a subnormal shape (pkumar(0.2015, 0.4224, 1.85e-317, log.p = TRUE), ppareto(318.7, 1.04e-317, 1, log.p = TRUE)) |
−Inf | −729.6448082452898, −728.127870954796 (mpmath: −729.64480824528978, −728.12787095479600) |
dkumar(0.2015, 0.4224, 1.85e-317, log = TRUE) |
−728.528830589584 (off by 1.2e-10) | −728.5288305013036 (mpmath: −728.52883050130359) |
qkumar(-744.2443613428673, 1.1349, 0.1241, log.p = TRUE) (a log p below the normal range) |
0 | 1.0076418889538287e-284 (mpmath: 1.0076418889538287057e-284) |
ptriang(3.0662e-190, 0, 1.2412e133, 5.581e132, log.p = TRUE) (a subnormal ratio of lengths) |
−Inf | −1484.8619589788332 (mpmath: −1484.8619589788330) |
Quantiles in the far tails (qlaplace, qkumar, qtriang, …) |
1 − p rounds: qlaplace(1e-300, lower.tail = FALSE) is Inf |
correctly rounded (maps back to p) |
Densities steep in a parameter (dinvgamma with alpha = 100, dtriang near the ends) |
the rounding of beta / x or b − x is magnified (to 9e-14) | the division in double-double |
distSummary skewness and kurtosis of weibull and kumar |
the raw-moment formulas cancel: 9 digits of the kurtosis lost for shape 20 | central moments integrated directly (3e-14) |
erfinv of a small argument (pracma’s definition through qnorm((1 - |y|) / 2)) |
the relative accuracy of y is lost: erfinv(1e-10) off by 8e-8, erfinv(1e-300) is −0 |
Newton steps on erf |
gammainc (R’s pgamma(x, a) * gamma(a)) |
two roundings, and exp of a large log where the product overflows (1e-13 for a = 200) | the series for x < a with pow |
| Case | R | rStats.js |
|---|---|---|
pbinom(36, 1e5, 0.01, log.p = TRUE) |
-Inf (internal underflow, with a warning) | -851.68… |
pbinom(1e16, 2e16, 0.5) (beyond 2^53, x + 1 rounds to x) |
0.5 (the symmetric I_p(x, x)) | 0.5000000028209479 = 1/2 + dbinom/2 (I_p(x + 1, n - x) = I_p(x, n - x) - (n - x)/n dbinom(x); NaN where n - x rounds as well). ppois takes the same identity there, as R’s values do |
pnbinom(1e16, 1e16, 0.5) (beyond 2^53, x + 1 rounds) |
0.5 | 0.5000000028209479 = 1/2 + dnbinom (I_p(size, x + 1) = I_p(size, x) + dnbinom(x)); qnbinom(0.5, 1e16, 0.5) is 1e16 as in R. Where the term is not resolved against a deep upper tail, the rounded x + 1 is used (one unit of x is below the resolution there) |
pgeom(2^54, 1e-14, lower.tail = FALSE) (beyond 2^53, x + 1 rounds) |
0x1.13bd80f2f26d7p-260 (q^(x + 1) with the rounded x + 1 in the exponent) | 0x1.13bd80f2f26d2p-260 (q^x q; the correctly rounded value is …d1p-260; issue #327) |
binom.test(0, 1e20), poisson.test(0, r = 1e20) (counts beyond 2^53) |
error “result would be too long a vector” | a p-value (the bisections stop where their midpoint rounds to an end; they did not return before) |
DescTools’ BinomCI(method = "midp") at the one-sided level 0.5 (sides = "right", the two-sided level 0) |
error “f() values at end points not of opposite sign” (the root is outside its bracket) | binomCI: the root (the mid-p median) |
epitools’ oddsratio(method = "midp") with a zero cell or an odds ratio beyond 1000 ([[0, 10], [5, 5]], [[100, 1], [1, 100]]) |
error “f() values at end points not of opposite sign” | oddsRatio: exact2x2’s conventions at the ends of the support (estimate and limit 0 or Infinity), the roots otherwise |
poisson.test(2^53 + 2, r = 2^53 + 2, alternative = "greater") (beyond 2^53, x - 1 rounds) |
0.50000000980826 (P[X >= x] as ppois(x - 1, upper) with a rounded x - 1) | 0.50000000140118 = P[X > x] + dpois(x), true 1/2 + 1/(3 sqrt(2 pi x)) to first order; also the upper tails of the two-sided p-value (issue #323) |
binom.test(2^53, 2^54, alternative = "greater"), binom.test(2^53 + 2, 2^54 + 4, alternative = "greater") (beyond 2^53, x - 1 or n - (x - 1) rounds) |
0.5, 0.500000011889406 (pbinom(x - 1, upper) with a rounded argument) | 0.5000000029723516 = P[X > x] + dbinom(x) (true 1/2 + dbinom(n/2)/2); also the upper tails of the two-sided p-value (issue #324) |
poisson.test(c(5, 5), T = c(1e308, 1e308)), T = c(1e-308, 1e-308) |
p-value 0 (p0 = r T1 / (r T1 + T2) = 0), expected count NaN; rate ratio NaN | p-value 1, expected count 5, rate ratio 1 (the ratio T2 / T1 where the sums overflow or fall below the normal range) |
binom.test(5, 10, conf.level = 1 - 1e-16) and poisson.test (alpha below 1e-8) |
the upper limit from 1 - alpha, which loses its digits (1 and Inf at 1 - 1e-16) | the upper limit from the upper probability alpha itself (0.99981, 52.549); levels with alpha >= 1e-8 as R |
The same for the intervals of var.test, prop.test, mantelhaen.test, t.test, the ICC, cor.test, the one-way contrasts, confint and predict of lm, glm’s profile intervals, coxph, survfit and equivalence’s tost (alpha below 1e-8) |
1 - alpha or (1 + level) / 2 rounds to 1: limits 0, NaN or Inf | the upper probability alpha passed to the quantile function |
mantelhaen.test with counts near 1e150 (products of counts overflow) |
statistic and p-value NaN (Inf / Inf in the variance) | the ratios formed first there: statistic 0 and p-value 1 for balanced tables |
mantelhaen.test on I x J x K tables with counts near 1e103 or more (t^2 (t - 1) and the products in the covariance overflow), e.g. every cell 1e103 |
error “NA/NaN/Inf in foreign function call” (0 times Inf in the covariance) | each covariance entry as r_i (d - r_ii / t) (d - c_jj / t) c_j / (t - 1) there, and all counts divided by a power of 2 where a stratum total or a sum over the strata overflows: statistic 0 for balanced tables, otherwise the statistic within 1 ulp of exact arithmetic |
mantelhaen.test on 2 x 2 x K tables whose stratum totals or sums over the strata overflow (finite counts near 1e308) |
error “missing value where TRUE/FALSE needed” (the totals are Inf, the difference NaN) | all counts divided by an even power of 2 there, the statistic scaled back by it and the sd of the log odds ratio by its square root: statistic 0, estimate 1 for balanced tables, otherwise within a few ulps of exact arithmetic |
ks.test(x, "punif", exact = TRUE) with D >= 1/2 and a tiny p-value (D = 0.9, n = 20, 50, 99) |
0, 8.9e-16, 2.0e-15 (1 - P(D < d) loses the digits) | 2.0e-20, 2.0e-50, 2.05e-99: P(D >= d) = 2 P(D+ >= d) for d >= 1/2, a sum of positive terms |
ks.test(x, F, exact = TRUE) (one sample, two-sided) with D < 1/2 and a small p-value, e.g. x = (1:99)/99, F(q) = 0.51 q (D = 0.49) |
1.998e-15 (1 - P(D < d): absolute accuracy 1e-15 only, relative error 8e-13 at p = 3e-3) | 1.9222472248029e-22 (Rmpfr 1.9222472248029365e-22): where 2 P(D+ >= d) < 1e-2, P(D >= d) as a sum of positive terms (the binomial steps of the empirical process between the boundaries); p-values that may be larger as R. Where that sum would need more than 2^28 terms (large n, small D), 1 - P(D < d) as R (#483) |
quade.test, fligner.test with ranges or deviations of finite data that overflow (rows -1e308 to 1e308 and -9e307 to 9e307) |
tied as Inf: the result changes when the data are rescaled | the data divided by a common power of 2 there: the same result at any scale |
wilcox.test(c(1e308, 1.1e308, 1.2e308), mu = -1e308), and the two-sample x - mu (finite data whose difference from mu overflows) |
the differences tie as Inf: V = 6 by the normal approximation, p = 0.1489 (W = 9, p = 0.0636 against y = 1:3) | the differences in half units (x / 2 - mu / 2) there, ranked as the true differences: the exact p = 0.25 (0.1 for W = 9) |
mcnemar.test on an r x r table where a pair of cells has no discordant counts |
statistic and p-value NaN | that pair adds 0 (df unchanged) |
cor.test(c(1, 2), c(1, 2), method = "kendall", exact = FALSE) (n = 2) |
statistic and p-value NaN: the second tie term of the variance is 0 / 0 (n − 2 = 0 in its denominator) | z = 1, p = 0.3173: that term is 0 (every tie group has at most 2 values) |
cor.test(c(1e-300, 2e-300, 3e-300), c(1, 2, 3)) (Pearson; the sums of squares underflow) |
NaN with the warning “the standard deviation is zero” | r = 1 (the data scaled by powers of 2) without a warning |
predict(glm, newdata, se.fit = TRUE) where the squares overflow (newdata 1e155) |
se.fit Inf | the norm formed from the values divided by the largest: 1.07e154 |
summary(lm), summary(glm) and confint(glm) with a column of x far from 1 (x times 1e-200 or 1e200) |
the standard error Inf or 0 ((R’R)^-1 overflows or underflows), t 0 or Inf, p 1 or 0; the profile interval fails | the columns of R divided by powers of 2 before the inverse: t, p and the interval as for x itself (the unscaled covariance is still Inf or 0 where it is out of range) |
glm (gaussian, with intercept) with weights of 1e308, or with an infinite response of weight 0 |
null deviance NaN (the sum of the weights overflows; 0 times Inf) | 5e306 and 4.67: the weights divided by a power of 2, rows of weight 0 left out |
anova(lm(...)) and car’s Anova with a huge response in a row of weight 0: y = c(1, 2, 4, 3, 1e308), x = 0:4, weights 1, 1, 1, 1, 0 |
anova: error “missing value where TRUE/FALSE needed”; Anova: NaN throughout |
the table of the fit of the first four rows (Sum Sq 3.2 and 1.8, F 3.56): the scale of the response is taken from the rows of positive weight only (issue #350) |
car’s Anova (types II and III) of a weighted lm whose weights sum beyond the largest double: lm(y ~ x, weights = rep(1e308, 5)) with x = 0:4, y = c(1, 2, 1, 3, 1) * 1e-154 |
error “system is computationally singular: reciprocal condition number = 0” | Sum Sq 0.1 and 3.1, F 0.0968, p 0.776 (as anova): only where a sum over the weights overflows, the weights are divided by an even power of 2 (issue #347) |
summary(lm(y ~ x, weights = c(1e308, 1e308, 1e308, 2^-1074))) with x = 0:3, y = c(0, 1, 2, 4) (a weighted residual sum of squares in the subnormal range) |
sigma 0 (rss / df = 2^-1075 rounds to 0), standard errors 0, R^2 and F NaN | sigma 2^-537.5 = 1.57e-162, R^2 1, F Inf, the standard errors from it: where a positive weight underflows on the common weight scale, the rss is formed from the original weights in units of a power of 2 (issue #388; with one residual df, 2^-537 as R) |
lmer with a response of 1e200 (or 1e-200) times ordinary data |
lme4: the fixed effects as expected but sigma Inf (the penalised sum of squares overflows) | the response divided by a power of 2 for the fit: theta as for the data itself, fixed effects, sigma, variance components, random effects and residuals scaled back, the log-likelihood shifted by −(n or n − p) log c |
lmer(y ~ x + (x \| g)) with x in other units (x times 3e5, 1e6 or 1e-5) |
lme4 stops at another point with a convergence warning (REML criterion 101 for 65.9 on the data of issue #11; it suggests autoscale = TRUE) |
the minimisation over theta on Z with its columns divided by powers of 2, theta scaled back: the same fit in the units of x |
| lmerTest’s Satterthwaite df with the response in other units (times 1e6 or 1e-6) | the df of x 7.4e8 for 31 at 1e6 (0.19 at 1e-6), with an eigenvalue warning: the Hessian in (theta, sigma) is cut at an absolute 1e-8 | the Hessian cut in coordinates of comparable scale (theta by the columns of Z, sigma by a power of 2 near its estimate): df, t, F and p as for the data itself |
pracma’s barylag with nodes of 1e200 (or 1e-200) |
the products of node differences overflow (underflow): every weight 0, the result NaN | the products kept with their exponents and the weights scaled by a common power of 2: 0.25 for (x / 1e200)^2 at 0.5e200 |
pracma’s barylag(c(-1e308, 1e308), c(-1, 1), 0) and other finite nodes whose range overflows |
a node difference overflows: NaN | the weights and differences in x / 2 (the interpolant does not depend on the scale of x): 0 |
pracma’s barylag(c(0, 2^-250, 2^-249, 2^-600), c(1, 0, 0, 0), 2^-1074) (a product of node differences, 2^-1099, underflows; a weight divided by the difference to the point overflows; issue #402) |
NaN | 1 (only where they leave the range, the product of the two factors each as m 2^f, and the terms of the quotient as m 2^e divided by the power of 2 of the largest) |
pracma’s barylag(c(0, 2^-250, 2^-249, 2^-600), c(0, 2^-250, 2^-249, 2^-600), 2^-300) (y = x; the terms -2^300 and 2^300 of the second form’s denominator cancel exactly to 0, and what is left is below their rounding error; issue #467) |
NaN (rStats.js before: Infinity) | 2^-300 (only where the denominator falls below 2^-100 of the sum of the absolute terms while the numerator keeps 2^-26 of its own: the first form l(x) sum w_j y_j / (x - x_j) with the factors as m 2^e; data whose numerator cancels too, such as a constant, keep the second form) |
varimax and factanal (varimax or promax) with a row of zero loadings (a variable uncorrelated with the others) |
“infinite or missing values in ‘x’”: the Kaiser normalisation divides the row by 0 | the rotation of the other rows (as R’s varimax of them), the zero row kept 0 |
dcauchy with a scale above 5.7e307 (dcauchy(1.1e308, scale = 1e308)) |
0: π × scale overflows | the subnormal density, 1.44e-309, with 1/π taken first there |
lm with all weights below 1e-308 |
standard errors Inf (NaN at 5e-324), t 0, p 1 | the values of the weights 1 ((R’R)^-1 formed for the weights divided by a power of 2) |
anova(fit1, fit2) where the larger model fits essentially perfectly (y = 1 + x + z exactly) |
F 2.6e30 and p 4e-16 without a warning (the table of one fit warns) | the same values with the warning “ANOVA F-tests on an essentially perfect fit are unreliable” |
p.adjust(p, "BY", n = Inf); "holm" with n = Inf |
“result would be too long a vector”; every p-value 1 | an error (n must be finite); BY with a large finite n uses the expansion of the harmonic number beyond 1e6 |
qbinom(-1e10, 1e5, 0.01, log.p = TRUE) |
37 (search stops early) | 0 (F(0) ≈ e^-1005 exceeds e^-1e10) |
qt(1e-320, 2) (subnormal p) |
-Inf | -7.0711e159 (matches the closed form −sqrt(1/(2p))) |
qbeta(-1e5, 1e-10, 100, lower.tail = FALSE, log.p = TRUE) |
NaN | 1 (the true answer rounds to 1) |
qbeta(2.25e-265, 5.68e-37, 5643.4, lower.tail = FALSE) (a tiny shape) |
1, with a warning | 0.08797712670529832 |
df(1.33e-322, 1.04, 206159) and other subnormal x |
NaN | 3.77e153 (from the log of m x / n) |
df(Inf, df1, df2) with df1 < 2 (df(Inf, 1, 1), df(Inf, Inf, 1)) and df(Inf, df1, finite, ncp) |
NaN | 0 (log -Inf): the density tends to 0 as x -> Inf for every df1 (issue #493) |
df(x, Inf, df2) where dgamma(1/x) or x^2 leaves the normal range: df(1e-300, Inf, 5), df(1e160, Inf, 1) |
NaN (0 / 0), 0 | 0, 3.9894228040143e-241 (Rmpfr …433e-241): the linear density from its log there (issue #493) |
pf(5.43e-319, 1.04, 206159) (subnormal x) |
1.0014e-166 | 7.3742e-167 |
dcauchy(1e300, log = TRUE), pcauchy(-1e300, scale = 1e-300, log.p = TRUE) |
-Inf | -1382.69… |
dweibull(1e-300, 3, log = TRUE) |
-Inf | -1380.45… |
dweibull(1e100, 5, log = TRUE) |
NaN (∞ − ∞) | -Inf |
pnbinom(30, 1e7, 0.7, log.p = TRUE) |
-Inf | -3566376.67… |
qcauchy(-1000, 0, 1e-300, log.p = TRUE) |
-Inf | -6.27e133 |
qcauchy(1e-320, 0, 1e-300) |
inaccurate (πp is subnormal) | correct value, computed as scale/p/π |
qlogis(1e-320, lower.tail = FALSE) |
Inf | 736.83 |
plogis(-745) and other subnormal answers |
0 | 5e-324 |
pwilcox(q, 500, 500) |
R 4.5 used several GB and ran out of memory (R 4.6, with Löffler’s formula, takes 10 s) | computed (memory grows with mn/2). Beyond about m = n = 510 the entries near the center lose their accuracy (the passes of the table amplify errors above their centers): a RangeError there, from 1.7 sd below the center at 520 to 18 sd at 1050 (the tails stay available; unequal sizes with a small m, such as 100 and 20000, reach the center) |
dwilcox(3, Inf, 5), dsignrank(3, Inf) |
allocation error or crash | NaN |
qsignrank(p, 1100), qhyper(0.5, 1e13, 1e13, 1e13) |
does not finish | computed (qhyper takes about 2.5 s at this size; beyond a standard deviation of 2^21 it throws a RangeError, see the limits under Hypothesis tests) |
qtukey(1e-10, 20, 10) |
NaN | finite answer |
qtukey(1.52e-287, 3, 4.67e10, nranges = 2, lower.tail = FALSE) |
NaN (“convergence failed”) | 51.31849500218445 |
ptukey(54.5, 3, Inf, nranges = 2, lower.tail = FALSE, log.p = TRUE) (1 − W below the double range) |
-Inf | -744.6488312090673 (log 2 + log(1 − W)) |
qbeta(8.7e-285, 1.33e304, 5.89) (a huge shape; the answer rounds to 1) |
NaN, with warnings from bgrat |
1 |
pf(2e-323, 0.0121, Inf) (q df1 below the normal range) |
0 | 0.01091389160021212 |
qf(-385.76, 1.05, 1.14e264, ncp = 1.65e262, log.p = TRUE) |
Inf, with a warning | 1.5704712908151466e262 (the noncentral χ² limit) |
pf(2.5e300, 1827.5, 0.165, ncp = 3.66e307) |
NaN, with warnings | 7.4814091599854485e-292 |
qchisq(0.5, 1e308, ncp = 1e308), qchisq(0.5, 1e308, ncp = 7e307) (df + ncp overflows, or the quantile is near the largest double; issue #157) |
NaN, with a warning (also qchisq(0.5, 5e307, ncp = 5e307)) |
Infinity (mean 2e308, standard deviation 2.4e154: the quantile is beyond the doubles), 1.7000000000000001e308 (the distribution function steps from 0 to 1 at that double). The bracket stops at the largest double; if the target is not reached there the quantile is Infinity |
beta(1e-310, 1e-310) (B(a, a) > 2/a overflows) |
NaN, with warnings | Inf |
qhyper(1 - 1e-15, 1e4, 1e5, 5000) |
5000 | 617 (by definition) |
fisher.test on a 3 × 5 table with n = 179 |
FEXACT error 7 with the default workspace | 0.2023726720757 (0.65 s) |
wilcox.test(exact = TRUE) with very large n (e.g. 3000) |
psignrank gives NaN; with ties or zeros, “overflow error: cannot compute exact distribution” above about 1024 values |
computed (with ties or zeros up to the time limit, about n = 2400: performance) |
wilcox.test(x, y, exact = FALSE) (normal approximation) with every value tied, e.g. wilcox.test(1, 1, exact = FALSE) |
p = NaN (0 / 0; the exact conditional test, R 4.6’s default here, gives 1) | 1 (W always equals its expectation), for every alternative |
kappa(exact = TRUE) and MASS’s ginv of a matrix whose singular values exceed the largest double (a * matrix(c(1, 1, 1, -1), 2) with a = 1.7e308) |
NaN (Inf / Inf) and the zero matrix (the cut-off tol × Inf drops every component) | 1 and the inverse (±2.9e-309): ratios and the cut-off on the scaled singular values |
lmerTest’s contest with a contrast of extreme magnitude (c(0, 1e160), c(0, 1e-200), diag(2) * 1e160) |
standard error Inf or 0, t 0 or Inf, df and p NaN; “infinite or missing values in ‘x’” or no rows for the joint test | the test of the contrast itself (L and rhs divided by a power of 2), the estimate and the standard error in the contrast’s units |
psigamma(x, deriv) for x < 0 and deriv ≥ 6 |
NaN (not implemented in R) | computed (psigamma(-1.5, 10) = -156.229596593233) |
trigamma(1e-300), psigamma(1e-100, 3) and other results that overflow |
NaN | ±Inf |
besselI(1000, 1000) |
Inf | 2.7234536469108428e229 |
besselK(1000, 1000), lfactorial(1e-300), besselI(1e-300, 1) |
0 | 1.2981802514667e-233, -5.77e-301, 5e-301 |
besselJ(1e6, 0) |
0 | 3.3104301373987376e-4 |
besselY(1e6, -2.75) |
-4.1e-4 | -2.8030753997749413e-5 |
besselJ(1e308, 0), besselY(1e308, 0), besselI(1e308, 0, expon.scaled = TRUE) (pi x or 2 pi x overflows) |
0, with the warning “value out of range” for J | -2.4706564120790082e-155, 7.5866879552418034e-155, 3.989422804014327e-155 (the square roots taken apart) |
gamma(171.6243769563027) (the largest double whose Γ is finite) |
Inf | 1.79769313486223e308 |
gamma(-171.5), gamma(-172.5), … down to gamma(-177.5) (subnormal results) |
0 | 1.9316265431712e-310, -1.1197835032888e-312, …, 5e-324 |
lbeta(1e308, 1e308) (a + b overflows) |
-Inf | -1.3862943611198915e308 |
besselY(1e-310, 0), besselY(5e-324, 0) |
-Inf | -454.49387560035387, -473.99907342300429 |
besselK(1, 1e12), besselY(1, 1e12), besselY(10, 1e8) (results far out of range at large orders) |
error “cannot allocate vector of size 7450.6 Gb”; NaN with a warning | Inf, -Inf, -Inf at once (bounds on the log of the result decide before the recurrences of about nu steps) |
besselK(1e8, 2e8) |
0 | Inf |
besselI(1e12, 2e5, expon.scaled = TRUE), besselI(1e16, 1e7, expon.scaled = TRUE) (the continued fraction of I_(nu+1) / I_nu needs more than 1e6 terms; #492) |
0 | 3.910426939755009e-7, 3.969525474770118e-9 (Debye’s uniform expansion, Rmpfr to within 1e-15; before the fix rStats.js stopped the fraction at 1e6 terms and gave values 25% and 99.8% low) |
besselI(1e308, 1e154, expon.scaled = TRUE), besselK(1e308, 1e154, expon.scaled = TRUE) (#492) |
a warning (“ncalc … Arg. out of range?” and “precision lost in result”), then R 4.5.2 on Windows crashed (segmentation fault) | 2.419707245191434e-155, 2.0663656770612464e-154 (Debye’s uniform expansion, Rmpfr to within 5e-16) |
besselJ(1e200, 1e50), besselY(1e200, 1e50), besselJ(1e40, 1e17) (the asymptotic expansion for large x; #490) |
NaN with the warning “nu=1e+50 too large for bessel_j() algorithm” (every nu above 1e7) | 6.831382541998361e-102, -7.949547116811557e-101, -6.538328107498253e-22 (Rmpfr to within 3e-16; the powers of nu^2 as ratios nu / x where they overflow, and nu / 2 + 1/4 modulo 2 from nu modulo 4 for nu >= 2^52) |
ansari.test(conf.int = TRUE) with ties and exact unset (or TRUE) |
error “object ‘cint’ not found” (with both samples below 50 values R takes the exact branch, which skips the interval with ties) | the normal-approximation interval and estimate, the same as with exact: false, with R’s two warnings before it stops (“cannot compute exact p-value with ties”, “cannot compute exact confidence interval with ties”, “intervals” before R 4.6) |
ansari.test(c(1, 2), c(-1, -2), exact = FALSE, conf.int = TRUE) (no positive ratio of the samples: all x on one side of 0 and all y on the other; #506) |
the warning “samples differ in location: cannot compute confidence set, returning NA”, then the error “invalid ‘xmin’ value” | NaN limits and estimate, as the exact interval on such data, with the warning “samples differ in location …” (not R’s warnings of min and max of no values before it); the statistic and p-value as R |
ansari.test(c(1, 2, 3), c(-1, -2, -4), conf.int = TRUE) (exact, no ratio x / y >= 0 of the samples: all x on one side of 0 and all y on the other) |
the warning “cannot compute confidence set, returning NA”, then the error “object ‘absigma’ not found” | NaN limits and estimate, with the warning “cannot compute confidence set, returning NA”; the statistic and p-value as R computes them before it stops |
ansari.test(c(1e-308, 1.2e308, 1.3e308, 1.4e308, 1.5e308), 1.1e308, conf.int = TRUE) and ansari.test(c(-2e-160, -1e-160, 1e-160, 2e-160, 1e140), c(5e-150, -5e-150), conf.int = TRUE) (for a finite trial ratio s, x / s overflows to Inf or falls to 0, tying distinct observations in the ranks of AB(s)) |
estimate 0.6364; interval [2e-11, 4e-11] | estimate 1.3182 and interval NaN (no confidence set), as data with the same order and no overflow (c(1e-308, 1.2, 1.3, 1.4, 1.5) against 1.1; 1e-140 for 1e140): only there the ranks come from a comparison of x / s that keeps the order (#507) |
weighted.mean(c(1e308, 1e308), c(1, 1)) and other sums that overflow; weighted.mean(c(1e-308, 2e-308), c(1e308, 1e308)), where only the sum of the weights overflows; weighted.mean(c(1e308, 1e308, 1e308), c(1e308, -1e308, 1e-308)), signed weights that cancel; weighted.mean(1e-200, 1e-200), where the product underflows |
Inf; 0; NaN; 0 | 1e308; 1.5e-308; 1e308; 1e-200 (the sums of the products and of the weights formed exactly, and their quotient rounded once) |
fivenum(c(1e308, 1e308)), hist(...)$mids, the Kaplan-Meier median, the Hodges-Lehmann estimate and the midrange of wilcox.test, the default mode of the triangular distribution, the monoH.FC slopes of splinefun (all (a + b) / 2) |
Inf when a + b overflows | the midpoint, as a / 2 + b / 2 when a + b overflows |
hist(c(-1e308, 1e308), breaks = c(-1e308, 0, 1e308))$counts (at most 3 breaks, the data range overflows) |
(2, 0) (the counting fuzz 1e-7 times the range is Inf) | (1, 1): the fuzz from half the range, doubled |
hist(c(-1e308, 1e308), breaks = "Scott"), breaks = "FD" (finite data whose range and Scott or Freedman-Diaconis width overflow) |
error “invalid number of ‘breaks’” (Inf / Inf) | breaks (-1e308, 0, 1e308): the number of cells from the range and width of the data divided by a power of 2 (for FD, the data rounded to 5 digits first) |
hist(c(-1e308, 1e308), breaks = c(-1e308, 1e308))$density (a cell whose width overflows); hist(c(0, 1e308), breaks = c(0, 1e308))$density (n times the width overflows) |
0; 0 | 5e-309; 1e-308 (from the width, or half of it, scaled by a power of 2, rounded once) |
e1071’s skewness, kurtosis on data around 1e150 |
NaN (the powers overflow) | the value at any scale (the deviations rescaled by a power of 2) |
scale(c(1e200, 2e200, 3e200)), scale(c(1e-200, 2e-200, 3e-200)) |
scale Inf or 0, scaled values 0 or ±Inf | -1, 0, 1 (the sum of squares rescaled) |
runif(n, -1e308, 1e308) |
Inf (max - min overflows) | values in the range |
kappa() of a matrix around 1e308 such as 1e308 * matrix(c(1, 0, 1, 1), 2) (the default QR estimate, method = "direct", triangular = TRUE, exact = TRUE, norm = "1") |
error (“NA/NaN/Inf in foreign function call”), Inf, error (“computationally singular”) | the condition number of the matrix itself (3.33, 3.33, 4): the matrix divided by a power of 2 first |
optimHess(0, function(x) 1e200 * x, function(x) 1e200, control = list(parscale = 1e200, fnscale = 1e300)) (an analytic gradient whose product with parscale overflows, the scaled gradient 1e100 being finite) |
NaN (Inf - Inf) | 0 (the gradient divided by fnscale first there; issue #498). The same scaling of gr in optim |
optimHess(0, function(x) 0.5e-200 * x * x, function(x) 1e-200 * x, control = list(parscale = 1e200, ndeps = 1e200)) and optimHess(0, function(x) 0.5e8 * x * x, function(x) 1e8 * x, control = list(parscale = 1e200, ndeps = 1e100)) (the denominator 2 step parscale_i parscale_j, or the difference of the scaled gradients, overflows where the Hessian is representable) |
0 and Inf | 1e-200 and 1e8 (only there the quotient is formed from factors scaled by powers of 2; issue #503) |
optimize(function(x) x^2, c(-1, 1), tol = 5e-324) (a tol whose third underflows) |
does not return (the step rounds to 0 among the subnormals) | 0 (the search ends where a step no longer moves) |
seq(1, 2, by = Inf); seq(1, 2, by = -Inf) (a step pointing away from to) |
NaN; NaN | 1; error “wrong sign in ‘by’ argument” |
seq(-1e308, 1e308, by = 5e307) |
the middle value -1.9958e292 | 0 (the ends’ difference overflows: the values are those of the halved ends, doubled) |
eigen() of a small nonsymmetric matrix such as matrix(c(1, 3, 2, 4), 2) * 1e-60 |
treated as symmetric (isSymmetric compares absolutely when mean |a| <= 100 eps): wrong eigenvalues |
the symmetry test made relative at every scale (isSymmetric() itself is R’s) |
merge() on several keys whose values contain “\r”, or NA against the text “NA” |
rows with different keys matched (the keys are pasted with “\r”) | matched only on equal keys |
JonckheereTerpstraTest (DescTools) two-sided |
can exceed 1 | at most 1 |
JonckheereTerpstraTest (DescTools 0.99.60) exact p-value on R 4.6 |
negative: -1.727 for three groups of six with no ties (x of the demo example more-tests); R 4.5.2 gave 9.3277404228e-7 |
the exact p-value 9.327740420177e-7, as clinfun’s jonckheere.test on R 4.6.2 |
distSummary’s mean of unif(-1e308, 1e308), variance of beta(1e150, 1e150), skewness of triang(-1e308, 1e308, 0) and triang(0, 3e120, 1e120) |
Inf, 0, NaN, NaN | 0, 1.25e-151, 0, 0.3054 (the skewness from the parameters divided by a power of 2) |
aov(y ~ x + w + Error(id/w)) with a covariate x in small units (x * 1e-4) |
the x row disappears (a column is kept in a stratum when its projection’s squared length exceeds 1e-5) | the same table at any scale of x (the threshold is 1e-14 times the column’s own squared length; 1e-5 times its mean square, used before, also dropped the small within-subject part of a covariate that varies mostly between subjects) |
t.test, oneway.test, var.test, bartlett.test, PMCMRplus’s tukeyTest/gamesHowellTest, pairwise.t.test on data around 1e-200 or 1e155 |
“data are essentially constant”, or NaN (the variances underflow to 0 or their squares overflow) | the result at any scale (the data rescaled by a power of 2, which is exact) |
The Welch degrees of freedom of t.test, gamesHowellTest, cohensD and ICC’s two-way bounds, data around 1e±150 |
NaN (fourth powers of the standard errors) | the same df at any scale |
chisq.test(c(1e200, 1e200), p = c(0.1, 0.9)), chisq.test(matrix(1e200, 2, 2)), and the Pearson terms of mcnemar.test, prop.test, mantelhaen.test |
Inf or NaN (the squared deviation or the product of the margins overflows) | 3.56e200, 0 (formed as (d / sqrt(e))^2 or (a / n) b when needed) |
mcnemar.test(matrix(c(0, 8e307, 1e308, 0), 2)) (the sum of a discordant pair overflows) |
NaN | 2.22e306 (that pair’s term in units of 2^520 for the difference and 2^1040 for the cells, which is exact and needs no scaling back) |
prop.test(c(6e307, 4e307), c(1e308, 1e308), correct = FALSE) (the total of the trials overflows) |
Inf (the pooled proportion is 0) | 8e306 (both totals in units of 2^s, 2^s >= the number of groups, for the pooled proportion) |
chisq.test(c(1e308, 1e308)) and other goodness-of-fit tests whose total count overflows |
NaN (the expected counts are Inf) | statistic 0, expected counts 1e308 (the counts in units of 2^s, 2^s >= the number of cells and s even; the expected counts and the statistic scaled back by 2^s, the residuals by 2^(s/2)) |
chisq.test(c(1, 1), p = c(1e308, 1e308), rescale.p = TRUE) (the total of the finite weights overflows) |
statistic Inf, p-value 0 (each weight divided by Inf is 0) | statistic 0, p-value 1 (the weights in units of 2^e, 2^e >= the number of cells, before the division; issue #303) |
afex’s aov_ez and mauchly.test with the response in other units (1e-4 times, or around 1e±100) |
the sphericity corrections and Mauchly’s test disappear (car’s absolute eigenvalue threshold), or W is NaN | the same epsilons and W at any scale (the rank judged relative to the largest eigenvalue and to the sum of squares of the data; W as det(U / (trace(U)/p))) |
coxph(Surv(time, status) ~ x1 + x2) with covariates in very different units (x1 * 1e7 or x1 * 1e-6, x2 as is) |
the Wald test drops a covariate (3.36 becomes 0.31 or 3.08: the Cholesky pivots of the variance in the original units fall below the relative tolerance); at x1 * 1e200 the standard error underflows to 0 (z Inf, p 0), at x1 * 1e-160 “infinite argument in coxph.wtest” | the same z, p and Wald test at any scale (the variance, z, the Wald test and the check for infinite coefficients formed in units of a power of 2 of each covariate’s scale; the coefficients, the variance and the standard errors scaled back for output) |
zTest (BSDA’s z.test), effectsize’s cohens_d/hedges_g, irr’s icc, psych’s alpha, nortest’s ad.test/cvm.test/lillie.test/sf.test/pearson.test, aov, TukeyHSD, car’s leveneTest, lm, anova, aov(... + Error()), afex’s ges, TOSTER’s t_TOST and tsum_TOST on data around 1e±200 |
NaN, 0, ±Inf or a different test result (squares of the data overflow or underflow) | the result at any scale (the data scaled by a power of 2 before the mean is subtracted; sums of squares, MSE, standard errors and intervals scaled back for output) |
cov(c(MAX, MAX, -MAX), c(-1e-308, -1e-308, 1e-308)) (MAX the largest double), and a paired t.test of values of opposite sign near the largest double |
-Inf or NaN (the deviation, or the difference, overflows before any rescaling) | about -2.3969 and a correlation of -1; the paired test as at any other scale |
t.test(x, mu = 1e100), and t.test(1:4, mu = 1e6) (mu far larger than the interval) |
interval [0, 0]; [0.44573974329978228, 4.5542602567002177], 1.4e-10 off (formed as mu + (t ± q) stdErr; NaN for an infinite mu) | the interval about the estimate, which does not depend on mu: [0.44573974323947896, 4.5542602567605215]. Only where mu or t stdErr exceeds 16 times abs(estimate) + q stdErr, or R’s end is not finite; elsewhere R’s form and bits |
car’s Anova (types II and III), predict(lm) standard errors and intervals, gaussian glm and summary, residuals, rstandard, cooks.distance, predict, anova, confint of it, DescTools’ CoefVar and MeanAD, with the response around 1e±200 |
Inf, 0 or NaN, “residual sum of squares is 0”, or “no valid set of coefficients has been found” | the result at any scale (the response scaled by a power of 2; for glm on the gaussian family, or quasi with constant variance, on the identity link) |
pnorm(1e308, -1e308, 1.7e308), qnorm(0.9, -1e308, 1.7e308), and the same for plogis/qlogis, pcauchy/qcauchy, extraDistr’s plaplace/qlaplace/dlaplace: x - location or scale z overflows although the result is in range |
1, Inf, 0 or -Inf (pnorm 1, dnorm 0, qnorm Inf confirmed in R 4.5.2) | 0.8803, 1.1786e308 (x and location halved, or location and scale divided by a power of 2, before the subtraction or product) |
quade.test(y) where a block (row) has a missing value, e.g. y <- rbind(c(10,12,15), c(11,14,16), c(12,NA,17), c(13,15,18), c(14,16,20)) |
F = 10, df (2, 8), p = 0.00666: the dropped block still counts in b (B = sum S_j^2 / b, (b - 1) B / (A - B), df (b - 1)(k - 1)), so the result differs from quade.test(y[-3, ]) (F = 25, df (2, 6), p = 0.00123) for the same data; a bug in R (4.5.2, checked by running it) |
the test on the complete blocks: F = 25, df (2, 6), p = 0.00123, as for the data without the block |
rt(n, Inf, ncp = 1), rf(n, Inf, 10, ncp = 2), rf(n, 10, Inf, ncp = 2) (noncentral, an infinite df) |
NaN (“NAs produced”; the central rt(n, Inf) and rf(n, Inf, 10) do give values) |
the limits: N(ncp, 1) for t; for F the chi-squared over its infinite df is 1 (X / df1, df2 / Y, or 1). The same variates are drawn as in R, so the stream after the call is R’s |
rf(n, 0, 10, ncp = 2) (noncentral, df1 = 0), rsignrank(n, Inf) |
Inf or NaN depending on the draw (division by df1 = 0; the central rf gives NaN); an undefined integer cast of Inf |
NaN (F needs df1, df2 > 0; the same variates are drawn as in R, so the stream after the call is R’s); NaN without drawing |
expm’s expm(matrix(c(1e308, 0, 0, 0), 2), method = "Higham08") |
NaN in every entry (Inf * 0 in the squaring) | diag(Inf, 1): an overflowed entry stands for a finite value, so its product with an exact 0 is 0; a matrix whose 1-norm overflows no longer loops forever |
expm’s expm(matrix(c(0, 1e-308, 1e308, 0), 2), method = "Higham08") (also with 1e±200; the scaling A / 2^s before the Padé approximant takes the entry 1e-308 below the normal range; issue #207) |
[[1, 1e308], [0, 1]] (the exponential of a nilpotent matrix) | [[cosh 1, 1e308 sinh 1], [1e-308 sinh 1, cosh 1]], the same bits as the default “Higham08.b”: only where that scaling would take a nonzero entry below 2^-1022, “Higham08” balances internally (dgebal’s job “S”, a diagonal similarity by powers of 2) and transforms back. Other matrices are not balanced, as in R |
expm’s expm(matrix(c(0, 0, 2^-1074, 0), 2), method = "Taylor") (any order, also “TaylorO”; issue #404) |
the identity matrix: the scaling by N = 2^p with p >= 5 takes the entry to 0 (1e-310 loses its last digits: 9.9999999999945e-311) | [[1, 2^-1074], [0, 1]] (the exponential I + A of this nilpotent matrix), and 1e-310 exactly: only where A / 2^p would take a nonzero entry below 2^-1022, p is the smallest with 2^p >= 16 nu (nu = sqrt(1-norm x infinity-norm)) and p >= 0, instead of p >= 5. “Pade” uses the same p (1e-310 gives 1.00000000000005e-310, R 1.00000000000103e-310), but still loses 2^-1074 (its first coefficient 1/2 halves it). Other matrices keep R’s p |
expm’s expm(matrix(c(0, 0, 1, 0), 2), method = "Pade", order = 0) (also “Taylor”, “PadeO”, “TaylorO”) |
the identity matrix (the answer is [[1, 1], [0, 1]]) | an error: order must be a positive integer for these methods (the Higham08 methods ignore it, as in R). A matrix of 2 x 2 or larger with NaN or infinite entries is an error for every method (the Padé and Taylor methods gave NaN) |
rcond(matrix(c(1e308, 0, 1e308, 1e308), 2)) and other matrices whose norm overflows (also triangular = TRUE, and solve’s condition check) |
error -5 from dgecon (0 with triangular = TRUE); solve of that matrix stops as computationally singular (rcond = 0) |
0.3, as for the matrix divided by a power of 2 (the reciprocal condition number does not depend on the scale); solve gives (0, 1e-308) |
qr(matrix(1e308, 2, 2)) (also LAPACK = TRUE), and lm(y ~ x) with x near 1e308 (x = c(1e308, 5e307, 3e307, 8e307), y = c(1, 3, 2, 4)) |
rank 2 and R[, 2] = -Inf (the Householder products overflow); lm: NaN coefficients (glm: an error) |
rank 1 and R = [-1.414e308, -1.414e308; 0, 0]; lm and glm: (2.948, -6.897e-309), the fit of x / 2^1000 scaled back. Where the decomposition of a finite matrix is not finite, it is made again with each column beyond [2^-256, 2^256] divided by a power of 2 (LINPACK; its tests are relative to each column) or the whole matrix (LAPACK), and R scaled back |
qr.solve(qr(matrix(c(1, 2, 2, 4), 2), LAPACK = TRUE), c(3, 6)) (a LAPACK decomposition of deficient rank) |
(8, -2.5): the rank of a LAPACK decomposition is always min(n, p) | “singular matrix in qrSolve”: abs(R_kk) <= tol abs(R_11) (tol 1e-7) counts as deficient rank |
kappa(matrix(c(1, 2, 2, 4), 2), exact = TRUE, norm = "1") (exactly singular, a norm other than 2) |
“system is exactly singular” | Inf, as with norm “2” (a computationally singular matrix still stops, as in R) |
anova(lm(y ~ x2), lm(y ~ x1 + x3)) and anova() of glm fits that are not nested (neither model is a special case of the other) |
an F test (F 1110, p 4.6e-7 in the example), or a likelihood ratio test for glm | no test: F, the p-value and the test columns are NaN, as lmerAnova (nested: the columns of the model with fewer parameters lie in the column space of the other, judged by the QR rank on the rows of positive weight: rows of weight 0 are not in the likelihoods) |
anova() of glm fits with different offsets (glm(y ~ 1, poisson) and glm(y ~ x, poisson, offset = log(y) - x/2)) |
a likelihood ratio test (p = 0.000417) | no test (NaN): the fits are nested only when the difference of the offsets also lies in the column space of the larger model, as for the columns |
cooks.distance(glm(y ~ x, binomial), dispersion = 1e308), and Cook’s distances whose (r / (1 - h))^2 overflows (a binomial fit with prior weights 1.5e306, which R does not fit) |
0 for every row (h / (dispersion p) underflows) | 1.4e-309, …, 9.0e-307 (the distances for dispersion 1 divided by 1e308) and 1.35e308: where the square overflows or h / (dispersion p) is below the normal range, the residual and the dispersion in units of powers of 2 |
glm where a part of the working weight w mu.eta(eta)^2 / V(mu) overflows or underflows although the weight does not: poisson y = c(1e308, 1e308), Gamma (inverse link) y = c(1e308, 1e308), inverse.gaussian (log link) with a mean of 1e200 or of 1e-200, a poisson mean of 1e-320 (offset log(1e-320)) |
“NA/NaN/Inf in ‘x’” (poisson, Gamma); working weight NaN (mean 1e200); converged at the clamped mean 2.2e-16 with deviance 2e200 (mean 1e-200); the mean and weight clamped to 2.2e-16 (1e-320) | the fits: log(1e308) = 709.196 with null deviance 0; 1e-308; the weight 1/mu = 1e-200; the mean 1e-200; the weight 1e-320. Where mu.eta^2, V(mu) or w mu.eta^2 is outside the normal range, the weight is sqrt(w) abs(c) mu^((2a - p)/2) from mu.eta = c mu^a and V = mu^p (identity, log, inverse, sqrt, 1/mu^2 and power links; variances 1, mu, mu^2, mu^3), and so the working and Pearson residuals; V = mu^p underflowing for a positive mean is no longer “0s in V(mu)”; the null model’s mean divides the response by a power of 2 where its weighted sum overflows. The binomial links keep R’s form. For the Gamma fit the working weight mu^2 = 1e616 itself is beyond the doubles: the weights are Inf, and the dispersion and standard errors NaN |
shapiro.test(c(-1e308, 0, 1e308)) (the range overflows) |
NaN | W = 1, as shapiro.test(c(-1, 0, 1)) (the data divided by a power of 2 first) |
polycor’s polyserial(x * 1e200, y, std.err = TRUE) (the sum of squares overflows) |
rho 0, chisq NaN | the values for x (for example rho 0.589) |
rexp(n, rate = 1e-310) (positive rate, 1 / rate overflows) |
NaN, with a warning, drawing nothing | the variates exp_rand() / rate (Inf unless the exponential variate is below about 0.018), one exponential variate each |
rnorm(1, mean = -1e308, sd = 1e308) after set.seed(7) (sd Z overflows, mean + sd Z does not; issue #396) |
Inf | 1.2872471613405238e308 (only where mean + sd Z is not finite: the same sum with mean and sd halved, doubled; the same draws) |
rweibull(1, shape = 0.001, scale = 2^-1074) after set.seed(19) ((-log u)^(1/shape) overflows, the variate does not; issue #408) |
Inf | 103020481.1280669 (only where the power overflows: scale (-log u)^(1/shape) from the logs in double-double; the same uniform) |
rgamma(1, 0.001, scale = 2^1023) and extraDistr’s rinvgamma(1, 0.001, 2^-1023) after set.seed(1) (shape below 1: the unit variate p^(1/shape) underflows, the scaled one does not; issue #409) |
0 and Inf | 1.5563963702389774e-268 and 6.4250985103907345e267 (only where p^(1/shape) is below the normal range and scale > 1: scale p^(1/shape) from the logs in double-double; the same draws and acceptance) |
rcond(diag(c(1, 1e-310))) and other nonsingular matrices whose inverse has a norm beyond the doubles (also triangular = TRUE, a non-square matrix, and solve’s condition check) |
0 | 1e-310: where a product with the inverse overflows in the estimate, it is repeated with every vector divided by a power of 2 (exact) and the result scaled back; 0 only if it overflows again |
backsolve(diag(1e-308, 2), c(1, 2)), forwardsolve(..., transpose = TRUE) (also solve) |
NaN, Inf (0 * Inf from the overflowed component); solve stops with rcond = 0 |
1e308, Inf: coefficients of exactly 0 are skipped, as an overflowed component stands for a finite value |
solve(1e308 * matrix(c(1, 1, 1, -1), 2), c(1, 0)) and the inverse (the elimination overflows: -1e308 - 1e308), and solve(matrix(c(1, 1, 1, -1), 2), c(1.7e308, -1.7e308)) (the substitution overflows) |
(1e-308, 0) and an inverse with 0; -Inf, Inf | (5e-309, 5e-309) and the inverse (±5e-309); (0, 1.7e308): where U or the solution is not finite for finite input, from the LU of the matrix divided by a power of 2 (the one the condition check uses), with the right-hand side divided by the power of 2 of its largest entry if needed, scaled back once at the end |
prcomp(c(1e308, -1e308, 1e308, -1e308))$sdev (the singular value overflows) |
Inf | 1.1547005383792517e308 (the decomposition of the matrix divided by a power of 2) |
sd(c(-1e308, -1e308, -1e308, -1e308, 1.5e308)) (the variance overflows), sd(c(1e-200, 2e-200, 4e-200)) (it underflows); e1071’s skewness, kurtosis and the CV of such data |
Inf, 0; NaN or 0 | 1.118e308, 1.53e-200 (sd from the deviations in the coordinates 2^-k); the moments and the CV as at any scale |
scale(x) and prcomp(x) of the same data, where a deviation from the mean (2e308) overflows |
scale: NaN, scale Inf; prcomp: an error from svd |
scale: [-0.447, …, 1.789], scale 1.118e308; prcomp: sdev 1.118e308, the score that is out of range Inf (computed in the coordinates 2^-k) |
determinant(diag(c(1e308, 1e308, 1e-308, 1e-308)), logarithm = FALSE) |
modulus Inf (the running product overflows) | 1 (the product keeps a binary exponent apart) |
matrix(c(1e308, 1e308), 1) %*% matrix(c(1e308, -1e308)), and the off-diagonal entries of crossprod(x), tcrossprod(x) for x <- matrix(c(1e200, 1e200, 1e200, -1e200), 2) (the products overflow, the sum does not); matrix(c(1e308, 1e308, 1e-308), 1) %*% c(1e308, -1e308, 1e308) (the large products cancel; issue #208) |
NaN | 0; 0.9999999999999999 (the double 1e-308 * 1e308). Such entries are summed again exactly: each product as an integer times a power of 2, summed in BigInt and rounded once (only where the plain sum is not finite) |
predict(lm(y ~ x1 + x2 - 1), data.frame(x1 = 1e308, x2 = 1e308)) with x1 = c(1, 0, 1), x2 = c(0, 1, 1), y = c(2, -2, 0) (coefficients 2 + 1 ulp and -(2 + 2 ulp): the products overflow and cancel; issue #195) |
NaN | -4.440892098500626e292 (the exact value for these coefficients, Rmpfr; the exact inner product of the matrix products, only where the plain sum is not finite) |
The fitted value of a row of weight 0 where the products overflow and cancel: lm(y ~ 0 + a + b, weights = c(1, 1, 1, 0)) with a = c(1, 0, 1, 1e308), b = c(0, 1, 1, 1e308), y = c(1.9, -1.9, 0, 0) (R’s coefficients 1.9 and -(1.9 + 3 ulp); issue #193) |
fitted and residual of row 4 NaN | the matrix form (the same coefficients as R): -6.661338147750939e292 and its negation, the exact x’b for these coefficients as predict (only where the plain sum is not finite); the formula form: 0 (its double-double coefficients are exactly 1.9 and -1.9) |
predict(glm(y ~ x1 + x2, gaussian), data.frame(x1 = 1e308, x2 = 1e308)) with x1 = c(0.5, 0, 0.5), x2 = c(0, 0.5, 0.5), y = c(2, -2, 0) (glmPredict with newdata; slopes 4 + 2 ulp and -(4 + 1 ulp) in rStats.js, 4 + 1 ulp and -(4 + 1 ulp) in R: the products overflow and cancel; issue #174) |
NaN | 8.881784197001252e292 (the exact value for these coefficients, Rmpfr; the exact inner product as predict for lm, only where the plain sum is not finite) |
crossprod(rep(1e-162, 100)) (also tcrossprod, %*%, and predict for lm and glm with new data; each product 1e-162 * 1e-162 rounds to 0 although the sum is representable; issue #395) |
0 | 1e-322, the exact inner product rounded once (crossprod(rep(1e-160, 3), rep(3e-161, 3)): 9e-321, R 8.997e-321). The exact sum of the rows above is also taken where the plain sum is below 2^-969 in magnitude and a product of nonzero factors fell below 2^-1022 (each such product is off by up to 2^-1075, which a larger sum rounds away). “Below 2^-1022” is the exact product: one that rounds up to 2^-1022 counts (crossprod(rep(2^-511, 100), rep(2^-511 (1 - 2^-53), 100)) is 0x1.8ffffffffffffp-1016, R 0x1.9p-1016; issue #465). A sum that cancels in the normal range keeps the plain value (crossprod(c(1e16, 1, -1e16), c(1, 1, 1)) is 0, as R) |
predict(lm(y ~ 0 + x), data.frame(x = 1e200), se.fit = TRUE)$se.fit with x = c(1e-200, 2e-200, 3e-200), y = c(1e-200, 2e-200, 4e-200) (R^-T x about 1e400 before the residual standard error 4.2e-201 is applied; issue #196) |
NaN (R’s residual standard error underflows to 0) | 1.1293848786315636e199 (Rmpfr 1.12938487863156401e199; only where R^-T x is out of range, solved again with x divided by a power of 2); with x = c(1e200, 2e200, 3e200), y = c(1e100, 2e100, 4e100) at x = 1e-200: R 0, rStats.js 1.129384878631563e-301 |
predict(glm(y ~ x1 + x2, gaussian), data.frame(x1 = 1.5e308, x2 = 1.5e308), se.fit = TRUE, dispersion = 1e-300)$se.fit with x1 = c(0, 1, 0, 1), x2 = c(0, 0, 1, 1), y = c(0, 1, 1, 2) (glmPredict; the norm of R^-T x about 2.1e308 before sqrt(dispersion) is applied; issue #175) |
Inf | 2.1213203435596427e158 (the value for newdata divided by 2^100, times 2^100; only where the product in the fallback for overflowing squares is not finite, sqrt(dispersion) is applied to the norm first) |
lm(y ~ x, weights = c(2, 2, 2)) with x = c(0.7e308, 0.8e308, 0.9e308), y = c(1, 2, 3) (sqrt(w) x has a column norm 1.97e308; issue #199), and lm(y ~ x) on the same data in the formula form (the double-double refit squared the column) |
NaN coefficients (also without weights) | -5.999999999999999 and 1e-307 in the formula form (Rmpfr -5.99999999999999933, 9.99999999999999889e-308), -5.999999999999992 and 9.999999999999993e-308 in the matrix form with weights; where the weighted decomposition is not finite, qr is that of the weights divided by 2^qw (the largest weight in [1/4, 1)), which predict takes into account |
optimize(function(x) (x / 1e308 - 1.05)^2, c(1e308, 1.1e308)) (lower + upper overflows) |
does not return (the midpoint is Inf) | 1.05e308 (the search in x/2) |
optimize(function(x) (x / 1e308 + 1.6)^2, c(-1.7e308, 1e306)) (lower + upper is finite, but an end is beyond .Machine$double.xmax / 2, so the midpoint of the bracket narrowed near it overflows; issue #212) |
does not return | -1.5999999916130706e308 in 38 evaluations (the search in x/2 also where an end is beyond half the largest double) |
approx(c(-1e308, 1e308), c(0, 1), n = 3), approx(c(0, 1), c(-1e308, 1e308), xout = 0.5), spline(c(-1e308, 1e308), c(0, 1), n = 3) (differences of finite values overflow) |
y 0, 0, 1; Inf; spline 0, 0, NaN | 0, 0.5, 1; 0; 0, 0.5, 1 (the differences in half coordinates; the spline in x / 2^k) |
splinefun(c(-1e308, 1e308), c(0, 1))(0) (every method), splinefun(c(-1.5e308, 0, 1.5e308), c(0, 1, 0), method = "periodic")(0), splinefunH(c(-1e308, 1e308), c(0, 1), c(0, 0))(0) (the range of the knots overflows; issue #125) |
0 (fmm, natural), NaN (hyman, monoH.FC, splinefunH); periodic 0 | 0.5; periodic 1 (built in x / 2^k, derivatives of order d brought back by 2^(-d k); splinefunH keeps the given slopes). spline takes the same condition (the range, not only neighbouring spacings) |
spline(c(0, 2), c(-1e308, 1e308), xout = 1), splinefun(c(0, 2), c(-1e308, 1e308))(1) (fmm, natural with two knots), splinefunH(c(0, 2), c(-1e308, 1e308), c(0, 0))(1, deriv = 1) (the difference of the ordinates overflows; issue #380) |
Inf | 0; 0; 1.5e308 (the secant from the halved ordinates) |
splinefun(c(0, 1, 5), c(0, 2e-199, 4e-199), method = "hyman")(5, deriv = 1) (the product of the two neighbouring secants, 2.5e-399, underflows; issue #398) |
-7e-200 (the limiter takes the sign of the fmm slope: a negative derivative for increasing data) | 0 (the signs of the secants compared, not their product) |
splinefunH(c(0, 1e200), c(0, 0), c(1e200, 1e200))(5e199, deriv = 3) (h^2 overflows; issue #399) |
12 (R divides the third derivative by h once, see “Third derivative of a cubic Hermite spline” below) | 1.2e-199 (divided by h twice where h^2 is not a normal number; was 0) |
splinefunH(c(0, 1e200), c(0, 0), c(1e200, 1e200))(1e100) (h m = 1e400 overflows before the basis factor 1e-100; issue #400) |
NaN | 1e300 (where such a term is not finite, h, m and the basis factor multiplied with their exponents apart) |
splinefunH(c(0, 1e-200), c(0, 1e200), c(0, 0))(1e-300, deriv = 1) (the secant 1e400 overflows before the basis factor 6e-100; issue #401) |
Inf | 6e300 (where the secant is not finite for finite ordinates, the difference times the basis factor over h with the exponents apart) |
splinefunH(c(0, 1e-200), c(0, 1e200), c(0, 0))(5e-201, deriv = 2) (the secant 1e400 overflows before the basis factor 6 - 12 t = 0; issue #466) |
NaN | 0 (as the first derivative of #401: the difference times the basis factor over h^2 with the exponents apart) |
splinefun(c(0, 1, 2), c(0, 1e-200, 1e200), method = "monoH.FC")(0.5) (the ratio of the slope to the secant, 5e399, overflows and the Fritsch-Carlson test Inf < Inf skips the limiter; issue #397) |
-6.25e198 (not monotone) | 1.25e-201 (only where the ratios or their products overflow, the test and the limited slopes from the ratios divided by a common power of 2) |
rbeta(n, 1e308, 1e308, ncp = 0) (2 shape overflows) |
NaN | 0.5 (the chi-squared variates halved, with R’s draws) |
rgeom(n, 1e-309), rnbinom(n, 1, prob = 1e-309), rnbinom(n, 0.5, mu = 1e308) ((1 - p) / p or mu / size overflows) |
NA or NaN, drawing nothing after it | the variates (e.g. 1.716e308 for set.seed(4)): the exponential or unit gamma variate times 1 - p, divided by p; Infinity only where the mean itself overflows. The draws of the Poisson step are made, so the stream departs from R’s only there |
rmultinom(n, size, c(0.5, 0.5, 1e-16)) (the probabilities sum to 1 in doubles) |
the second category takes all that is left (p = 1), and the third is never drawn | the second is a binomial draw with 0.5 / (0.5 + 1e-16), from the probabilities of the remaining categories summed from the end (the stream departs from R’s only in such cases) |
summary(glm(...), dispersion = -1) (also glmAnova, glmPredict, glmRstandard, glmCooksDistance) |
NaN standard errors, with a warning | an error: the dispersion must be a non-negative finite number (0 gives standard errors of 0, as R) |
pwr.chisq.test(w = 1e200, N = 100, df = 3), pwr.f2.test(f2 = 1e308), pwr.anova.test(f = 1e200) (the noncentrality overflows) |
NaN | 1, the limit of the power; powerAnovaTest takes between.var / within.var first where only the product overflows |
pwr.2p2n.test(h = 1e-100, n1 = 1e200, n2 = 1e200) (n1 n2 overflows) |
1 | 0.10895461755061556: where the product overflows (finite sizes), the effective size n1 n2 / (n1 + n2) as a / (1 + a / b) with a <= b |
ES.w1(c(0.5, 0.5, 0), c(0.5, 0.5, 0)) and ES.w2 with an empty row or column (cells with both probabilities 0) |
NaN (0 / 0) | such a cell adds 0 (0 here); p0 = 0 < p1 still gives Inf, as R |
ES.w1(c(1e-320, 1), c(1e-200, 1)) ((p1 - p0)^2 underflows; issue #264), ES.w1(c(0, 1), c(1e-300, 1)) |
0; NaN (0 / 0) | 1.0000055664551364e-40 (Rmpfr 1.00000556645513627e-40); Inf (p0 = 0 < p1, as for larger differences): where the square of the difference is below the normal range, the term is (d / sqrt(p0))^2 |
ES.w2(matrix(c(1e-200, 0, 0, 1), 2)) (the expected cell probability r c = 1e-400 underflows; issue #265), ES.w2(matrix(c(1e-160, 1e-170, 1e-170, 1), 2)) (r c subnormal) |
NaN (0 / 0); 1 | 1; 0.9999999998999998 (Rmpfr 0.99999999989999997): where r c is below the normal range (and the row and column sums are not 0), the term is (p / sqrt(r c) - sqrt(r c))^2 from the square roots of the sums |
pwr.r.test(n = 4, r = 0.5, sig.level = 1e-320) (the critical t, 7.07e159 with 2 df, overflows when squared; issue #269) |
NaN (R’s qt also gives Inf for such a subnormal probability) |
0: where t^2 + n - 2 overflows for a finite t, the critical correlation is 1 / sqrt(1 + ((n - 2) / t) / t) (1 here), and the power underflows to 0 |
power.anova.test(groups = 3, n = 1e308, between.var = 1, within.var = 1e308) ((groups - 1) n overflows, the noncentrality is 2; issue #272) and between.var = 0 there |
NaN; NaN | 0.2255449157695638 (R’s pchisq for the noncentrality 2 with 2 df: 0.22554491576956397; df2 is Inf); 0.05 (the noncentrality 0): where (groups - 1) n between.var / within.var is not finite even with the ratio first, the four factors are scaled by powers of 2 |
power.anova.test(groups = 1e200, n = 1e200, between.var = 1e8, within.var = 1e308) (df1 = 1e200, df2 = Inf, the noncentrality 1e100; issue #272) and power.anova.test(groups = 1e17, n = 2, between.var = sqrt(1e17) / 1e17, within.var = 1) (both degrees of freedom above 1e16) |
NaN; 1 (with a warning that pnchisq did not converge) | 0.17418726161793208 (pnorm(qnorm(0.95) - 1 / sqrt(2), upper) = 0.1741872616179323 to O(1e-100); before: 0.760); 0.2595110241630547 (a 256-bit reference 0.25951102181670718; before: 0.2595111267699508): where both degrees of freedom exceed 1e16 (groups - 1 > 1e16), the power is that of the normal approximation of F, as for pwr.anova.test and pwr.f2.test (#200, #202) |
pwr.f2.test(u = 1e308, v = 1e308, f2 = 1e-308) (u + v overflows, the noncentrality is 2; issue #202) and pwr.f2.test(u = 1e24, v = 1e24, f2 = 1e-12) (both degrees of freedom above 1e16) |
NaN; 1 (with a warning that pnchisq did not converge) | 0.04999999999999999 (the limit 0.05 + 1e-155); 0.25951102284186195 (before: 0.2591899066123998; 0 for 1e32 and above): where u + v overflows for finite values, the noncentrality is 2 f2 (u / 2 + v / 2 + 0.5); where both degrees of freedom exceed 1e16, the critical value of F keeps only a few digits beyond 1 in doubles (and rounds to 1 above about 1e33), and the power is that of the normal approximation of F (mean 1 + ncp / u, variance 2 (1 + 2 ncp / u) / u + 2 (1 + ncp / u)^2 / v), whose error there is O(1 / sqrt(u)): against Rmpfr, 2.3e-9 at u = v = 1e17 and 7e-11 at 1e20, where the exact path pf(qf(…)) was off by 1e-7 and 3e-6 (R gives 1 there, with the warning) |
pwr.anova.test(k = 1e160, n = 1e160, f = 1e-160) (k n overflows, the noncentrality is 1; issue #200), pwr.anova.test(k = 3, n = 1e308, f = 1e-154) and pwr.anova.test(k = 1e40, n = 2, f = 1e-10) (both degrees of freedom above 1e16) |
NaN; NaN; 1 (with a warning that pnchisq did not converge) | 0.04999999999999999 (the limit 0.05 + 7e-82); 0.32152403656716766 (R’s value for n = 1e300, f = 1e-150: 0.3215240365671677); 0.259511022841444 (before: 0): where k n f^2 is not finite for finite values, the four factors are scaled by powers of 2; where both degrees of freedom exceed 1e16 (k - 1 > 1e16), the power is that of the normal approximation of F, as for pwr.f2.test (#202) |
effectsize’s hedges_g with very large df (Hedges’ J from two lgammas near df log df) |
J 0.99997 at df = 1e10 (relative error 3e-5), 1.28 at 1e14, 1e-14 at 1e16; 3e-10 off already at 1e6 | J from the difference of the lgammas formed directly (lgammaDiff): 1 - 3/(4 df - 1) to rounding at large df |
effectsize’s cohens_d(c(1, 1 + eps), mu = -1) (t = 2^54, where t ± 1 rounds to t) and hedges_g |
error from optim: “function cannot be evaluated at initial parameters” |
d 1.27e16 with the interval [3.99e14, 2.86e16] (the search for the noncentrality starts from t ± 1 to 2 ulp there) |
effectsize’s eta_squared, omega_squared, epsilon_squared of an aov fit of data around 1e154 (also with Error() and afex’s aov_ez) |
NaN (the sums of squares overflow) | the values of the same data in other units: the sums of squares as fitted (response divided by a power of 2), divided by one power of 2 before the ratios |
aov(y ~ x + W + Error(id)) with the covariate x around 1e-200 or 1e200, and Error(z) with a covariate z around 1e-200 |
x dropped from every stratum (its squares underflow); z: correct | the tables of the same data in other units: each treatment and error-model column is divided by its own power of 2 (the strata depend only on the spaces the columns span) |
mauchly.test with fewer residual degrees of freedom than dimensions (mauchly.test(lm(cbind(c(1, 3), c(2, 7)) ~ 1))) |
NaN, or W = 0 with p = 1, or W 2e-17 with p 9e-4 (the covariance is singular whatever the data) | an error: too few residual degrees of freedom for the test |
mauchly.test with one tested dimension (two measurements with X = ~1, or M one dimension larger than X) |
W = 1 and p = 1 whatever the data (one dimension is always spherical; the chi-squared df p (p + 1) / 2 - 1 is 0) | an error: one tested dimension, the test has no degrees of freedom (issue #342) |
coxph(Surv(time, status) ~ x) with a time censored at Inf |
“NA/NaN/Inf in foreign function call” | the fit, with the subject at risk at every event time (the same as for a censoring time beyond the last event) |
coxph(Surv(time, status) ~ x) with a covariate around 1e308 or subnormal (x times 2^1020, 2^1022 or 2^-1060) |
se 0 at 2^1020; “Loglik converged before variable 1; coefficient may be infinite” at 2^1022 and 2^-1060 (the sums of the centring and scaling overflow) | the fit of x: the same tests and log likelihood, the coefficient and se times 2^-k (beyond the doubles at 2^-1060: -Inf and Inf) |
coxph(Surv(time, status) ~ x) at an initial value whose linear predictors exceed exp’s range (x = 0, 1 or 0, 2 with init = 1000, iter.max = 0) |
the log likelihood -Inf (x = 0, 1) or “initial values lead to overflow or underflow of the exp function” | the finite log likelihood (-1000, -2000): the risk sums are held as e^-m times their values, with m moved only where a finite exp(eta) would overflow. Iterating from such a saturated value still gives NaN coefficients (survival NA) |
rgeom(n, 5e-324) (prob below about 5.6e-309), rnbinom(n, Inf, prob = p) with p < 1 |
NA; about 9e307 (the draw for size = MAX / 2) or NA | Infinity: the draws are beyond the largest double (for rgeom but with a probability below 1e-15; for rnbinom all the probability is at infinity, as dnbinom and qnbinom say). The same variates are drawn, so the stream is R’s |
rbeta(n, 1e308, 1e308) and other shapes above about 1e154 (2ab overflows) |
0 (Algorithm BB’s constants overflow) | the mean a / (a + b), to which the distribution is concentrated within 1e-77; the same uniforms are drawn, so the stream is R’s |
rbeta(n, 0, 0, ncp = 0) (and the Poisson-0 component for ncp > 0) |
NaN (0 / 0) | 0 or 1 with probability 1/2 each (Beta(0, 0)), as the central rbeta(n, 0, 0); one uniform is drawn there, where R draws none |
dhyper(1, 1e308, 1e308, 1), phyper, qhyper, rhyper(n, 1e308, 1e308, 1) (m + n overflows) |
NaN; rhyper 0 throughout | 0.5, 0.5, …: with k / (m + n) below 2^-60 the hypergeometric is the binomial Bin(k, m / (m + n)) to double precision, which is used there (m / (m + n) formed without the sum); rhyper draws one uniform each, where R draws none |
dnbinom(0, size = 1e308, mu = 1e308) |
1 | 0 (= 0.5^1e308; p and q from the ratio of size and mu when their sum overflows) |
qt(0.5, 10, ncp = Inf) |
NaN (or Inf, depending on p), although pt(t, 10, ncp = Inf) is 0 at every finite t |
Inf: all the probability is at +∞ (-Inf for ncp = -Inf), as for df = Inf |
pbeta(-1, 0, 2), pbeta(-1, 0, 0) (and an infinite shape) |
1, 0.5: the point masses are checked before q <= 0, so the distribution function is positive left of its support | 0 |
dweibull(x, shape, scale = Inf) at a finite x > 0 |
NaN (Inf * 0) | 0 (log -Inf), the limit |
qnorm(0.5, 3, Inf), qlnorm(0.5, 0, Inf), qlogis(0.5, 3, Inf), extraDistr’s qlaplace(0.5, 3, Inf) (the median with an infinite scale) |
NaN (Inf * 0), although the other p give the limits (±Inf; 0 and Inf for qlnorm) and pnorm(3, 3, Inf) is 0.5 |
the location (3; exp(meanlog) = 1 for qlnorm), the limit |
dbeta(0.5, 1e308, 1e308) and other shapes whose sum overflows |
NaN | 1.128e154 (log 354.72): the exponent from the halved shapes, doubled (the deviances are homogeneous) |
dbeta(1, 1.5e308, 1, ncp = 1.5e308, log = TRUE) (the density a + ncp/2 at x = 1 overflows, its log does not) |
-Inf | 710.0071388583824 |
dbeta(0.5, 0.75, 5e-324, ncp = 0.1, log = TRUE) (a subnormal shape) |
-Inf | -743.5986379456813: the j = 0 term of the mixture kept (log(1 + a/b) without forming a/b) |
pf(1e150, 1e150, 1e308, lower.tail = FALSE, log.p = TRUE) and df(..., log = TRUE) (m x beyond 1e290, n larger) |
-Inf | -4.999999975e299: the beta coordinate from m x and n divided by 2^600 together |
mvtnorm’s pmvnorm(c(-1e200, -1e200), c(Inf, Inf), corr = ...) and other huge finite bounds of a bivariate normal (pbvnorm) |
NaN | 1 (and 0 for c(1e200, 1e200)): a bound beyond ±40 is taken as infinite (Φ(-40) = 3.7e-350) |
extraDistr’s qtriang(-1000, 0, 1e308, 0, log.p = TRUE) (mode at an end, exp(p) below the doubles) |
-Inf | 2.5379794487747283e-127 (w exp(p/2)^2 / 2) |
dlogis(0, 0, 1.282987806042392e308) and other x (scale (1 + e)^2 overflows) |
0, and -Inf on the log scale | 1.95e-309 (log -710.83): the division by the scale last |
pbeta(0.1, 1e308, 1e308, log.p = TRUE) and other tails away from the mean of shapes whose sum overflows (also lower.tail = FALSE) |
-Inf | -1.0216512475319813e308 (the log of the leading factor x^a (1 - x)^b / (a B(a, b)) to the bit, Rmpfr); the linear values 0 and 1 as R. -E with the deviance E in the halved shapes, doubled, where E >= 1e22 (the other factors change the log by less than an ulp); these were NaN (issue #491) |
qbeta(0.5, 1e308, 1e308) and other quantiles near the mean of shapes whose sum overflows; pbeta(0.4999999999999999, 1e308, 1e308, log.p = TRUE) |
NaN (“NaNs produced”); -3.98e276 | 0.5 (the median of a symmetric beta); -4.93e276 = -a log(1 - 4 d^2) with d = 2^-53. The uniform expansion of the incomplete beta function in the halved shapes, with the deviance and m doubled (pbeta near the mean was NaN here) |
pwilcox(x, 1050, 1050, log.p = TRUE) for small x, and other lower tails whose probability is below 1e-308 (also pwilcox(1000, 600, 600, log.p = TRUE)) |
-Inf (the probability divided by C(m + n, m), which overflows) | -1451.558 (x = 0), -752.510 (600): the table of probabilities rescaled by powers of 2 where its largest entry falls below 2^760, as dwilcox in logs |
qcauchy(p, 3, Inf) |
NaN for every p, although dcauchy and pcauchy give the limits 0 and 0.5 |
-Inf, 3 and Inf below, at and above the median, as qnorm and qlogis |
lm(y ~ x, weights = rep(1e308, n)) (weighted sums of squares beyond the doubles) |
R² NaN, F NaN | the values for any common scale of the weights (R² 0.982 for the example in the tests); sigma grows as the square root of the scale. The sums of squares are formed with the weights divided by a power of 2 |
integrate(f, 0, -Inf), integrate(f, Inf, 1), integrate(f, Inf, -Inf), integrate(f, Inf, Inf) |
the integral over (0, Inf), (-Inf, 1), (-Inf, Inf) and (-Inf, Inf): the sign of an infinite limit is not used | minus the integrals over (-Inf, 0), (1, Inf) and (-Inf, Inf), and 0 |
integrate, optimize and uniroot where upper − lower overflows (uniroot(function(x) x, c(-1e308, 1e308))), and integrate where a midpoint overflows (integrate(function(x) 1/x, 1e308, 1.1e308)) |
integrate: “roundoff error was detected” (0 with the error 0 for the midpoint: every node at Inf); optimize and uniroot: warnings (“Inf replaced by maximum positive value”) |
solved in x / 2 on the halved interval (uniroot 0, which was -Inf here before; optimize did not return) |
deSolve’s ode(1, c(-1e308, 1e308), function(t, y, p) list(0), NULL, method = "euler") (also "rk4", rkMethod("rk2")) and other finite times whose difference overflows |
NaN (1 + Inf × 0) | the step formed from half its length, h k as (h/2) k added twice: 1 for a zero slope |
numDeriv’s hessian(function(x) (x[1] / 1e100)^2 + x[1] / 1e100 * x[2] / 1e100, c(1e100, 1e100), method.args = list(d = 2e54)) and other steps whose square or 2 h_i h_j overflows |
diagonal 2.0007e-200 (the first step’s quotient is 0), off-diagonal NaN | 2e-200 and 1e-200: the difference divided by the steps one at a time where their product overflows |
numDeriv’s hessian(function(x) 1e-92 * x[1]^2, 0, method.args = list(eps = 1e200, r = 2)) and hessian(function(x) 1e-92 * x[1] * x[2] + 0.5e-92 * x[1]^2, c(0, 0), method.args = list(eps = 1e200, r = 2)) (the second difference f(x + h) - 2 f(x) + f(x - h) of finite values near 1e308 overflows) |
NaN | 2e-92, and 1e-92 on and off the diagonal: only there every term divided by the step(s) before the sum (issue #504) |
uniroot(f, c(1, 2), extendInt = "yes") with f(1) and f(2) of the same sign whose product underflows (1e-300 (x − 5)) |
“f() values at end points not of opposite sign” | extended as for other values of the same sign (5) |
glm with an observation of weight 0 whose deviance contribution is 0 × Inf (poisson, y = 1e308) |
deviance NaN | the observation adds 0 (and its deviance residual is 0) |
coxph(Surv(1, 1) ~ x) with x = 0 and other fits whose log likelihood stays 0 |
“Ran out of iterations and did not converge” (the test 1 − 0/0 is NaN) | converged (an unchanged log likelihood is converged) |
survdiff(Surv(c(1, 1), c(1, 1)) ~ c("A", "B")) and other data whose variance matrix is singular |
“system is exactly singular” | the generalized inverse on rank(V) degrees of freedom (df in the result); with no information on the groups (rank 0) chisq 0, df 0, p NaN |
survdiff or survfit with a time censored at Inf |
“NA/NaN/Inf in foreign function call” | the subject at risk throughout (an event at Inf is an error) |
lmerTest’s anova(fit, type = 1) (and type 2) with a predictor in small units, e.g. lmer(y ~ x1 + I(x2 * 1e-6) + (1 \| g)) |
the type I F of x1 becomes its type II F (14.45 instead of 13.96): the Doolittle factorisation compares pivots and entries with 1e-6 in the units of the data; a bug in lmerTest (R 4.5.2, checked by running it) | the same tests at any units (the factorisation on the cross-product matrix scaled to unit diagonal) |
anova() of lmer fits of different rows of the data or different responses with the same number of rows |
a likelihood ratio test | an error (lme4 compares only the number of rows) |
power.t.test(n = 10, delta = 1e308, sd = 1e308) and other delta, sd whose noncentrality is finite while sqrt(n / ts) × delta overflows |
power 1 (the noncentrality Inf) | 0.56198, the power of delta = sd = 1 (the ratio delta / sd taken first where the product overflows) |
poisson.test(c(1e308, 0), r = 2, T = c(1, 1e308)) and poisson.test(c(1e300, 0), r = 2, T = c(1e-10, 1e308)) (the expected count, where n r T1 and r T2 / T1 overflow) |
NaN (with bgrat warnings); 0 | 1; 1e-18: n r T1 / (T1 + r T2) from the mantissas of n, r, T1 and T2, their powers of 2 applied last; also where n r T1 underflows to 0 with positive n and r (poisson.test(c(0, MAX), T = c(MIN, MAX), r = MIN) with the largest and smallest doubles: R 0, rStats.js Number.MIN_VALUE; issue #481) |
poisson.test(c(1, MAX), T = c(1e-12, MAX)) with MAX the largest double (the interval, where T2 / T1 overflows and the binomial limits are subnormal) |
[0, 5.571643e12] (R’s qbeta(0.025, 1, MAX) is 0) |
[2.5317807984e10, 5.571643390939e12]: (p / (1 - p)) (T2 / T1) from the mantissas of the odds, T1 and T2 where T2 / T1 overflows (issue #482); the lower binomial limit is subnormal, so the lower end is about 1.5e-14 relative off the exact 2.53178079842899e10 |
summary(glm(y ~ 1, Gamma("log"), weights = rep(2e304, 100))) with y 99 times 1e-6 and once 5000, and other fits whose weighted sum of squared Pearson residuals overflows while the dispersion does not (also glmAnova, glmPredict, glmRstandard, glmCooksDistance) |
dispersion Inf | 2.0e306: where the sum overflows, each term as (sqrt(w) r)^2 with the residuals and the products divided by powers of 2, and the exponents added back after the division by the residual degrees of freedom |
anova(glm(1e154 ~ 0, gaussian("log")), test = "Cp") and other Cp of a model without parameters whose dispersion exceeds half the largest double |
Cp NaN (2 × dispersion overflows, times 0) | 1e308, the residual deviance: the penalty as 2 (n − df) × dispersion (the same bits wherever R’s order does not overflow) |
AIC(glm(y ~ 0, gaussian("log"))) with y = 1e154, and other gaussian fits whose 2 pi × deviance overflows while the deviance does not |
Inf (log(2 * pi * dev / n)) |
714.034 (the true value): log(2 pi) + log(dev / n) where 2 pi × dev overflows; R’s form elsewhere |
The inverse Gaussian AIC with prior weights summing to sw where dev / sw overflows (inverse.gaussian()$aic(1, NULL, 1, 1e-10, 1e308)) |
Inf (log(dev / sum(wt) * 2 * pi)) |
2.0000000735 (the true value): log(2 pi) + log(dev) - log(sw) where 2 pi × dev and dev / sw overflow, log(2 pi) + log(dev / sw) where only 2 pi × dev does (sw = 1e308, dev = 3e307: 1.634e308 as R, one ulp below R’s; issue #479); R’s form elsewhere |
prop.trend.test(c(5e307, 5e307), c(1e308, 1e308)) and prop.trend.test(c(1, 0), c(1e300, 1e300)) (the totals of the counts, or the weights n / (p (1 - p)), overflow) |
error “NA/NaN/Inf in ‘x’” (from lm.wfit) | statistic 0 (p-value 1) and 1: the pooled proportion from the counts divided by a power of 2, and the regression with the weights n_i 2^-k, the statistic multiplied back by 2^k; R’s form elsewhere |
polycor’s polychor(matrix(8e307, 2, 2)) and polychor(matrix(4e307, 2, 2)) (the total of the table, or the log-likelihood, overflows) |
0.999859 (with “Inf replaced by maximum positive value”) | -1.67e-16, the value of the table of 1s: where the total is 2^1000 or more, the counts divided by a power of 2 (rho and the thresholds do not depend on their units), the variances, the chi-square and n multiplied back |
bartlett.test(list(c(1e200, 1.000000000000001e200), c(0, 1e-100))), bartlett.test(list(c(1e200, 2e200, 4e200), c(1e-200, 2e-200, 4e-200))) and other groups with a variance below about 2.2e-308 times the square of the largest absolute value |
NaN | 874.084 (p 4.2e-192), 2945.09: where a variance underflows on the common scale, each group’s variance on its own scale, the logs of the variances and of the pooled variance (log-sum-exp) relative to the largest scale |
sampleInt(n) returns values in 0..n-1 (R’s sample.int() minus 1,
from the same random stream), and the pivot of qr() and chol(x, { pivot: true }) is
0-based. sample(array, ...) returns elements, as in R.cor of a matrix has NaN on the diagonal where the correlation of a column with itself is undefined: a constant
column (0/0), or, with use: "everything", a column with a missing value. R puts 1 on the whole diagonal whatever
the column holds (cor(cbind(c(1, 1, 1), c(1, 2, 3))) has 1 at [1, 1]). Elsewhere the diagonal is 1, as in R.Distribution parameters are scalars; they are not recycled as vectors. The first argument
may be a number, an array or a Float64Array. Use map for vector parameters; random draws made
one at a time after setSeed consume R’s stream in the same order as R’s recycling, so the
results are R’s:
[0, 1, 2].map((m) => pnorm(1.96, { mean: m })); // R: pnorm(1.96, mean = c(0, 1, 2))
setSeed(1);
[0, 10, 100].map((m) => rnorm(1, { mean: m })[0]); // R: set.seed(1); rnorm(3, mean = c(0, 10, 100))
// [-0.6264538107423324, 10.183643324222082, 99.16437138758995]
NA from NaN (for example table and unique count them
apart); rStats.js has one NaN.var is called variance, because var cannot be a name in JavaScript.
zTest, an infinite probability in
chisqTest, non-binary data in cochranQTest, negative counts in propTrendTest and polychor, fewer than 2
subjects or raters in icc and kappamFleiss, fewer than 2 complete rating pairs in kappa2 (irr’s kappa2
gives z and p NaN; issue #309), binomTest([0, 0]) (no trials; R returns a p-value of 1 for
binom.test(c(0, 0)), while poissonTest compares two counts of 0 as R), a time base T of 0 in poissonTest
(R returns NaN or Inf for the estimate and the interval), counts whose total overflows in binomTest and
poissonTest (R: NaN or an error), fractional counts in mantelhaenTest(exact: true) (R returns a result), a
table without discordant pairs in mcnemarTest, only zero differences in the signed rank wilcoxTest, and two
constant samples in varTest.tTest also when the mean is 0 (samples of zeros, zero paired
differences: “data are essentially constant”; R’s guard is 0 < 0 there and it returns t NaN or ±Inf; issue
#314), an infinite observation in adTest, cvmTest, lillieTest, sfTest and pearsonTest (nortest’s
pearson.test(c(1:7, Inf)) returns P = 8, p = 0.0183 from an empty classification, sf.test NaN; the others
stop; issue #304), a group with an infinite median in flignerTest (its deviations are Inf - Inf; R ranks the NaN
last: fligner.test(c(1, Inf, 2, 3), c("a", "a", "b", "b")) gives 2.476, p 0.116; issue #329), fewer than 2
distinct scores in propTrendTest (all scores equal, or one group with a score: R’s prop.trend.test gives NA;
issue #318, which reverses the NaN of issue #50), and df <= 0 in pwrChisqTest.dunnettTest, tukeyTest and
glhtDunnett (a pooled variance of 0: R’s p-values are 0 in TukeyHSD and PMCMRplus, 1 in multcomp’s glht),
and in pairwiseTTest with a pooled SD and onewayTest with varEqual: true (R’s pairwise.t.test gives p 0,
or NaN for equal means, oneway.test F Inf and p 0; groups of one observation only: “no residual degrees of
freedom”, R NaN); a confLevel outside [0, 1] or NaN in TukeyHSD (R returns NaN limits; 0 and 1 are accepted as
in R), one value per group in TukeyHSD (no residual degrees of freedom; R returns NaN limits and p-values; issue
#315) and 1 residual degree of freedom in TukeyHSD and tukeyTest (the studentized range distribution of
ptukey and qtukey, as R’s, starts at 2 df; R returns NaN, PMCMRplus NA; issue #315).B, or goodness-of-fit counts summing to a fraction, in chisqTest’s simulation (R’s
p-value can exceed 1 there), a fractional B in fisherTest’s simulation (R simulates trunc(B) tables and
divides by B + 1; issue #278), and fractional counts in chisqTest’s simulation of tables (R returns NaN or
truncates the margins).glm, and a covmat in factanal and omega that is not
square, finite and symmetric (as R’s isSymmetric) with a positive diagonal (R’s factanal analyses an
asymmetric matrix).optim’s reltol, uniroot, optimize,
integrate, qr, chol, solve, coxph, glm); a temperature temp that is not positive and finite in
optim’s SANN (R stops on 0 with “non-finite value supplied by optim” and accepts a negative one); an infinite
fnscale in optim and optimHess (R’s optim returns the start with value NaN and convergence 0, optimHess
NaN; issue #248); a NaN or infinite component of an analytic gradient gr in optim (BFGS, CG, L-BFGS-B) and
optimHess, “non-finite value of the gradient [i] supplied by ‘gr’” as the numerical gradient’s check (R does not
check gr: a NaN gradient returns the start with convergence 0 without a step, and optimHess a NaN matrix;
issue #355); a step eps of 0 or a non-finite d, eps or zeroTol in grad, jacobian and hessian
(numDeriv’s “simple” method gives NaN for eps = 0; d = 0 is an error there too), and a step d abs(x[i])
beyond the doubles (issue #213) or of 0 (x[i] = 0 with zeroTol: 0, issue #246) in the same three (numDeriv: an
error from grad’s check of f, NaN from jacobian and hessian); a rule other than 1 or 2 in approx (R takes
every value other than 1, such as 3, 0 or 1.5, as rule 2).cut (R returns NA codes; one break is R’s error
“invalid number of intervals”, and infinite breaks are accepted as in R), and an infinite or NaN explicit break in
hist (R returns a density of 0 for an infinite cell, with an infinite or NaN midpoint).exact: false); R computes most
of these however long they take, or runs out of memory. The bounds are listed in
performance.md and described with R’s behaviour under
Hypothesis tests and Random numbers below.pwrRTest, probabilities outside
[0, 1] in esH, esW1 and esW2 (R: NaN), an empty or ragged matrix in esW2 (R: 0), n <= 0 in powerPropTest
(R: a power for n = 0, NaN below), and n < 2 in pwrTTest (as pwr). Solving for sd with delta = 0, or for
withinVar with betweenVar = 0, says that the power does not depend on it (R: “lower < upper is not fulfilled”);
so does solving for n with no effect (delta = 0 in powerTTest, p1 = p2 in powerPropTest, betweenVar = 0
in powerAnovaTest; R: “no sign change found” or “f() values at end points not of opposite sign”, issue #311), and solving powerPropTest for p1 with p2 = 0
or for p2 with p1 = 1, where the search interval is a point (R: “lower < upper is not fulfilled”, issue #312).
cohensD rejects infinite values and fewer than 2 observations (per group) with a message (effectsize: NA).| Case | R | rStats.js |
|---|---|---|
qbeta answer underflows (e.g. qbeta(0.5, 1e-10, 2.5)) |
2^-1024 (5.56e-309) | 0 |
qf answer overflows (e.g. qf(-1e-300, 1, 1, log.p = TRUE)) |
a finite value near 2^1023 | Inf |
dchisq, pchisq and qchisq with df = -5e-324 (the least negative subnormal) |
df / 2 rounds to -0, the point mass at 0: Inf, 0, 1, 0 | NaN (a negative df is invalid) |
| Uniform with overflowing max − min (min = -1e308, max = 1e308) | Inf / 0 / NaN | computed with both ends halved (dunif 5e-309, punif(-1) 0.5, qunif(0.5) 0) |
dmultinom with finite weights whose sum overflows (dmultinom(c(1, 1), prob = c(1e308, 1e308))) |
0 (log -Inf) | 0.5 (log -0.693): the weights are divided by a power of 2 before they are summed |
dmultinom where a category’s share of the weights is below the double range (dmultinom(c(1, 0, 0), prob = c(5e-324, 1, 1), log = TRUE)) |
-Inf | -745.133 (log 5e-324 - log 2): the term of that category from the log of its share |
dnbinom with size = Inf |
finite log probabilities such as -1.2e308 for prob < 1; NaN for log P[X = 0] with prob = 1 | -Inf and 0 |
qnbinom with size = Inf and prob < 1 |
Inf or NaN depending on p | always Inf (the mass is at X = ∞; p = 0 and 1 as in R) |
qnbinom answer above 2^53 |
an answer whose distribution function misses the target (log p −31.85 for a target of −32) | an answer that meets the target |
qsignrank, qwilcox with tiny p (below about 1e-15), small upper-tail p, or deep log p |
converts to a linear lower-tail p and compares with absolute slack 10ε, so returns 0 and similar (qsignrank(1e-100, 1000) is 0) |
the answer by definition (69727) |
qsignrank, qwilcox, qhyper with log.p = TRUE and p = -Inf |
NaN | same as p = 0 (lower end of the support) |
| signrank with n = Inf, wilcox with m = Inf | crashes | NaN |
Non-central qbeta with an infinite parameter (e.g. shape2 = Inf) |
0, 0.5 or 1 from a search on NaN | NaN |
qchisq(p, 0, ncp = 0) (all mass at 0) |
NaN or Inf | 0 |
qgamma and pgamma (log upper tail) where q / scale exceeds the largest double and the answer is finite, which needs a shape of about 1e307 and above, or about 1e290 with q / scale just beyond the largest double (qgamma(-1e308, 1e308, scale = 1e-308, lower.tail = FALSE, log.p = TRUE), true value about 3.146; pgamma(1.8, 1e308, scale = 1e-308, lower.tail = FALSE, log.p = TRUE), about -2e307) |
Inf, -Inf | NaN (not computed: the standardized x is beyond the doubles; a wrong 1.797 and -Inf before, issue #368). With scale >= 1 the quantile is Inf, as in R |
pgamma(Inf, shape, rate = r) with a subnormal r (below about 5.6e-309, so 1 / r overflows) |
NaN | 1 (P[X ≤ Inf] = 1 by definition) |
pgamma(q, Inf, scale = s) with 0 < q / s < 1, so pchisq(q, Inf) with 0 < q < 2 (all mass at +Inf) |
NaN | the limits: lower tail 0, upper tail 1 (as R gives for every other finite q) |
df(0, df1, Inf, ncp, log = TRUE) |
not the log of the linear value (−1.386 with ncp = 0, where the linear value is 1) | log of the linear value |
qf with df2 = Inf when the answer rounds to 0 |
meaningless values such as 2e-130; Inf for log p = -1e-300 | value checked with the distribution function |
pgeom, pnbinom, ppois, pbinom, phyper, pwilcox, psignrank and the exact ansari.test distribution with q just below an integer k: k − 1e-7 ≤ q < k − 1e-9 max(1, k), so only for k < 100 (pgeom(0.99999999, 0.5)) |
floor(q + 1e-7) = k, so P[X ≤ k] (0.75), although the density treats q as non-integer (dgeom is 0 there) |
P[X ≤ k − 1] (0.5): the largest count not above q |
The distribution functions of the discrete distributions take P[X ≤ q] as P[X ≤ k] with k the largest
count not above q. A q within min(1e-7, 1e-9 max(1, |q|)) of an integer counts as that integer (a computed
2.9999999999999996 is 3); any other q gives floor(q). Below q = 100 this is the rule by which dpois, dgeom,
dnbinom, dhyper, dwilcox and dsignrank decide whether x is an integer; above it the slack stays at R’s 1e-7,
so that a q such as 1000 − 5e-7 (ppois(1000 - 5e-7, 1000) = P[X ≤ 999], as in R) is not counted as an integer. R adds 1e-7 before the floor,
so its distribution functions step 1e-7 before the integer and do not agree with its densities. Only q
within 1e-7 of an integer is affected. (R 4.5’s psignrank rounded q + 1e-7 to the nearest integer, so that any q
with a fractional part of 0.5 or more changed, issues #145 and #146; R 4.6 takes the floor.) An earlier version had
kept R’s floor(q + 1e-7) for pbinom as R’s own behaviour; that decision was reversed for the sake of
correct values and agreement with the densities.
For very flat qnbinom cases (size = 1e-10, p = 1 − 1e-10 and similar) the rounding width of p
contains dozens of integers, so the answer can differ from R by dozens; both answers are checked
to have a distribution function within 16ε of p.
R’s dgeom and dnbinom treat x as non-integer when |x − round(x)| > 1e-9 max(1, |x|).
rStats.js’s dpois and dbinom use a threshold of 1e-7, which may differ from R near integers
(not verified).
darcsine, parcsine,
qarcsine and rarcsine (not in extraDistr) are beta(1/2, 1/2) moved to (a, b); where b - a
overflows (a = -1e308, b = 1e308) they are computed on the halved scale. An infinite
shape or location is taken as the limit, where extraDistr’s formulas give NaN or a stray value at
the edges (qkumar(0, Inf, 1) is 1 there, 0 here). Where x and an infinite location are the same
infinity (plaplace(Inf, mu = Inf)) there is no limit and the value is NaN, as in extraDistr. qinvgamma returns NaN for alpha <= 0, as
dinvgamma and pinvgamma do (extraDistr’s qinvgamma does not check alpha). The random generators follow
the quantile functions: an infinite shape a or alpha gives the limit (rkumar 1, rpareto b, rinvgamma 0, as
extraDistr), and an infinite b of rkumar and rpareto or beta of rinvgamma is NaN, as the density,
distribution and quantile functions (extraDistr returns 0 or Inf), drawing the uniforms extraDistr draws.
rlaplace likewise takes an infinite mu as the limit mu (as extraDistr), and sigma = Inf as the limit -Inf or Inf by
the sign (as extraDistr and qlaplace; NaN when mu is infinite too), after the exponential and the uniform
extraDistr draws. The Laplace distribution with sigma = Inf is the limit, as the normal, logistic and Cauchy
distributions: density 0 and probability 1/2 at every finite x (as extraDistr), NaN at an infinite x or mu.
rtriang with an infinite endpoint is NaN, as qtriang (extraDistr returns Inf for b = Inf with a finite c),
after the two uniforms extraDistr draws.distSummary follows these conventions: a moment that does not exist is NaN, an infinite
one Infinity; the mode of a discrete distribution with two equal maxima is the larger, and NaN
when the density has no unique maximum.setSeed(seed) followed by any r* function or sample gives the same stream as R’s
set.seed(seed). Discrete values, sample and the number of uniform draws consumed match
exactly; continuous values agree to about 1e-13 (at most 1e-12), because the last bits of
Math.log, Math.exp, Math.pow and Math.tan differ between V8 and glibc.rbinom with n min(p, 1 - p) >= 30 (algorithm BTPE) is not R’s stream. The final acceptance test of R’s
rbinom.c adds the Stirling corrections of log ix! and log (n - ix)! where they are to be subtracted (an error of up
to 0.013 in the log of the probability ratio at n = 60); rStats.js uses the right signs, so some draws are accepted
or rejected differently and the stream departs from R’s from there (set.seed(439); rbinom(1, 10000, 0.5): R
5023, rStats.js 4879). The binomial draws of rmultinom go through the same code.rbeta with one huge shape and one up to 1e32 (2ab overflows) is not R’s stream. R returns the mean there
(set.seed(12); rbeta(5, 1.1, 1e308) is 1.1e-308 five times, though the coefficient of variation is 0.95);
rStats.js draws G from Gamma(m) for the smaller shape m and returns G / (G + B), which is the beta variate to double
precision, so the stream departs from R’s from there. With both shapes above 1e32 the mean is returned with R’s
stream, as R.rbinom with p below 1.1e-16 (where 1 - p rounds to 1): R’s inversion starts from (1 - p)^n = 1, so every draw
is 0 although a success has probability n p (up to 1e-7); rStats.js starts from exp(n log1p(-p)). Both use one
uniform per draw, so the stream stays R’s; a uniform above exp(n log1p(-p)) gives 1 where R gives 0.qnorm and therefore of normal variates: set.seed(42); rnorm(3)[2]
is -0.56469817139608869 on x86_64 and -0.5646981713960888 on arm64. JavaScript has no FMA, so
rStats.js matches x86_64 R."Mersenne-Twister" (the default) and
"L'Ecuyer-CMRG", the normal kind "Inversion" and both sample kinds ("Rejection", the
default, and "Rounding") are supported, through RNGkind({ kind, sampleKind }). R’s
set.seed(seed, kind, sample.kind = ...) is RNGkind({ kind, sampleKind }) followed by
setSeed(seed), which gives the same state (R does the same internally); setSeed itself only
takes the seed, so that the L’Ecuyer-CMRG generator is left out of bundles that do not use it.
RNGkind returns an object ({ kind, normalKind, sampleKind }) instead of R’s character vector,
and choosing "Rounding" gives no warning.getRandomSeed()/setRandomSeed() use the same integers as R’s .Random.seed: the kind code
(10403, 403 with Rounding, 10407 for L’Ecuyer-CMRG), then 625 integers for
Mersenne-Twister or 6 for L’Ecuyer-CMRG. Where R silently reseeds from the clock (an
unsupported kind code, or an L’Ecuyer-CMRG state with seeds out of range or the first three
all zero), setRandomSeed throws a RangeError, and so do nextRNGStream and nextRNGSubStream
(R computes a meaningless state without checking).rmultinom returns an array of n arrays of length K instead of R’s K × n matrix.r2dtable returns an array of tables, each an array of rows, instead of R’s list of matrices.warnings (R’s text, each once, in R’s order; [] when there are none) and are
printed only through setWarningHandler (nothing by default). Those that explain a NaN result (“NaNs produced”) are
included; those of R’s distribution functions about their own precision (“full precision may not have been achieved
in …”) and R’s warnings about argument types are not. cronbachAlpha returns psych’s alpha’s own warnings, not
those of the functions it calls (principal, cor), and pairwisePropTest and pairwiseWilcoxTest give each
warning once (R repeats it for every pair). Method names and all numeric fields match R.brunnerMunzelTest takes confLevel where lawstat takes alpha (confLevel = 1 - alpha),
and returns an alternative field, which lawstat’s result lacks. An empty sample throws “not
enough ‘x’ observations” (or ‘y’); lawstat returns meaningless numbers, because it indexes the
ranks with n1 + 1:n2 and 1:0 is c(1, 0). A sample of one value throws the same error; lawstat returns a
NaN statistic, df and interval (its variance estimate divides by n - 1 = 0; issue #320).pAdjust with the Hommel method throws when n is not an integer (R returns a value), and
returns an empty array for an empty p with n > 0 (R returns 1).fisherTest (2 × 2) and mantelhaenTest(exact: true) throw a RangeError when the
support of the count has more than 2^24 values (fisherTest: min(a, d) + min(b, c) + 1; mantelhaenTest: 1 plus
that sum over the strata, with the hint to use exact: false), before anything is allocated. R allocates the whole
support whatever its size: fisher.test(matrix(1e7, 2, 2)) (2e7 + 1 values) took 45 s, and counts of 1e9 would
take 16 GB per array.chisqTest (simulatePValue: true) throws a RangeError when B times the
total count exceeds 2^27 (134217728 draws, tens of seconds), before drawing. Below that the draws are made n at a
time from the same uniforms as R’s sample.int, so the p-values match R; R draws all B n at once and accepts any
size it can allocate (chisq.test(c(1e9, 1e9), simulate.p.value = TRUE, B = 1) asks for 2e9 draws; issue #287).r2dtable and the simulated p-values of chisqTest (contingency tables) and fisherTest throw a RangeError
when tables are to be generated and the grand total exceeds 2^24 (16777216), because Patefield’s algorithm uses a
table of log factorials with total + 1 entries (128 MB at the limit; the same 2^24 as the exact tests above).
R builds the table for any total up to 2147483647 (8 GB for r2dtable(1, c(5e8, 5e8), c(5e8, 5e8))).
r2dtable(0, ...) builds no table and still accepts totals up to 2147483647, as R (issues #285, #286, #336).ksTest, ansariTest, corTest (Kendall), jonckheereTest and the Hommel method of
pAdjust throw a RangeError, before anything is allocated, where the computation would need more than a few
seconds (limits set from timings on the development machine; the default thresholds, such as n < 100 for ksTest,
are far below them). ksTest(exact: true) (one sample, two-sided, D < 1/2): the matrix of size m = 2 floor(n D) + 1
is raised to the n-th power, and m^3 times the number of matrix products may be at most 2^33 (m 783 at n 1023, 3.6 s;
the sum for small p-values, #483, takes 1.4 s there).
ansariTest(exact: true) (no ties): the distribution keeps 2 (m + 1) (floor((N + 1)^2 / 4) + 1) doubles (N = m + n),
at most 2^24, and N times half that many steps, at most 2^32 (m = n = 202, 5.3 s). corTest(method: "kendall",
exact: true) (no ties): n at most 1290 (about n^3 / 2 steps, 4.9 s; the same number as the Spearman exact limit).
jonckheereTest(exact: true) (no ties): the convolution of the Mann-Whitney distributions may have at most 2^24
values and take at most 2^32 multiply-adds (three equal groups of 216, 8.5 s). The hint is to use exact: false.
pAdjust(method: "hommel"): n at most 65536 (O(n^2) steps, 5.7 s). R computes these however long it takes (issues
#307, #308, #316, #321, #391).expm with the methods "Taylor", "Pade", "TaylorO" and "PadeO" throws a RangeError, before any
computation, when order times (n^3 + 64) exceeds 2^31 for an n × n matrix: the methods make order matrix products
whatever the matrix (the limit is order 29826161 for 2 × 2, about 5 s with Taylor and 9 s with Padé, and 17171 for
50 × 50, about 9 s with Padé). The default order 8 is far below it. expm in R
accepts any order up to 2147483647 (about 8 minutes for 2 × 2, about 13 days for 50 × 50 here).grad, jacobian and hessian with the method “Richardson” throw “‘r’ must be at most 512” for r > 512,
before the steps (jacobian has evaluated the function at x only). From r = 513 on, the factor 4^512 of the
extrapolation overflows and every result is NaN, also in numDeriv, and the extrapolation’s O(r^2) steps do not end
for a huge r. Up to 512 the values are unchanged (from about r = 20 on they lose accuracy, and with the default
d they mean nothing from r = 41 on, where the smallest step is below half an ulp of x, as in numDeriv; issue #123).phyper and qhyper throw a RangeError, before any sum, where the sums of the probabilities would take more
than a few seconds (an exception to the NaN that distribution functions return for invalid parameters: these are
valid). The sums step through the support one value at a time, as many values as a multiple of the standard
deviation sigma. phyper: the number of terms is estimated from the normal approximation, about
sqrt(u^2 + 83 sigma^2) - u for a tail that starts u past the mean (83 = 120 ln 2: the terms fall below 2^-60 of the
sum), both tails within 1 of the mean, and at most the distance to the end of the support; at most 2^26 (about 5 to
8 s; sigma about 3.7e6 at the center, 7.4e6 a little off it, more in the far tails). qhyper: sigma at most 2^21
(about 5 s; its search evaluates the distribution function a few times). With m = n = k, phyper(5e14, 1e15, 1e15,
1e15) (sigma 1.1e7, about 40 s before) throws and phyper(5e12, 1e13, 1e13, 1e13) takes 1.3 s. The ends of the
support, the binomial limit and p = 0 or 1 answer as before. R’s phyper sums double terms with a looser stop
(1.0 s at the center of 1e15, and 1.8e-11 off at 1e13: 0.5000001783941305 for 0.5000001784124118), and its
qhyper takes time proportional to m + n (0.7 s at m = n = k = 1e7). rhyper, which inverts qhyper for parameters beyond
2147483647, has no bound.besselJ, besselY, besselI and besselK throw a RangeError, before the computation, where the bounds on
the log of the result do not decide (they return Inf or 0 at once where the result is far out of range)
and a continued fraction or a recurrence would take more than a few seconds. J and Y: the continued fraction takes
about x - nu terms for x above nu outside the asymptotic expansions, at most 2^25 (besselJ(1e7, 2e5), 9.8e6 terms,
takes 1.6 s; besselJ(1e8, 2e6) ran into the loop’s limit of 1e8 terms before); near the turning point (x a little
below nu) the recurrence takes about nu steps, at most 2^31 for J (about 5 ns a step; besselJ(1e8 - 1, 1e8) takes
0.5 s) and 2^28 where Y is needed (besselY, and besselJ of a negative non-integer order; about 45 ns a step).
I and K: the forward recurrence of K takes about nu steps; beyond 2^28 steps, and where the continued fraction of
I_(nu+1) / I_nu does not converge within 1e6 terms (x above about 5e10), orders above 1000 take Debye’s uniform
expansion (u1 to u4, relative error about eps times the exponent nu eta - x; besselK(3e9, 3e8, expon.scaled =
TRUE) first gave Inf after 4.4 s, and then a RangeError until #492). There a RangeError remains only where
the terms of that exponent exceed 2^26 and the result is in range (unscaled I and K near x = 0.66 nu, nu above
2^28). R’s besselJ gives 0 with a warning from about nu = 1e6 on, and R’s besselY is fast
there. In the asymptotic expansion for large x (x above about 90 nu), J and Y throw a
RangeError, before the computation, where the phase correction nu^2 / (2x) exceeds 2^26: formed in double its
error is about 1e-16 times itself, and no digit of the result is left beyond about 1e13 (besselJ(1e200, 1e154),
5e107; below the bound the relative error is at most about 1e-9). R gives NaN with a warning there (every nu above
1e7; #490).dwilcox, pwilcox and qwilcox (and the exact p-values and intervals of the two-sample wilcoxTest) throw
a RangeError, before the table is built, where it would take more than 2^29 steps: min(m, n) passes over the table
of the smaller tail up to the value asked for (about 6 to 8 s; another exception to the NaN of distribution functions
for invalid parameters). pwilcox(2e5, 3000, 3000) (6e8 steps) took 5 s and throws, pwilcox(1e5, 3000, 3000)
takes 2.8 s, and m = n = 1e5 at q = 1e6 would take about 20 minutes. wilcoxTest adds “use exact: false” to the
errors of its exact distribution. R builds a three-dimensional table, which takes longer (1.5 s at
pwilcox(2e4, 200, 200), where this takes 24 ms) and runs out of memory beyond about m = n = 500.seq, approx, spline and sampleInt (as for rnorm and the other
random generators): the length is what the caller asks for, and time and memory grow in proportion to it
(seq(0, 1e7) 0.46 s, approx and spline with n = 1e7 2.7 s and 1.5 s, sampleInt(1e7) 4.9 s, R’s
sample.int(1e7) 5.05 s). A length that JavaScript arrays cannot hold (about 1.3e8 elements) is an error
(seq(0, 2e8, by: 1) fails with “Invalid array length” after about 11.5 s). R accepts what it can allocate.optim’s maxit (an integer up to 2147483647, as R): the time is about maxit evaluations of fn
(SANN always makes maxit evaluations, about 20 minutes at 2^31 even for a cheap fn; the other methods stop when they
converge). As with integrate’s subdivisions and uniroot’s maxiter, most of the time is the caller’s function.kruskalTest and flignerTest with a list of one sample throw rStats.js’s “all observations
are in the same group” (R: “‘x’ must be a list with at least 2 elements”).g of kruskalTest, aov, TukeyHSD, the pairwise* tests, …)
are sorted in C-locale order, by code point; R sorts factor levels with the locale’s collation,
so the order of groups, and of the results listed by group, can differ ("a", "b", "B"
sorts as "B", "a", "b" here and as "a", "b", "B" in an en_US locale). The same holds
for the levels of the two factors of chisqTest(x, y) (the rows and columns of the table), which
must be strings (null for missing values).
It also holds for the factors of formulas (modelMatrix, lm, aov, lmer; levels fixes the order)
and for the between-subject factors of aovEz. The within-subject factors of aovEz keep afex’s
order of first appearance in the data.., +, -, *, /, :, %in%, ^,
parentheses, 0 and 1, one Error() term in aov, and random-effects terms (lhs | g) and (lhs || g) in
lmer (not the covariance structures diag(), cs(), ar1() of lme4 2.0). Function calls (log(x), I(x^2),
poly(x, 2), offset()), backquoted names and transformed responses are not supported: compute
the column first. Contrasts are contr.treatment (default), contr.sum and contr.helmert (and contr.poly in
lmer). A
formula that cannot be parsed throws “invalid formula: …” instead of R’s parse error.
A variable name starts with a Unicode letter, a letter number (such as Ⅰ), . or a digit that is not ASCII
(. followed by an ASCII digit starts a number; _ cannot start a name), and goes on with letters, numbers that are
not symbols, combining marks, . and _ (転帰 ~ 年齢 works). This is wider than R on Windows, which takes no
combining marks (नमस्ते, Thai with vowel signs, a decomposed é) and no character outside the BMP (𝐀, CJK
Extension B) in a name; R on Linux takes both.lm, aov with or without Error(); such as “Error() model is singular” or an
absent variable named in contrasts) are carried to anova (of all the fits compared), car’s Anova, aovSummary
and the effect sizes computed from them, each message once (R gives them when fitting only; a handler set with
setWarningHandler receives them once too, from the fit).dunnTest ranks the values as numbers. dunn.test 1.4.2 given a character group vector ranks them as text
(so 10.06 before 8.88); with a factor it ranks them as numbers, which is what dunnTest reproduces.aovEz messages that R completes with a printout of the data (ids removed for missing
values, empty within-subject cells, empty between-subject cells) stop where the printout starts.aovEz and missing values: a response that is null or NaN removes its id (afex’s “Missing values for …
ID(s)”), an infinite response is an error, and rows with a missing id or factor value are dropped. When the error
SSP matrix of a within-subject term is singular, a warning says that its p-values are uncorrected (afex prints none).
A within-subject factor with one level is an error, as a between-subject one is (afex returns an empty table).aovEz with a factor name repeated in between or within, or given in both, is an error (“duplicated factor
names in ‘between’: A”, “factors in both ‘between’ and ‘within’: A”). afex’s aov_ez drops a repeat silently
(between = c("A", "A") is the one-factor table) and stops with “No observations remain after removing missing
values” for a name in both. A repeated name is a slip (another factor meant), so it is not fitted as a smaller model.aovEz with a singular error SSP matrix (for example fewer subjects than measurements): car gives no
sphericity corrections (“Singular error SSP matrix”). rStats.js judges each on its own condition: the
Greenhouse-Geisser epsilon tr(A)^2 / (p tr(A^2)) is defined for any nonzero A and is given; Huynh-Feldt only when
d - p GG > 0 (otherwise NaN, and correction: "HF" corrects with GG); Mauchly’s test only for a nonsingular matrix.
Each omission comes with a warning. An eigenvalue of the error SSP matrix counts as 0 below 1e-12 of the largest one
or 1e-24 of the sum of squares of the wide data, judged on the matrix in the metric of (P’P)^-1 (whatever the
contrasts). So an error SSP matrix made only of the rounding of the data (additive data with decimal values, such as
y = s_i + c_j with s_i = 0.3, 1.7, …) counts as 0: no corrections and no Mauchly test, at any scale. car gives none
either at the usual scales, but its absolute threshold gives W = Inf with p = 1 at 1e100 times the same data.Anova (types II and III) reports “residual sum of squares is 0 (within rounding error)” when the residual sum
of squares is below 1e-24 times the (weighted, uncentred) sum of squares of the response, residuals at the level of
rounding (below 1e-12 of the response’s size); car compares it with sqrt(eps) itself, which depends on the units
(y = 1000 x + e / 100 with residuals of 0.01 gives a table in both, the same data divided by 1e6 is an error in
car only).nextRNGStream takes only the L’Ecuyer-CMRG kind codes 10407 and 407, those setRandomSeed restores (R takes any
code ending in 07).rgamma
and rweibull with a negative (or NaN) shape and scale 0, rlogis with a negative scale. The uniforms R draws are
drawn as well, so the stream after the call is R’s.setRandomSeed refuses a Mersenne-Twister state whose position is negative, not an integer or above 2^31 − 1
(which R’s integer .Random.seed cannot hold either), or whose words are not 32-bit integers. R takes a negative
position as given, and its first draw then reads the position slot itself as a state word. A position of 0 or past
624 regenerates on the next draw, as in R.rwilcox throws “m + n must be at most 2147483647” where R’s allocation of the ranks fails, and “n must be at
most 2^24 (16777216)” beyond that n, before drawing: it draws one uniform per rank of the second sample (3.4 s per
value at n = 2^24 + 5 before; 13 s at n = 2^24 with m = 1e9). R accepts n up to its integer range (4.8 s per value at
n = 1e7). Beyond 2^24 ranks in all (m + n), only the slots that the draws swapped are kept, in a Map, instead of an
array of all m + n ranks (up to 8 GB per value before), with the same uniforms and values as the array.rsignrank throws “n must be less than 2^27 (134217728)” for n >= 2^27 (after rounding), before drawing (#407).
It draws one uniform per rank, and 2^27 takes about 4 s (8 s with L’Ecuyer-CMRG); the bound is the domain of
dsignrank. R runs up to 2147483647 (about a minute) and gives 0 without drawing beyond its integer range.anova(fit1, fit2) for lm, glmAnova with several fits) require the same rows, response
values and weights; R compares only the number of rows (and for glm drops fits with another response formula).
lmerAnova checks the same.confint and predict for lm (R gives NaN limits, or an interval
of another coverage for a negative level) and in the effect sizes (cohensD, etaSquared, …, as effectsize).qr rejects a negative tol (R accepts it, and then no column is dependent).lmerAnova comparing fits that differ in a variance component uses the chi-squared distribution, as lme4: the
null value 0 is on the boundary, so the p-value is conservative (the reference distribution is a mixture of
chi-squared distributions, 0.5 chi2_0 + 0.5 chi2_1 for a single random intercept).chisqTest (R returns NaN), an infinite
offset in glm (R stops on the working response; rStats.js had returned coefficients of 0), and a distribution
function returning values outside [0, 1] in ksTest (R reports D = 1.5 and p = 0 for one returning 1.5) are errors.glmAnova rejects fits of different families or links (R uses the first fit’s family for all).glmConfint gives NaN limits when the fit, or a restricted fit of the profile, does not converge.lmerAnova of fits that are not nested (fixed-effect columns of the smaller fit missing from the larger, or a
random-effect term not within a term of the same grouping factor there, such as (1 | g) against (1 | h)) gives
no Chisq and p-value; lme4 reports a likelihood ratio test for any pair. AIC and BIC compare them as before.coxph takes a time censored at Inf as at risk throughout and rejects an event at Inf, as survdiff and
survfit (R stops on any infinite time).pbeta checks its parameters before the ends of the support: a negative shape or a negative or
infinite ncp gives NaN (R returns 0 or 1 at q <= 0 or q >= 1 for them, and the central pbeta NaN). Shapes of 0
(point masses) keep the ends, as in R.qnbinom with a negative size or mu is NaN, as dnbinom and pnbinom (R’s qnbinom returns 0 for mu = 0 or
size = 0 before checking them).qgamma and qchisq with a negative shape or df, or a scale <= 0, are NaN also at p = 0 and 1, as the density
and distribution function (R returns 0 and Inf there).qgeom takes the slack of the other discrete quantiles (8 ε relative on p, 2 ε on the log scale) where it is
below half a step, and is otherwise exact for p as given; it equals qnbinom with size 1. R’s closed form subtracts
1e-12 from the ratio of logs, which takes y − 1 for a p up to 1e-12 relative above a jump: qgeom(0.7500000000000866,
0.5) is 1 in R, where P[X <= 1] = 0.75 < p (2 here, as R’s qnbinom(p, 1, 0.5)), and
qgeom(0.8757104766401955, 1.1843097327690854e-6, lower.tail = FALSE) is 112065 in R (112064 here and in R’s
qnbinom, p being pgeom(112064)).phyper and qhyper whose support reaches beyond 2^53 are NaN: the tail sums step through the integers one by
one, which no longer move there (phyper(5e16, 1e17, 1e17, 1e17) did not return). Below 2^53 the time grows as
the standard deviation, with a bound (a RangeError, see the limits under Hypothesis tests). Likewise dhyper, phyper and qhyper inside the support are NaN where m + n
is not exact in double precision (dhyper(0, 1, 1e16, 1e16): the population 1 + 1e16 rounds to k = 1e16, and R
gives 1, 0 for x = 1, 0); the ends of the support and the binomial limit (k / (m + n) below 2^-60) still answer.dwilcox, pwilcox and qwilcox with mn beyond 2^53 are NaN: the statistic ranges over 0..mn, whose
integers are not all doubles there (as phyper above). The table was built in min(m, n) passes even for one
entry (dwilcox(0, 1e12, 1e12) would have taken about 50 minutes).
The bound is on the exact product: m = 3, n = 3002399751580331 (mn = 2^53 + 1, which rounds to 2^53) is NaN too.
Likewise dsignrank, psignrank and qsignrank are NaN for n >= 2^27, where n(n + 1)/2 exceeds 2^53 (R’s
psignrank(5, 134217733) did not finish in two minutes).omega adds a warning when the minres fit (L-BFGS-B) does not converge (“minres did not converge …”);
psych’s fa goes on from the last point silently. The values are the same.mauchlyTest drops the rows of y with a missing value and those with a missing group (as lm(y ~ group));
an infinite value is an error.aovEz (fewer subjects than between-subject parameters, or as
many) and in mauchlyTest (as many complete rows as groups), where R returns NaN.icc, cronbachAlpha and the other functions on rating matrices reject infinite values (“contains infinite
values”).poissonTest requires a finite T and r (R accepts Inf). The one-sample test accepts confLevel 0 and 1
as R does (the two-sample test, as binomTest, needs 0 < confLevel < 1).
coxph takes the covariates as a matrix (no formula), so the cluster is only the cluster option (R’s
cluster() term of the formula, and R’s warning when both are given, do not exist). With the robust variance, a
single cluster is an error “at least two clusters are needed for the robust variance” (R fails with “(subscript)
logical subscript too long” for two or more covariates). Cluster labels that are numbers with the same 15-digit
text are one cluster, as strata. An infinite case weight is an error “‘weights’ must be finite” (R’s check of the
weights, > 0, lets it through). Weights of 2^64 or more are fitted divided by the power of 2 of the largest, which
leaves the coefficients and the robust variance as they are (weights × 2^1015, or one weight of 1e308 among
weights near 1, gave a coefficient 0 or NaN when the risk sums were formed from the weights as given); the log
likelihoods, the score test and the naive variance are scaled back (the log likelihoods −Inf where they are
beyond the doubles). R’s own results for a coefficient running off to infinity over many iterations depend on the platform (x86_64
and arm64 R differ by 1e-7 after 20 iterations), so such fits agree with R only to that size.omega with one factor reports the group column of the Schmid-Leiman matrix and the group omegas as exactly 0;
R reports the square roots of rounding residues (about 1e-8). With four or more group factors R’s own results move
by up to 4e-11 when the data change in the last bit, so omega agrees with R to about that size there (1e-12 with
up to three).
binomCI, binomDiffCI, binomRatioCI and oddsRatio (DescTools’ BinomCI, BinomDiffCI,
BinomRatioCI, epitools’ oddsratio) take one case per call (DescTools recycles vectors) and treat input without a
defined result as an error: x > n, a negative or non-integer count, n = 0 and a level outside (0, 1) throw, where
the packages return NaN, a number (agresti-coull of 11/10 gives [0.80, 1]) or round the counts (epitools, through
fisher.test). A two-sided level below 0.5 is accepted (BinomCI stops with “‘conf.level’ has to be in [0.5, 1]”);
a one-sided level must be at least 0.5 (the two-sided level 1 - 2(1 - c) at least 0). binomRatioCI applies
sides as the other two do (the other limit becomes 0 or Infinity); DescTools computes the one-sided level but
keeps both limits of that two-sided interval. Wilson’s limits at x = 0 and x = n are exactly 0 and 1 (DescTools:
0.99999999999999989 for 10/10 at 50%), so that Newcombe’s "score" difference of 0/10 against 10/10 has the lower
limit -1 (DescTools: -1.0000000022). "wilsoncc" at x = 0 or n has no “NaNs produced” warning (DescTools warns
about the limit that it then replaces by 0 or 1). oddsRatio gives the score interval of epiR’s epi.2by2 as its
method "score" (no other package in scope has it), its mid-p estimate and limits at a zero cell as exact2x2 does,
and does not have epitools’ method "small". A table of zeros is an error (epitools: the estimate 0, [0, Inf], the
p-values 1 and a chi-squared p-value NaN), and so is a table beyond the limits of the exact computation (performance:
a support above 2^23 values for "midp" and "fisher"); "wald" and "score" take counts above 2^31 - 1, where
epitools fails in fisher.test. epiR’s other numbers of epi.2by2 are those of these functions:
the risk ratio (Wald = "katz.log" away from zero counts, score = "koopman"), the odds ratio ("wald",
"score", "fisher") and the attributable risk (binomDiffCI "wald" and "mee", times 100; binomDiffCI
clips the Wald interval to [-1, 1], epiR does not).fisherTest(midp: true) (exact2x2’s fisher.exact(midp = TRUE)) is an option of fisherTest for 2 × 2
tables (an error for larger ones); its two-sided test is always the central one (exact2x2 stops with “midp option
not supported for tsmethod=’minlike’ or ‘blaker’”), and there is no tsmethod: exact2x2’s tests without mid-p (its
default minlike test with the matching interval, rounded to 4 decimals, and the central test) are not offered. A
level of 0 is an error (exact2x2 returns the point interval at the mid-p median). The estimate is the conditional
MLE as fisherTest gives it (the root; exact2x2 reports fisher.test’s).boschlooTest (Exact’s exact.test(method = "boschloo")) takes the 2 × 2 table with the groups in the rows and
the events in column 1, as Exact, and its alternative in Exact’s orientation ("less": pi1 < pi2; exact2x2’s
boschloo() uses the odds ratio of group 2 to group 1, the opposite one). The default two-sided method is
"square" (Exact’s; exact2x2’s is "central"). Not offered: confidence intervals, Berger and Boos’ restricted
nuisance range (np.interval), the mid-p version, and exact2x2’s p-value (the maximum over 98 grid points, with ties
split by floating-point equality and the tables (0, 0) and (n1, n2) left out). The region keeps the tables whose
statistic is within a relative 1e-7 of the observed one (Exact compares the statistics rounded to 12 significant
digits); statistic is not rounded. The result has the one value nuisanceParameter (Exact’s np may list
several) and not the sample sizes as parameter.gTest (DescTools’ GTest) takes a table or a vector (no second factor y); a table with one row or column is
a goodness-of-fit test, as DescTools. Yates’ correction is DescTools’ on purpose: the diagonal moves up when
ad - bc is 0 (so [[5, 5], [5, 5]] gets G = 0.2003 instead of 0) and no cell stops at 0 ([[0, 1], [0, 1]] gives NaN
with “NaNs produced”); parameterName is DescTools’ "X-squared df". The degrees of freedom count empty rows and
columns, as DescTools. Williams’ correction with an empty row or column is an error (its q has 1/0: DescTools gives
q = Inf, G = 0 and p = 1, as for [[10, 0, 3], [2, 0, 8]]). ftResiduals (the Freeman-Tukey deviates of the counts given, without Yates’ correction) is
not in DescTools.stuartMaxwellTest (DescTools’ StuartMaxwellTest) has K - 1 degrees of freedom, K the categories left after
removing those without counts off the diagonal; DescTools keeps the original number less 1 ([[10, 0, 0], [0, 5, 3],
[0, 2, 8]]: df 1 and p = 0.6547, DescTools df 2 and p = 0.9048). Categories whose off-diagonal counts fall into
unconnected groups (the covariance matrix is singular) are an error. No second factor y.goodmanKruskalGamma (DescTools’ GoodmanKruskalGamma) always returns the interval (level 0.95 by default) and
the standard error ase, as an object; DescTools returns gamma alone without conf.level. The levels 0 and 1 are
errors (DescTools: the point and [-1, 1]). Without concordant or discordant pairs gamma is NaN, as DescTools. The
variance leaves out the term (sum x psi)^2, which is 0 in the mathematics (DescTools subtracts its rounding, below
1e-30). No test of gamma = 0.lblTest (coin’s lbl_test, asymptotic) scores every factor 1..k, also one with two levels: coin leaves such a
factor unordered and codes it by an indicator of its first level, which turns the sign of Z ([[10, 5, 2], [3, 8, 6]]:
Z = 2.4074 here, -2.4074 in coin, and "less" and "greater" swapped), and refuses 2 x 2 tables, which are tested
here (Z^2 is the ‘N - 1’ chi-squared statistic). Scores are given as rowScores and colScores; only the
asymptotic distribution and a table (no formula, no blocks). Tables whose scores do not vary over the observations
are an error.chisqTest(nMinus1: true) is not in R: Campbell’s (2007) ‘N - 1’ chi-squared test, Pearson’s statistic without
continuity correction times (N - 1)/N, for 2 x 2 and r x c tables (method “Pearson’s ‘N-1’ Chi-squared test”). The
default continuity correction is then not applied; correct: true given with it, a vector (goodness of fit) and
simulatePValue are errors, and so is a total N of at most 1 (the factor (N - 1)/N would make the statistic 0 or
negative).ftResiduals of chisqTest and gTest is not in R: the Freeman-Tukey deviates sqrt(O) + sqrt(O + 1) -
sqrt(4E + 1) (Bishop, Fienberg and Holland 1975), computed without the cancellation of that formula (it loses
eps sqrt(O) absolute: -31.236670803616562 for -31.236670803616877 in [[1e5, 2e5], [3e5, 4e5]]). The variant
2 (sqrt(O) - sqrt(E)) is not offered.tost (equivalence’s tost) names its fields as the other tests: pValue (R’s tost.p.value), confInt and
confLevel (tost.interval and its attribute), seDiff (se.diff), parameter (the df); result keeps R’s
strings "rejected" and "not rejected". There is no null.value. The difference, its standard error and the
degrees of freedom are tTest’s (missing values dropped as there), so the values agree with R to the last bits of
the t quantile and tail (within 1e-13 relative over the fixture). A confLevel of 0.5 or less and an alpha of 0.5
or more are errors (the 1 - 2 alpha interval would be a point or reversed; R checks only that conf.level lies in
(0, 1)), and so is an epsilon that is not positive and finite. The paired test (paired: true, method
"Paired TOST", estimate “mean of the differences” as R) is tTest’s paired test with the same two one-sided tests.ICC (psych’s ICC) accepts complete data only (missing ratings are an error; psych’s lmer path handles them).
Ratings that are all equal, or the same for every subject, are errors (psych: rounding noise such as ICC -8e-16);
fewer than 2 subjects or raters too. Where the residual mean square is exactly 0 (ratings that differ between
raters by constants) F is Infinity and p 0, and ICC3, ICC3k and their bounds are 1; aov’s warning essentially
perfect fit for ‘1’: summary may be unreliable is kept on the ANOVA path then. lme4’s boundary (singular) fit
message is not a warning. The interval of ICC2k is psych’s (ICC2’s bounds transformed by Spearman-Brown), not that
of icc with unit: "average" (irr’s, McGraw and Wong’s formula): for the 6 × 4 data of Shrout and Fleiss [0.0711,
0.9272] against [0.0394, 0.9286]. Only the six rows and the mean squares are returned (no stats table, lme or
summary), and check.keys is not offered.tTOST (TOSTER’s t_TOST) treats mu as one rule: the effect is the difference (or the one-sample mean) minus
mu, Δ - mu, everywhere. The bound tests compare Δ - mu with [low, high], and the raw estimate, the raw interval and
the standardised difference are those of Δ - mu, for one, two and paired samples. TOSTER uses mu inconsistently:
its bound tests compare Δ itself with the bounds, its raw estimate is Δ - mu but its raw interval that of Δ, its
two-sample standardised difference that of Δ + mu, and its paired one that of Δ (only the one-sample standardised
difference is of Δ - mu). With mu 0 (the default) the two agree. The "t" and "z" intervals of the one-sample
standardised difference are 1 - 2 alpha intervals as in the other designs (TOSTER’s are 1 - alpha). TOSTER’s notes (Equivalence interval does not include zero., the
note on SMD bounds and the MET note) are warnings; its decision sentences are not reproduced. alpha must lie in
(0, 0.5) (TOSTER accepts 0.5, a zero-width interval), and bounds in the wrong order are an error. The paired SD of
the differences is computed from the differences (TOSTER’s sqrt(s1² + s2² - 2 r s1 s2) cancels for r near 1). With
smdCi: "goulet" and a difference of exactly 0 the limits are the continuous limit of the formula (TOSTER uses
another expression there).tsumTOST (TOSTER’s tsum_TOST): the one-sided p-values are upper tails (TOSTER’s 1 - pt(t, df) loses small
ones); otherwise as tTOST. Paired samples need r12 in (-1, 1).binomDiffEquivalenceTest is not in R: the test of equivalence of two proportions on counts by two one-sided
score tests (Miettinen-Nurminen by default, Farrington-Manning "mee" or Wald), dual to binomDiffCI with the same
method at the level 1 - 2 alpha. For 0/1 data it is the test to use rather than tost, whose t approximation has a
variance of 0 for a group of all 0s or all 1s. The margin is symmetric, (-margin, margin) with margin in (0, 1).roc, auc, ciAuc, rocTest and coords (pROC): the curve, its AUC (U/(mn) from the counts, rounded
once; pROC’s trapezoid sum differs by an ulp), DeLong’s interval and tests and the bootstrap (R’s random stream:
after setSeed the same draws and values as pROC) agree with pROC within 1e-13 relative. Differences:
naRm: false
(pROC: NA). A curve of the { controls, cases } form is never treated as paired with another curve (it has no
response to compare).confLevel 1 ciAuc
gives [0, 1] as pROC, also when the variance is 0.rocTest uses DeLong’s test unless method is given (pROC switches to the bootstrap silently for curves of
different directions), and checks confLevel also then (pROC: NaN limits). Venkatraman’s test, the sensitivity
and specificity tests, smoothing, percent and the ci.coords family are not offered.ciAuc with the bootstrap returns the curve’s AUC as estimate and the interval (pROC’s middle value is the
median of the bootstrap AUCs). A stratified bootstrap needs at least two controls and two cases (pROC resamples a
single value x ≥ 1 from 1, …, x); a non-stratified resample without controls is dropped with the warning of one
without cases (pROC stops with “missing value where TRUE/FALSE needed”). With rocTest, the count in “auc with partialAuc: limits outside [0, 1] are an error (pROC: NA), as is McClish’s correction below the
diagonal (pROC: NA with the warning “Partial AUC correction not defined for ROC curves below the diagonal.”).
The correction is computed exactly from the counts of the points and rounded once, so a curve on the diagonal
gives 0.5 rather than counting as below it, and limits near 0 keep their digits (pROC’s rounded areas can differ
in the last bits, or by more for limits near 0).coords: all columns from the integer counts (see above); "best" returns every row tied exactly; the cost in
bestWeights must be positive (pROC does not check it); youden is pROC’s se + r·sp, not se + sp − 1. The
columns are camelCase (lrPos, lrNeg, closestTopleft).diagnosticTests (epiR’s epi.tests) returns sensitivity, specificity, the predictive values, the likelihood
ratios, accuracy, the diagnostic odds ratio and the two prevalences with their intervals, not Youden’s index, the
number needed to diagnose or epiR’s p.* rows. Methods "exact" (epiR’s “exact” and “clopper-pearson”, computed
directly), "wilson" and "jeffreys"; Jeffreys’ interval is binomCI’s, 0 at x = 0 and 1 at x = n (epiR: the beta
quantiles there). epiR’s "agresti" (which changes the estimates) is not offered. A zero row or column total, non-
integer counts and a level outside (0, 1) are errors (epiR: NaN, the counts used, NaN limits); zero cells give
infinite ratios and NaN limits as epiR. The option prevalence adds the predictive values at that prevalence.blandAltman (BlandAltmanLeh’s bland.altman.stats) names its fields in camelCase (meanDiff, lowerLimit,
upperLimit, criticalDiff, n for based.on) and returns the intervals as pairs (meanDiffConfInt,
lowerLimitConfInt, upperLimitConfInt) instead of the vectors lines and CI.lines; the complete pairs (groups)
are not returned. Fewer than 2 complete pairs, infinite values and a level outside [0, 1] are errors (R: NA or NaN
limits, with the warning “less than 2 data pairs after deleting NAs” for the first). The option ciMethod: "exact"
is not in the package: the exact interval of the limits of agreement from the noncentral t distribution (Carkeet
2015), wider than the package’s limit ± t sqrt(3 s²/n) for small n (3% at n = 17, 6% at n = 10, twice at n = 2).
For identical methods (s = 0) every interval is the point d̄, also at the level 1 (R: NaN there). Data of order
2^±500 and beyond, where R’s sd() over- or underflows, give the results of the unscaled data times the power of 2.mcreg (mcr’s mcreg) is one function with the options in camelCase and confLevel (= 1 - mcr’s alpha); the
result has intercept and slope as { estimate, se, confInt } (mcr’s @para), xmean, weights (@weight),
jackknife (@B0jack, @B1jack), bootstrap (@B0, @B1, @sigmaB0, @sigmaB1, @glob.sigma, @nsamples) and,
for Passing-Bablok, cusum with mcr’s calcCUSUM statistic (nPos, nNeg, maxCusum; not the path). The
default interval is "analytical" ("jackknife" for weighted Deming), not mcr’s random bootstrap with 999
resamples; the bootstrap with rngSeed gives mcr’s resamples for the same rng.seed (R’s stream), and without it
draws from the current stream. Only Deming, weighted Deming and Passing-Bablok: no PaBaLarge (and NBins),
LinReg, WLinReg, PBequi or TS; no names of the methods or samples. Passing-Bablok’s slope at an odd position
is dy/dx itself (mcr: tan(atan(dy/dx)), a few ulps off, 0.99999999999999989 for 1); for a slope of exactly 1 this
can change the CUSUM, where mcr’s residuals of the points on the line are tiny positive numbers and here 0 (6
points above the line and a maximum of 0 in mcr, 1 and 0 here, for x = 1..6, y = 1..5, 6.5). Where Passing-Bablok’s
interval is not defined (too few points, always for n <= 4) the limits are -Inf and Inf as in mcr, with a warning
(mcr gives none). Data with a Deming covariance of 0 are an error (mcr: NaN), and so are 2 or fewer pairs, constant
x or y, infinite values, a negative value for Passing-Bablok and a value that is not positive for weighted Deming
(mcr’s restrictions, with rStats.js’s messages). The 1e-12 tie rule of Passing-Bablok is applied to the data
scaled by a power of 2 (the same ties; mcr’s rule overflows near the largest doubles). Weighted Deming stops as mcr
(an absolute threshold, iterMax, the warning “no konvergence after … iterations” with mcr’s spelling), so it
is not exactly invariant to the units of the data.subset takes the condition as a boolean per row or a function of the row ((r) => r.age >= 20), not an
expression; select is an array of names. A missing condition counts as false, as in R.split returns a Map (in R’s order of the groups), since a plain object would move integer-like names
first.aggregate summarises numeric columns with a function returning a number or the same number of values for
every group (R would also make list columns).pivotLonger and pivotWider return the data frame; tidyr’s warnings go to the optional onWarning
callback (without it, pivotLonger’s go to the handler of setWarningHandler). A cell that several rows fill is an error in pivotWider (tidyr warns and makes a list column):
summarise them with valuesFn. In pivotLonger, names (after namesTransform) that give one ".value" column
twice for the same key are an error (tidyr makes a row for each; issue #444). Regular expressions (namesSep,
namesPattern) are JavaScript’s. After a zero-width match of namesSep the split goes on one character (code
point) later, as stringr’s str_split: "A😀B" with "(?=.)" gives "", "A", "😀", "B"; tidyr 1.3.2 on
R 4.5.2 (gregexpr(perl = TRUE)) goes on inside the UTF-8 bytes of the emoji and gives "", "A", "😀", "",
"", "", "B" (issue #500).merge and cbind throw on a duplicated column name, which R allows but an object of columns cannot hold.lm with every weight 0 throws “all weights are zero”; R returns NA coefficients.lm with an infinite weight throws “non-finite weights not allowed” (as glm). R stops with
“NA/NaN/Inf in ‘x’” when the model has columns, but a model with no columns (y ~ 0) returns the residuals
y and sigma Inf (issue #302).glm takes the predictors as a matrix (or a vector), with a column of ones added
unless intercept is false, and the response as a vector or, for the binomial families, rows of
(successes, failures). Each column is one term: glmAnova adds the columns one by one (rows
"x1", "x2", …), so a factor coded as several columns is several rows of the table. Coefficient
indices (parm of glmConfint) are 0-based, intercept first.glmAnova warns about a model that has not converged (“model k has not converged: its deviance is not that of
the maximum likelihood fit”); the table is R’s. R’s anova tests such fits without a word.glmConfint computes the exact profile likelihood limits. R’s confint for a glm moves each
coefficient on a grid of steps of about 1/5 of its standard error and interpolates a spline through
the signed roots of the likelihood ratio (or score) statistic; its limits are up to 4.5e-4 standard
errors from the exact ones in the test fixture. rStats.js solves z(b) = qnorm((1 ∓ level)/2) by
Brent’s method, with the fit and every profile refit iterated until the coefficients stop changing
(R’s rule on the relative change of the deviance stops while they can still move by about
sqrt(epsilon)), and the dispersion from the converged fit. The limits agree with the exact references
of the test fixture (computed in R from fits converged in the same way) to 1e-14 standard errors.
At a very small level (the cutoff below 2^-9, level below about 1.6e-3) the cutoff comes from the series of
sqrt(2) erfinv(level), and the limits from the inverse profile interpolated through the limits at z = 0, ±2^-9 and
±2^-8, as the deviance difference cannot resolve a smaller z (its relative error is about epsilon D / z²); they are
within about 1e-10 relative of the exact ones (intercept-only binomial and Poisson fits). R gives [0, 0] at level
1e-20 (1 + level rounds to 1) and is 1.6e-4 relative off at 1e-10; rStats.js before #179 gave [-7.2e-10, 1.5e-8]
for ±1.2533e-10 there.setWarningHandler): glm’s result has R’s
warnings in warnings (each message once, in order of first appearance), including those of R’s dpois in the Poisson AIC
("non-integer x = 0.500000") and of sqrt in the 1/mu^2 link ("NaNs produced").
glmSummary and glmAnova return their own ("observations with zero weight not used for
calculating dispersion", "using F test with a 'binomial' family is inappropriate", and those of
the refits of glmAnova); glmResiduals, the influence measures and glmPredict return none.
The intercept-only refit for the null deviance of a model with an offset reports the warnings of
its iterations too (R’s glm.fit gives them as well).etastart and mustart (use start), method, singular.ok = FALSE, and the
x, y and model flags (the model matrix and response are always kept, in model).vcovHC, vcovCL, coeftest, coefci)vcovHC and vcovCL: the values are those of the fit without
those rows (n is the number of rows of non-zero weight, and a cluster whose rows all have weight 0 does not
count). sandwich counts the rows in n but not in the bread, which scales every type by (n_ok / n)², and
recycles the hat values of the rows used against all rows (with R’s warning longer object length is not a
multiple of shorter object length); its values are 9% to 53% off in the test fixture.type: "const" is the model-based covariance of the fit (R’s vcov(fit): σ̂² (X’WX)⁻¹ for an lm, the
dispersion of summary.glm times (X’WX)⁻¹ for a glm). sandwich’s "const" is that only for an unweighted
lm; for a weighted lm it uses the unweighted X’X and for a glm Σ (W z)² / (n − k), which are 7% to 75% off
vcov(fit) in the test fixture. With sandwich: false the meat is the one whose sandwich is vcov(fit)
(omega_i = dispersion W_i / phi_s²).vcovHC throws a RangeError naming the observations; R’s warning about hat values close to 1 is kept for the
finite results (HC0, HC1 and hat values below 1).vcovHC) or (n − 1) / (n − k)
(vcovCL) is infinite and sandwich returns a matrix of NaN; rStats.js throws a RangeError.coeftest and coefci take the standard errors from its scaled form, so that the
standard errors, statistics, p-values and limits are right where R’s are Infinity, 0 or NaN. That scaled
form is kept with the matrix object returned: a copy of the matrix gives the values it holds (se 0, z
Infinity, p 0 where it holds 0). The meat (sandwich: false) likewise has entries ±Infinity or 0 where its
values are beyond the doubles, with the same scaled form (formed in doubles, they came out NaN, Infinity −
Infinity). An omega function given for a gaussian glm whose response is far from 1 receives the residual
factors in the fit’s units, formed in units of powers of 2 (W z / phi_s in doubles is 0 or Infinity beyond
about 2^±512, where phi_s overflows or underflows). With fix, negative eigenvalues are looked for on the
matrix scaled to unit diagonal, so a positive definite covariance is kept as it is whatever the units of the columns; where an
eigenvalue is negative, it is set to 0 in the units of the largest variance, as in R, and coefficients whose
scale is about 2^537 or more below the largest then get variance 0 (R’s have no correct digits from about
2^26 apart on).at least two clusters are needed), where R fails with non-conformable arrays.vcovCL’s default type is HC1 for an lm and HC0 for a glm, as sandwich’s (a glm is not an lm for its
test).coeftest and coefci: a covariance with a negative, NaN or infinite variance is a RangeError (R gives
NaN standard errors with NaNs produced, or carries NaN and Infinity through to the statistics and p-values),
and so is a level outside [0, 1] (R gives NaN limits). Only the diagonal is used, as R’s: the matrix is not
checked for symmetry. The vcov option takes
a matrix (matched by position; it must be p × p, or k × k for the coefficients that are not aliased, where R
recycles), the result of vcovHC or vcovCL (matched by name) or a function of the fit; options of the
covariance function are passed by closing over them instead of R’s .... parm takes 0-based indices. As
lmtest, a glm gets z tests and normal quantiles by default for every family.lmer returns the exact optimum of the REML criterion (or the ML deviance), found by Newton’s method with
the analytic gradient. lme4’s optimiser stops when its own tolerances are met, typically 1e-9 to 1e-5 (relative)
from the optimum in θ, so θ, the variance components (VarCorr), the standard errors and the random effects
differ from lme4’s in about the 5th to 9th significant digit; the fixed effects and the log-likelihood agree to
more digits (the criterion is flat at the optimum). lme4’s convergence warnings (Model failed to converge ...)
are not returned.singular and the message boundary (singular) fit: see help('isSingular') follow from it. Where lme4 stops
just inside the boundary (θ above its threshold of 1e-4) it reports a non-singular fit that rStats.js reports as
singular.(x | g)): when the variance of the first column goes to 0, lme4’s
bound-constrained optimiser can stop at a point that is not a minimum, because the criterion does not change
when a column of the covariance factor changes sign. rStats.js minimises without that bound and reports the
equivalent factor, so it can reach a lower criterion than lme4 there (a better fit of the same model).The computation is sparse, as lme4’s, but in JavaScript: a fit takes about 2.5 to 3 times lme4’s time (see performance.md).
lmer has but rStats.js does not support (weights, offset,
subset, naAction, control, start, …) is an error, and so is an unknown key (a RangeError, as in every
function; R’s error is unused argument (reml = FALSE)). lmerTest’s summary, contest and anova ignore unknown arguments (summary with a
warning); lmerSummary, lmerContest and lmerAnova reject them. The logical options (REML, joint,
confint, refit) take booleans and numbers (0 is false), as R does, but not strings (R accepts "TRUE", "F"
and the like).A random-effects term without columns ((0 | g), (0 || g)) is an error with its own message, where lme4
fails with internal messages.
lmerSummary, lmerContest, lmerAnova) use exact (analytic) derivatives of the deviance
and of the covariance of the fixed effects at the exact optimum; lmerTest differentiates numerically at lme4’s
approximate optimum. The Satterthwaite degrees of freedom therefore differ from lmerTest’s in about the 4th to
8th significant digit (agreeing to about 1e-13 with references computed in 128-bit arithmetic), and the p-values
correspondingly. The Hessian’s warnings (Model failed to converge with ..., Model may not have converged
with ...) are decided from the exact Hessian and returned in each result’s warnings, not emitted when the
model is fitted. Only Satterthwaite’s method is available (not Kenward-Roger’s, nor ddf = "lme4" in
lmerAnova); ranova, ls_means, difflsmeans and step are not implemented.lmerContest with joint: false accepts a right-hand side per row of L (rhs: [1, 0, 2]), each row tested
against its own value; lmerTest gives an error there.lmerContest with a NaN or infinite L or rhs is an error (lmerTest gives a row of NaN for an infinite L, F Inf
with p 0 for an infinite rhs, a row of NA for NaN in L, and t (F) and p NA for a NaN rhs). level must be strictly between 0 and 1, as in
lmerTest.lmerAnova([fit1, fit2])): the REML fits are refitted by maximum likelihood to the exact ML
optimum (lme4’s refit stops near it); the fits must be results of lmer on the same data object, unchanged
between the fits. The hypotheses and refits of lmerAnova are built from a copy of the data taken at the fit, as R
uses the model frame stored in the fit.The denominator df of a joint F test takes the term ν/(ν − 2) of an infinite ν as its limit 1, and is infinite when every ν is (lmerTest’s formula gives NaN there, and an error when every ν is infinite).
glmer returns the exact optimum, and its covariance matrix of the fixed effects is computed from the exact
Hessian of the exact deviance at that optimum. lme4 stops its optimiser up to about 3e-3 away from the optimum in
the fixed effects, and takes the Hessian by finite differences of a deviance that its penalised IRLS perturbs at
the 1e-6 level, so its standard errors differ by up to about 1.3% (cbpp: 0.3032 in lme4, 0.3066 here), and much
more where lme4 warns that the model failed to converge or where the dispersion is small (a Gamma fit with log link
whose responses lie within 1e-4 of the model: the slope’s standard error 1.3565e-5 here, as the Hessian in 110-bit
arithmetic gives, and 1.951e-5 in lme4; within 1e-6: 1.357e-7 here, 7.0e-6 in lme4). The minimisation uses the
analytic gradient and works in the metric of the fixed effects’ covariance, so a predictor shifted far from 0 (years)
or rescaled gives the same fit transformed where lme4’s penalised IRLS can fail (binomial with x + 2000:
(maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate in lme4).glmer does not return lme4’s convergence and model warnings (Model failed to converge ..., Model is
nearly unidentifiable ..., Model failed to converge with max|grad| ...), as for lmer. The warnings of the
data and the response (for example non-integer #successes in a binomial glm!) and the fallback warning of the
covariance matrix are returned.glmer with nAGQ > 1: logLik, AIC and BIC are those of the true log-likelihood. lme4’s quadrature
deviance leaves out the constant of the saturated model (its Laplace deviance does not), so its logLik
is not comparable with the Laplace fit’s or with glm’s (cbpp with nAGQ = 2: −50.06 in R,
the log-likelihood −92.0 here). The estimates and the covariance matrix are R’s. glmerAnova of fits with
different nAGQ therefore differs from R’s: cbpp, Laplace against nAGQ = 5, Chisq 0.084 here and 84.04 in R.glmer with nAGQ > 1 for the Gamma, inverse.gaussian and gaussian families is a RangeError. lme4 holds the
dispersion at 1 in the quadrature deviance of these families, so its estimates are not maximum likelihood.
nAGQ > 1 is also an error for more than one scalar random-effects term, with lme4’s two messages.glmer with the gaussian family and the identity link (the default family) is a RangeError that tells to use
lmer; R warns that this shortcut is deprecated and returns the fit of lmer. A negative nAGQ (after the
truncation to an integer, so not −0.5, which is 0 as in R) is a RangeError (R uses 0).glmer fits where lme4’s penalised IRLS fails: an offset far from the data (log(exposure) such as
log(0.01 x), or a constant offset of −4: R’s Downdated VtV is not positive definite), started from glm.fit’s
linear predictor without the offset where lme4’s start fails; Gamma means beyond 1.3e154, whose squares overflowed
(the working weights from the powers of μ, as glm’s); and a Gamma response with the log link below 2^-40, which
meets lme4’s lower bound 2^-52 of the mean (R: pwrssUpdate did not converge in (maxit) iterations for a response
times 1e-20, θ 0 and a slope of 0 for 1e-150), fitted with the response divided by a power of 2 and the offset
shifted, which is the same model: the fit is the response’s as given, its intercept shifted by the log of the
scale. lme4’s step-halving tolerance is applied relative to the penalised deviance (lme4’s is absolute 1e-7).glmer at response scales its Laplace criterion cannot resolve is a RangeError (... outside what the Laplace
criterion can resolve ...). lme4’s criterion leaves out the dispersion, so for poisson, inverse.gaussian and
gaussian it is not invariant to the scale of the response or of the prior weights. Where the information about the
random effects at the start (Σ W z² of a column of Z) is above 2^40 (the penalised system then loses about 40 of
its 53 bits, and whether a fit converges depends on the platform’s last bits), or below 2^-40 where the fit fails
or a term ends at θ = 0 on a criterion flat to rounding, the error replaces lme4’s PIRLS messages, “did not
converge”, or a θ of 0 that is no estimate (inverse.gaussian with the log link and a response of 1e200, whose
optimum is near θ = 1e100). For data on the scale of 1 to 10 this means poisson counts up to about 1e11 (prior
weights up to about 2^34), inverse.gaussian with the log link up to about 1e13 and gaussian with the log link from
about 1e-6 to 5e4. Gamma fits are not limited by the scale of the response.glmer with non-integer poisson counts is a RangeError for nAGQ 0 and 1: R’s dpois is 0 there, so the
Laplace log-likelihood is −Inf for every parameter, and R warns non-integer x = ... and returns its starting
values (θ = 1) with logLik −Inf. With nAGQ > 1 the estimates are R’s, with its warning, and logLik is −Inf
(the true log-likelihood; R leaves out that constant).glmer: cbind(successes, failures) is accepted on the left-hand side only, with two column
names (not with expressions such as cbind(s, n - s); any other function call stays an error); a string
response is a factor for the binomial family (R: response must be numeric or factor), the first level being a
failure (levels sets the order). weights and offset are arrays or column names.glmerAnova also compares glm fits with glmer and lmer fits (R compares them as well, and refuses a glm fit
with a glmer fit with nAGQ > 1; the true log-likelihood makes them comparable here). A Chisq test is given only
for nested fits of the same family, link and offset; R gives one for any pair, for example a probit glm against a
logit glmer. lmerAnova accepts lmer fits only.glmerPredict, lmerPredict): an offset of a glmer fit that was given as a column name is read
from newdata, one given as an array is replaced by the option newoffset (default 0); R ignores the offset
argument of glmer and uses 0 in predict for it. A new level of a factor of the fixed part in newdata is a
RangeError (factor g has new level c; R: non-conformable arguments). Without newdata, the fit’s rows are
returned (R fails when the fit dropped a row with a missing grouping value). The standard errors (seFit) are
computed from the conditional covariance of the random and fixed effects and are correct where lme4’s se.fit is
wrong: with crossed or nested grouping factors (lme4 permutes the factor) and with re.form that drops a factor.
They are finite where only their sum of squares overflows (newdata of 1e200: Infinity in R), and a linear
predictor whose products overflow while they cancel is the exact inner product (NaN in R), as for predict of
lm and glm.qrSolve keeps a NaN of the solution (from a NaN in the response); only the coefficients of the columns the
decomposition leaves out (of a wide matrix) are 0. R’s qr.solve sets every NA and NaN to 0 (qr.solve of the
identity with b = (NaN, 1) is (0, 0)).dgeev only makes that component real). Vectors for repeated eigenvalues or
singular values, and singular vectors beyond min(rows, columns), are not unique and generally
differ from R.svd uses Golub–Reinsch and eigen uses the EISPACK algorithms tred2,
tql2, orthes and hqr2 (R uses LAPACK’s dgesdd, dsyevr and dgeev). Values agree to
rounding. The general eigen balances the matrix first as dgeev does (dgebal). eigen, svd and schur
scale a matrix whose largest entry is outside [2^-256, 2^256] by a power of 2 before the decomposition (exact),
so that its sums neither overflow nor underflow: a small matrix up to near 1, a large one down only to 2^256
(eigen: 2^459, as dgeev, so that the balancing sees entries down to 2^-1481 of the largest:
eigen(matrix(c(1, 1e-200, 1e200, 2), 2)) gives 2.618 and 0.382 as in R), so that entries down to 2^-1278 of the
largest stay in the normal range. R’s LAPACK scales down to about 2^459, so smaller entries keep more bits in R’s
svd and Schur form: svd(diag(c(1e308, 1e-80))) gives 1e-80 in R and 9.9999999999995e-81 here
(and ginv(..., tol = 0) 1e80 and 1.00000000000005e80); an entry below 2^-1331 of the largest
(diag(c(1e308, 1e-308))) becomes 0 in both.rcond of triangular matrices solves by plain substitution instead of dlatrs (which
rescales to avoid overflow), so matrices on the edge of overflow may give a different value.
Where the substitution overflows (also in the estimate from the LU decomposition), the estimate
is repeated with the vectors divided by a power of 2 (see the table above); R gives 0 for the
matrices tried there.chol propagates NaN on the diagonal instead of failing (R’s OpenBLAS does the same; the
reference dpotf2 stops). With pivot: true, a rank-deficient matrix returns rank instead
of a warning (the trailing submatrix is zeroed, as in R 4.6).solve with NaN or Inf in the matrix solves without the condition check (LAPACK 3.12’s
dgecon returns an error that R ignores); rcond of the same matrix throws.lu of a matrix with NaN or an infinite value throws “the matrix contains NaN or infinite values”, as svd,
qr and eigen do. Matrix::lu (LAPACK’s dgetrf) returns factors with NaN or infinite values, which need not
give back the matrix: for matrix(c(Inf, 1, 2, 3), 2) the multiplier 1 / Inf is 0, so P L U has NaN (0 × Inf) where the matrix has 1.splinefunH, and splinefun with
method: "monoH.FC", deriv = 3): rStats.js returns the mathematically correct value,
(6 m_i + 6 m_{i+1} − 12 δ) / h² on an interval of width h. R (4.5.2 and R-devel) returns h times
that, dividing by h only once, which looks like a bug in R; the two agree on intervals of width 1.
For example splinefunH(c(0, 2), c(0, 0), c(1, 1))(1, deriv = 3) is 6 in R and 3 here.These were determined from R’s documentation and observed output, and for the special functions also from R’s source. They are listed because they are easy to get wrong.
dhyper returns NaN for
non-integer m, n, k; phyper and qhyper round them. Signrank/wilcox n and m are rounded and
give NaN if ≤ 0. (How q is taken to a count differs from R; see the deliberate differences.)pbeta returns 0 or 1 for x ≤ 0 or x ≥ 1 even with invalid parameters.
Non-central chi-squared and beta with ncp = Inf give NaN (qchisq returns values only at the
end points). pf(·, Inf, df2, ncp) is NaN; df(·, Inf, df2, ncp) ignores ncp.dgamma, pgamma, qgamma) with a rate below about 5.6e-309 (subnormal):
scale = 1 / rate overflows to Inf, and the distribution is treated as lying at +Inf: pgamma and dgamma
are 0 at every finite x and qgamma is Inf, as in R (some quantiles of the exact distribution would be finite,
for example about 0.3 for qgamma(3.3e-160, 0.5, rate = 4.19e-319)). Only pgamma(Inf, ...) differs (1, not
NaN; see the table of deliberate differences).ptukey returns NaN for nmeans < 2, df < 2 or nranges < 1; non-integer nmeans and nranges are
accepted.qcauchy with scale = 0 returns
location before looking at p) follows R.wilcoxTest, corTest). Paired tests
remove pairs. cor with the default use: "everything" returns NaN when the data contain NaN,
as in R.tTest accepts exactly 0 and 1 (1 gives ±Inf);
wilcoxTest (only when confInt is true) and fisherTest (always) require an open interval;
corTest checks it only for Pearson.tTest: data are “essentially constant” (an error) when the standard error is below 10ε
times the absolute mean. The equal-variance method name starts with a space
(" Two Sample t-test"), as in R.chisqTest: Yates’ correction subtracts min(0.5, min |O − E|) from all cells (SciPy
corrects per cell); if that amount is 0, the method name does not mention Yates. Matrices of
2 × 2 or larger reject negative, NaN and Inf entries; vectors and 1-row or 1-column matrices
reject negative and NaN entries, Inf gives a NaN statistic, and 1-row or 1-column matrices are
treated as goodness-of-fit tests. p must sum to 1 within sqrt(ε) and is used without
renormalising. No alternative is returned.fisherTest: the odds-ratio estimate and interval reproduce R’s uniroot behaviour,
including its error: the value at ψ = 1 decides whether to search ψ ∈ [0, 1] or 1/ψ ∈ [ε, 1]
with Brent’s method (tolerance ε^0.25), so results can be up to 0.7% from the true root (the
upper limit for the tea-tasting table is 621.93 in both R and rStats.js; the true root is
626.24). The two-sided p-value sums tables with probability up to 1 + 1e-7 times the observed
one. Non-integer counts are rounded half to even. A 2 × 2 table with a zero margin gives p = 1,
estimate 0, interval [0, Inf]. For r × c tables alternative is not checked and is returned as
given. No statistic is returned.wilcoxTest: as R 4.6, by default (exact unset) the exact method is used for n < 50 (zeros
counted; both samples < 50 for two samples). With ties or zeros the exact test is the conditional
test given the mid-ranks; the exact signed rank test ranks the zeros with the data and leaves them
out of the scores (Pratt), while the normal approximation drops them first. Exact intervals report
the achieved confidence level. Normal-approximation intervals and estimates use the same search
range and objective as R and match to the last digit. correct 1 to 3 adds Edgeworth terms to the
normal p-value (without ties and zeros).corTest: Spearman’s exact test (Best and Roberts 1975, AS 89) is used for n ≤ 1290
without ties (R’s help says n < 1290, but 1290 is exact too): full enumeration for n ≤ 9,
Edgeworth series above. The p-value uses round(S). Spearman’s continuity applies only to the
t approximation and always moves rho towards larger values, (rho + d)/(1 + d) with
d = 6/(n³ − n), regardless of sign or alternative; this looks like an R bug but is matched.
Kendall’s exact test is the default for n < 50 without ties, and exact: true forces it for
n ≥ 50; continuity replaces S with sign(S)(|S| − 1). Pearson needs at least 3 pairs, Kendall
and Spearman at least 2; intervals need at least 4. Constant data give NaN statistic, p-value
and estimate.ansariTest interval (confInt: true): computed as R 4.6 does, with the locations taken as
qansari quantiles (whose cumulative sums have no slack, so a
probability that is exactly 1/2 can be missed by rounding, as in R), and limits that cannot be
formed are NaN (R’s NA). Normal approximation: the standardised statistic (with ties, R 4.6’s mean
and variance of the observed scores; R 4.5 took the no-ties mean) crosses the normal quantiles; the roots are
found with uniroot (tolerance 1e-4) between the smallest and largest ratio of the positive values
and of the non-positive x to the negative y; 0 / 0 at s = 0 is ranked last, as R’s rank puts NA
last.chisqTest, fisherTest): (1 + number of simulated statistics at least
(1 − 64ε) times the observed one) / (B + 1); for fisherTest, simulated tables whose
−Σ log(x_ij!) is at most the observed one / (1 + 64ε). The method gets R’s suffix
" with simulated p-value\n\t (based on B replicates)" and the parameter is NaN (R’s NA).
chisqTest uses the uncorrected statistic, does not simulate when a margin is 0 (the ordinary
test), and for goodness of fit draws B n categories at once and counts them n at a time (with a
non-integer total n, R’s matrix of floor(n) rows, recycled, is reproduced). fisherTest drops
empty rows and columns first and ignores simulatePValue for 2 × 2 tables. In both functions B must be a positive
integer: R runs no simulation for B = 0 and returns p = (1 + 0) / (0 + 1) = 1, a value computed from no data
(issues #488 and #489).pAdjust: n defaults to the number of non-NaN values, and a smaller n is an error.
p-values outside [0, 1] are processed, with only the upper end capped at 1. Abbreviated method
names are case-sensitive."log") and with lambda = 1 the
identity; other power links are named "mu^" with lambda rounded to 3 decimals. The inverse links
and their derivatives do not have R’s eps (2^-52) clamps (logit beyond |eta| > 30, the log link,
probit and cauchit at the eps quantile, cloglog, power): they give the exact values, kept within
the doubles by the least double and, for probabilities, the largest double below 1 (see the
table: the logit, probit/cauchit/cloglog/power and log link rows).epsilon: 1e-14 an exactly collinear column is no longer aliased.round. Rows of prior weight 0 are left out of the
likelihood in every family, where R’s gaussian AIC is infinite (see the row “AIC of a gaussian glm with rows of
weight 0” under “Where R is inaccurate and rStats.js is closer to the truth”).glmAnova: the refits of the sequential table use the same start as the fit, which has the
wrong length for the smaller models (an error, as in R); the default test is "Chisq" when the
dispersion is known and "F" otherwise (R 4.4.0 and later).qr default pivoting: columns are processed left to right; a column whose remaining norm
is below its original norm × tol (always, if the original norm is 0) is moved to the right end,
and moved columns are still transformed when their turn comes. rank = min(columns − moved,
rows).qrFitted, qrResid: with k = 0 they return y unchanged; a 1-row matrix has residual 0.qrX: ncol defaults to min(rows, columns); with pivoted columns, an ncol smaller than
the number of columns is an error. An ncol above max(rows, columns) is an error (R pads zero
columns, which are neither columns of x nor of an orthogonal completion); ncol 0 gives an empty matrix as in R.qrSolve: an error unless rank = min(rows, columns). For wide matrices the unused
coefficients are 0. b may be omitted only for square matrices.qr(x, { lapack: true }): qraux (tau) has min(rows, columns) elements, one
per reflection, as in R; rank is always min(rows, columns); qrFitted and qrResid throw. Matrices
containing NaN or Inf are not rejected (R also returns meaningless values; the values need not
match R’s). Where two columns tie for the pivot in exact arithmetic (e.g. cbind(a, b, a + b, b)),
rounding decides which comes first, in R as here: the reference LAPACK 3.12.1 is followed, and R’s
choice depends on its BLAS and platform (R 4.6.2 on aarch64 and on x86_64 differ); the rank, |diag R|
and Q R P’ = X do not depend on it.kappa: the default (exact: false) applies LINPACK’s dtrco estimate to R from a QR
decomposition (after transposing wide matrices). With norm: "I" it uses the same triangle of
the transposed matrix, as R does. triangular has an effect only with method: "direct", and
then also uses dtrco. As in R, these estimates through a triangular factor use the infinity norm only
for norm: "I" (not "i") and the 1-norm for any other norm; R’s warnings about the replaced norm are not
reported. Exact kappa of a singular matrix is Inf.norm: type must be a single letter (“One” is an error). type: "2" returns NaN if the
matrix contains NaN and throws if it contains Inf.eigen: a matrix is treated as symmetric when sum|A − Aᵀ| / sum|A| ≤ 100ε (as
isSymmetric), and then only the lower triangle is used. General matrices return eigenvalues
in decreasing modulus, ties in their original order (the conjugate with positive imaginary part
first).By default rStats.js returns what R returns;
{ rCompatible: false } returns the mathematical value instead.
choose and lchoose: R treats n within 1e-9 max(1, |n|) of an
integer as that integer, so choose(1e-10, 2) is 0 (mathematically -4.9999999995e-11) and
choose(5 + 1e-9, 2) is 10. For k < 30 choose keeps n in the product and rounds the result;
for k ≥ 30, and in lchoose for k ≥ 2, n itself is rounded, and for n < 0 the test is made on
k − 1 − n (so the tolerance is relative to it). lchoose(n, 1) is log|n| without rounding.choose(±Inf, k) is NaN for k ≥ 30 (±Inf below) and lchoose(±Inf, k)
is NaN for k ≥ 2; choose(n, Inf) is 0 and lchoose(n, Inf) is -Inf for finite n ≥ 0, NaN
otherwise. With rCompatible: false, choose(±Inf, k) is ±Inf for every k and
choose(n, Inf) is NaN.trigamma(-Inf) and psigamma(-Inf, deriv): R treats -Inf like the poles, giving Inf for
odd deriv and NaN for even (always NaN with rCompatible: false).choose and deriv in psigamma are rounded half to even (psigamma(x, 2.5) is
psigamma(x, 2)).integrate, optimize, uniroot) or of an
array (grad, jacobian, hessian); extra arguments (R’s ...) are passed through a closure.
ode’s func(t, y, parms) returns the derivatives as an array (deSolve’s list(dy)) and the
result is an array of rows [t, y1, y2, ...].sum accumulates in long double; exp, log, sin
and cos come from different libraries), the error estimate of integrate moves by up to a few
percent, a flat optimum by about 1e-14, and numerical derivatives by up to 1e-9 relative (a
difference quotient magnifies the function’s rounding by |f| / h).uniroot returns initIt as NaN when the interval was not extended (R’s NA) and does not
warn when maxiter is reached (iter is then maxiter, as in R).optimize searches with NaN and +Inf values of the function as the largest double and -Inf as the most
negative, as R does, without R’s warnings (“NA/NaN replaced by maximum positive value” and the like); objective
is the function’s own value there (NaN or -Inf, as in R).rnorm(3, mean = c(0, 10, 100))).hybrid and workspace, and Wilcoxon’s digits.rank. Kendall’s concordance count is O(n²).kappa’s inv_z, complex matrices, and EISPACK = TRUE / LINPACK = TRUE.glm (the predictors are a matrix; see ROADMAP.md).lmer: the covariance structures of lme4 2.0 (diag(), cs(), ar1() terms), weights, offset, subset,
na.action (rows with a missing value are always dropped), start and control; simulate, confint and
profile; lmerTest’s Kenward-Roger method, ranova, ls_means and step.glmer: subset, na.action (rows with a missing value are always dropped), control, mustart and etastart
(start for theta and the fixed effects is available), the quasi families; simulate, confint and profile
(see ROADMAP.md). nlmer (see ROADMAP.md).method = "complex"), which needs a function of a complex
argument, and the side argument of grad and jacobian.lsoda, ode45, …); ode has the fixed-step euler, rk2
and rk4.coxph: counting-process data (Surv(start, stop, event)), ties = "exact", offsets, tt() terms and
residuals (the score and dfbeta residuals behind the robust variance are not exported); concordance.omega: factoring methods other than minres, rotations other than oblimin, n.iter (bootstrap intervals) and
poly = TRUE.