CoefficientRArray (Function)
The CoefficientRArray function calculates the Pearson product moment correlation coefficient, R for two named arrays.
Syntax
CoefficientRArray(IndDepArray,DepArray,Size)
Returns (Double)
A numeric value between 1 and –1, for two named arrays, for the current bar. If no value is calculated for CoefficientRArray the function returns -2.
Parameters
|
Name |
Type |
Description |
|
IndDepArray |
Numeric Array |
Specifies the name of a numeric array of the independent values. |
|
DepArray |
Numeric Array |
Specifies the name of a numeric array of the dependent values. |
|
Size |
Numeric |
Sets the number of data elements (size) in the arrays to be evaluated. |
Remarks
The Pearson product coefficient, R, is a dimensionless index that ranges from -1.0 to 1.0 inclusive and reflects the extent of a linear relationship between Price and a dependent value for some number of values.
Pearson's product moment correlation coefficient, usually denoted by R, is one example of a correlation coefficient. It is a measure of the linear association between two variables that have been measured on interval or ratio scales.
A correlation coefficient is a number between -1 and 1, which measures the degree to which two variables are linearly related. If there is a perfect linear relationship with positive slope between the two variables, we have a correlation coefficient of 1; if there is a positive correlation, whenever one variable has a high (low) value, the other does also. If there is a perfect linear relationship with negative slope between the two variables, we have a correlation coefficient of -1; if there is a negative correlation, whenever one variable has a high (low) value, the other has a low (high) value. A correlation coefficient of 0 means that there is no linear relationship between the variables.
Under certain circumstances the function may not calculate a value for CoefficientRArray for the current bar. When this happens the function returns –2. You may want to check for this value and not plot for the current bar. Also, if you are looking for negative correlation you may want to add range checking. For example if R < -.75 AND R > -1.01 then …
The value for the Size input parameter should be a whole number greater than 0. Also, Size cannot be larger than the number of elements in the smallest array.
All array-based function calculations begin with array element 1.
Example
Assigns to Value1 the CoefficientRArray of one 10 element array to another 10 element array, then plots a ShowMe on the High when Value1 is greater than .75:
Array: myIndDepArray [10](0), myDepArray[10](0);
{… (assign values to both arrays) }
Value1 = CoefficientRArray (myIndDepArray, myDepArray, 10);
if Value1 > .75 then
Plot1(High, "CoefAR");