
Hi there,
I am trying to calc covariance for 2 dataset but can't find it. while I can find correlation class. I am wondering why we don't have a covarance method? Any reason?
thanks
chenming


Coordinator
Apr 4, 2013 at 5:21 PM

No particular reason, it just has not been added yet. ( UserVoice)
Thanks,
Christoph



Thx Chris. As my team is using this lib, can we add such mathematical methods and check in? Do you have a list of methods you plan to add? I can help on this.


Coordinator
Apr 14, 2013 at 7:03 PM

Yes, we accept contributions, and a covariance implementation would certainly be welcome.
We use github to coordinate contributions, see also
http://numerics.mathdotnet.com/
Thanks,
Christoph



You can use the Pearsons correlation to compute the elements of a correlation matrix:
I am sure this is not the fastest method and ignores the fact that the matrix could be better implemented with a square symmetric matrix but show how to get started
public static Matrix<double> Correl(Matrix<double> x)
{
Matrix<double> correlM = new DenseMatrix(x.RowCount, x.RowCount);
//off diagonal elements
foreach (var rowx in x.RowEnumerator())
{
foreach (var rowy in x.RowEnumerator())
{
if (rowy.Item1 > rowx.Item1)
{
correlM[rowx.Item1, rowy.Item1] = MathNet.Numerics.Statistics.Correlation.Pearson(rowx.Item2, rowy.Item2);
}
if (rowy.Item1 < rowx.Item1)
{
correlM[rowx.Item1, rowy.Item1] = correlM[rowy.Item1, rowx.Item1];
}
}
}
//Diagonal elements
foreach (var rowx in x.RowEnumerator())
{
correlM[rowx.Item1, rowx.Item1] = MathNet.Numerics.Statistics.Correlation.Pearson(rowx.Item2, rowx.Item2);
}
return correlM;
}



thanks, my team has implemented this and will submit to the branch once we are a bit free.

