The
CORRELATE function computes the linear
Pearson
correlation coefficient of two vectors or the
correlation matrix of an *
m*
x *
n*
array. If vectors of unequal lengths are specified, the longer vector is truncated to the length of the shorter vector and a single correlation coefficient is returned. If an *
m*
x *
n*
array is specified, the result will be an *
m*
x *
m*
array of linear Pearson correlation coefficients, with the element *
i*
,*
j*
corresponding to correlation of the *
i*
th and *
j*
th columns of the input array.

Alternatively, this function computes the covariance of two vectors or the covariance matrix of an *
m*
x *
n*
array.

This routine is written in the IDL language. Its source code can be found in the file ```
correlate.pro
```

in the ```
lib
```

subdirectory of the IDL distribution.

X = [65, 63, 67, 64, 68, 62, 70, 66, 68, 67, 69, 71]

Y = [68, 66, 68, 65, 69, 66, 68, 65, 71, 67, 68, 70]

Compute the linear Pearson correlation coefficient of x and y. The result should be 0.702652:

Compute the covariance of x and y. The result should be 3.66667.

PRINT, CORRELATE(X, Y, /COVARIANCE)

Define an array with x and y as its columns.

A_CORRELATE , C_CORRELATE , M_CORRELATE , P_CORRELATE , R_CORRELATE