pearson

 The pearson operator performs the Pearson correlation coefficient. Available only in the Enterprise Edition.

Synopsis

pearson(array1,array2[, use_flag]);

Library

The pearson operator resides in the Linear Algebra library. Run the following query to load this library:

AFL% load_library('linear_algebra'); 

Summary

Pearson's correlation coefficient between two variables is the covariance of the two variables divided by the product of their standard deviations:

The use flag lets you specify the behavior of pearson in case of null or missing values in the input arrays. Note that the use_flag has only one valid value: pairwise.complete.obs. With that value, pearson() computes the correlation between each pair of variables using all complete pairs of observations on those variables.

Examples

Using the Pearson Operator

To demonstrate the pearson operator, do the following:

  1. Create an array by entering:

    AFL% store(build(<val:double DEFAULT null>[row=0:3; col=0:3],
    '[
              [100,99,98,97]
              [(),95,94,93]
              [92,91,112,189]
              [188,13,186,185]
    ]',true),A_pearson1); 


    The output is:

    {row,col} val
    {0,0} 100
    {0,1} 99
    {0,2} 98
    {0,3} 97
    {1,1} 95
    {1,2} 94
    {1,3} 93
    {2,0} 92
    {2,1} 91
    {2,2} 112
    {2,3} 189
    {3,0} 188
    {3,1} 13
    {3,2} 186
    {3,3} 185 
  2. Enter:

    AFL% store(build(<val:double DEFAULT null>[row=0:3; col=0:3],
    '[
                        [120,130,97,103]
                        [213,95,94,()]
                        [92,(),112,189]
                        [188,17,186,179]
    ]',true),A_pearson2); 


    The output is:

    {row,col} val
    {0,0} 120
    {0,1} 130
    {0,2} 97
    {0,3} 103
    {1,0} 213
    {1,1} 95
    {1,2} 94
    {2,0} 92
    {2,2} 112
    {2,3} 189
    {3,0} 188
    {3,1} 17
    {3,2} 186
    {3,3} 179  
  3. Enter:

    AFL% pearson(A_pearson1, A_pearson2); 


    The output is:

    {col1,col2} pearson
    {0,0} null
    {0,1} null
    {0,2} null
    {0,3} null
    {1,0} -0.391486
    {1,1} null
    {1,2} -0.991412
    {1,3} null
    {2,0} 0.268118
    {2,1} null
    {2,2} 0.999943
    {2,3} null
    {3,0} -0.31154
    {3,1} null
    {3,2} 0.693349
    {3,3} null 
  4. Remove the arrays:

    AFL% remove(A_pearson1); remove(A_pearson2);