Method and source check
Last checked:
Automated source and implementation review, including worked examples and documented numerical limits. This review does not provide professional advice or specialist approval.
Method
Validate equal-length finite paired lists with at least two points. Compute sample covariance using n−1. Compute Pearson correlation from normalized centered observations, an equivalent ratio that preserves tiny varying data. Correlation is undefined for an actually constant list; nonfinite derived results are rejected.
sample covariance = Σ(xᵢ−x̄)(yᵢ−ȳ)/(n−1)
r = covariance/(sâ‚“sáµ§), when sâ‚“sáµ§>0
Variables and units
- xáµ¢,yáµ¢
- paired observations
- x̄,ȳ
- sample means
- sâ‚“,sáµ§
- sample standard deviations
- n
- number of pairs
Worked example
For X=1,2,3 and Y=2,4,6, sample covariance is 2 and Pearson r is 1.
Limitations
Covariance, defined correlation, and sample means are displayed to four decimals. Math.round retains the existing half-tie convention; if scaling for four-place rounding would overflow, the finite representable value is retained. Locale formatting is applied after numerical calculation.
- Association does not establish causation.
- Pearson r captures linear association and is undefined if either variable has zero variance.
- Derived values outside the supported finite numerical range are rejected with a localized input-field error.
- When X is constant, covariance is 0 but Pearson r is undefined, not zero.
- At least two equal-length paired lists are required.
- X=1e-200,2e-200,3e-200 and Y=2e-200,4e-200,6e-200 have r=1; covariance displays 0 after four-place rounding.
- Paired lists −1e200,1e200 are rejected because covariance is outside the supported finite range.
- X=1000000000000000,1000000000000001,1000000000000002 and Y=1,2,3 retain sample covariance 1 and Pearson r=1 after centering before scaling.