Correlation of two arrays in C#

前端 未结 6 979
挽巷
挽巷 2020-11-29 05:09

Having two arrays of double values, I want to compute correlation coefficient (single double value, just like the CORREL function in MS Excel). Is there some simple one-line

6条回答
  •  广开言路
    2020-11-29 05:51

    Math.NET Numerics is a well-documented math library that contains a Correlation class. It calculates Pearson and Spearman ranked correlations: http://numerics.mathdotnet.com/api/MathNet.Numerics.Statistics/Correlation.htm

    The library is available under the very liberal MIT/X11 license. Using it to calculate a correlation coefficient is as easy as follows:

    using MathNet.Numerics.Statistics;
    
    ...
    
    correlation = Correlation.Pearson(arrayOfValues1, arrayOfValues2);
    

    Good luck!

提交回复
热议问题