CORRELATE function computes the linear
correlation coefficient of two vectors or the
correlation matrix of an
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
array is specified, the result will be an
array of linear Pearson correlation coefficients, with the element
corresponding to correlation of the
th columns of the input array.
Alternatively, this function computes the covariance of two vectors or the covariance matrix of an
This routine is written in the IDL language. Its source code can be found in the file
subdirectory of the IDL distribution.
Result = CORRELATE(
A vector or an
can be integer, single-, or double-precision floating-point.
An integer, single-, or double-precision floating-point vector. If
should not be supplied.
Set this keyword to compute the sample covariance rather than the correlation coefficient.
Set this keyword to force the computation to be done in double-precision arithmetic.
Define the data vectors.
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:
PRINT, CORRELATE(X, Y)
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 = TRANSPOSE([[X],[Y]])
Compute the correlation matrix.