Function Math Statistics Class

Correlation

Returns the correlation coefficient of arrays vXValues and vYValues.

Signature (Visual Basic / VBA)

Public Function Correlation( _
      ByRef vXValues As Variant _
    , ByRef vYValues As Variant _
    ) As Variant

Code Example

    Correlation(Array(12, 34, 56), Array(23, 45, 67)) = 1
    Correlation(Array(12, 34, 56), Array(11, 22, 44)) = 0.981980506061966

Parameters

Parameter Description
vXValues First set of data. Numeric-type array or Variant array containing only numeric elements. This function is NOT affected by the current setting of the StatVarType Property. It assumes that vXValues is an array that contains only numeric elements.
vYValues Second set of data. Numeric-type array or Variant array containing only numeric elements. This function assumes that vYValues is an array that contains only numeric elements.

Return Value

Function returns the correlation coefficient for the arrays vXValues and vYValues. Function returns Null if the arrays vXValues and vYValues contain a different number of elements, if both arrays are empty, or if there is some type of error, such as if the argument is a Variant array which contains an Object reference or String.

Notes & Version History

v1.5 Note This function replaces the CorrelationVariantVector function, which has been removed from ArrayArithmetic Class. This function is slightly different in that it examines all of the elements in the array from its lower bound through its upper bound.