kendall
The kendall operator performs the Kendall tau (Ï„) metric, or Kendall rank correlation coefficient. Available only in the Enterprise Edition.
Synopsis
kendall(array1,array2)
Library
The kendall operator resides in the Linear Algebra library. Run the following query to load this library:
AFL% load_library('linear_algebra');
Summary
The Kendall rank correlation coefficient measures the tendency of two variables to move in the same or opposite directions. For two datasets A and B, two observations (A i , B i ) and (A j , B j ) are concordant if A j −A i and B j −B i are the same sign. The observations are discordant if A j −A i and B j −B i are opposite signs.
The Kendall tau metric is calculated from the number of concordant and discordant pairs in a sample as follows:
where C is the number of concordant pairs in A and B; D is the number of discordant pairs in A and B; and n is the sample size.
The Kendall operator requires that dimension lengths be exact multiples of the corresponding dimension chunk size.
Example
Using the Operator
To demonstrate kendall operator, do the following:
Create an array by entering:
AFL% store(build(<val:int64>[row=0:3:0:4; col=0:4:0:5], '[ [2,9,8,9,6] [8,8,6,3,8] [5,7,1,8,4] [8,4,4,9,1] ]',true),A_kendall1);
The output is:{row,col} val {0,0} 2 {0,1} 9 {0,2} 8 {0,3} 9 {0,4} 6 {1,0} 8 {1,1} 8 {1,2} 6 {1,3} 3 {1,4} 8 {2,0} 5 {2,1} 7 {2,2} 1 {2,3} 8 {2,4} 4 {3,0} 8 {3,1} 4 {3,2} 4 {3,3} 9 {3,4} 1Â
Enter:
AFL% store( redimension( apply( apply(A_kendall1, new_row, 3-row), new_col, 4-col ), <val:int64 DEFAULT null>[new_row=0:3:0:4; new_col=0:4:0:5] ), A_kendall2 );Â
The output is:{new_row,new_col} val {0,0} 1 {0,1} 9 {0,2} 4 {0,3} 4 {0,4} 8 {1,0} 4 {1,1} 8 {1,2} 1 {1,3} 7 {1,4} 5 {2,0} 8 {2,1} 3 {2,2} 6 {2,3} 8 {2,4} 8 {3,0} 6 {3,1} 9 {3,2} 8 {3,3} 9 {3,4} 2Â
Enter:
AFL% kendall( project(apply(A_kendall1, val_double, double(val)), val_double), project(apply(A_kendall2, val_double, double(val)), val_double));Â
The output is:{col,new_col} kendall {0,0} 0.182574 {0,1} 0 {0,2} 0.182574 {0,3} 0.547723 {0,4} -0.8 {1,0} -0.666667 {1,1} 0.182574 {1,2} -0.666667 {1,3} -1 {1,4} 0.547723 {2,0} -1 {2,1} 0.547723 {2,2} -0.333333 {2,3} -0.666667 {2,4} 0.182574 {3,0} -0.182574 {3,1} 0.6 {3,2} 0.547723 {3,3} 0.182574 {3,4} 0 {4,0} -0.333333 {4,1} -0.182574 {4,2} -1 {4,3} -0.666667 {4,4} 0.182574Â
Â
Remove the arrays by entering:
AFL% remove(A_kendall1);Â remove(A_kendall2);