First sample.
Second sample, of the same length as x.
Optionaloptions: CorTestOptions
See CorTestOptions.
The test result; see CorTestResult.
const r = corTest([1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 7, 8]);
r.estimate; // 0.9014600868406593
r.statistic; // 4.165113148435108 (t, df = 4)
r.pValue; // 0.01408675480909387
corTest([1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 7, 8], { method: "spearman" });
There is also a formula form, corTest("~ x + y", data, options) (next overload).
Test for correlation from a formula and a data frame. As R's cor.test(formula, data): the one-sided
formula "~ x + y" names the two variables. Only they count: the rows where one of them is missing are dropped.
"~ x + y" (exactly two variables, no response).
The data frame: an object of columns (null or NaN for a missing value).
Optionaloptions: CorTestOptions
See CorTestOptions.
Test for correlation between paired samples. Equivalent to R's
cor.test().Supports Pearson's product-moment correlation (t test, with a Fisher-z confidence interval), Kendall's tau and Spearman's rho (exact or approximate p-values, chosen by the same rules as R). Pairs containing
NaNare dropped; Pearson needs at least 3 pairs and the others at least 2. If the correlation is undefined (constant data) the statistic, p-value and estimate areNaN. Correlations are computed in double-double arithmetic, so results can differ from R's when r is very close to ±1, where R's own value is less accurate.As R,
warningshas "the standard deviation is zero" where x or y is constant (the correlation isNaN), and "cannot compute exact p-value with ties" (R 4.6's text) where Kendall's or Spearman's exact p-value is asked for or the default but there are ties (the approximation is used), and "NaNs produced" where Spearman's t approximation has 2 pairs (0 degrees of freedom: the p-value isNaN).