cancel
Showing results for 
Search instead for 
Did you mean: 

weighted correlation in Q?

Matt_Fang
New Contributor
I know there is a correlation function in Q.  https://code.kx.com/q/ref/cor/
Is there a "weighted correlation"? 
1 REPLY 1

ajay
New Contributor II
There is no inbuilt weighted correlation, but you can easily implement Pearson Weighted Correlation as follows

wcov: {[x;y;w] w wavg (x-w wavg x)*y-w wavg y}    // weighted covariance

wcor: {[x;y;w] wcov[x;y;w]%sqrt wcov[x;x;w]*wcov[y;y;w]}   // weighted correlation


-Ajay