Skip to content

Modern Math Correlation

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Math Library › Math Library › Correlation

Correlation

Returns the Pearson correlation of two arrays, from -1 to 1.

Syntax

Correlation( byref x as Array( of T ), byref y as Array( of T ) ) as float64

Notes

  • Unit-free, which is what makes it comparable between data sets where Covariance is not.
  • 1 is a perfect straight line rising, -1 a perfect line falling, 0 no LINEAR relationship at all.
  • Zero does not mean independent: a perfect parabola correlates at 0.
  • The arrays must be the same length.

Examples

#import "std/numeric"
#import "std/containers"
using numeric
using containers

dim as Array( of float64 ) x = { 1.0, 2.0, 3.0, 4.0, 5.0 }
dim as Array( of float64 ) y = { 2.0, 4.0, 6.0, 8.0, 10.0 }

print Correlation( x, y )               '' 0.9999999999999998 --
                             '' a perfect line, to within one rounding

dim as Array( of float64 ) down = { 10.0, 8.0, 6.0, 4.0, 2.0 }
print Correlation( x, down )            '' -0.9999999999999998

Library: Math Library
Category: Math Library
Documented under: Members

Clone this wiki locally