public static DoubleMatrix Covariance(
	ReadOnlyDoubleMatrix data,
	bool adjustForBias,
	DataOperation dataOperation
)Public Shared Function Covariance ( 
	data As ReadOnlyDoubleMatrix,
	adjustForBias As Boolean,
	dataOperation As DataOperation
) As DoubleMatrixpublic:
static DoubleMatrix^ Covariance(
	ReadOnlyDoubleMatrix^ data, 
	bool adjustForBias, 
	DataOperation dataOperation
)static member Covariance : 
        data : ReadOnlyDoubleMatrix * 
        adjustForBias : bool * 
        dataOperation : DataOperation -> DoubleMatrix 
            Given a sequence of  random 
            variables 
,
            their covariance matrix can be defined as that having generic entry:
            
            By interpreting the rows or the columns 
            of data as samples drawn from
            random variables, this method returns estimates of the 
            covariance matrix of such variables.
            Let  and  
            
 be the data
            number of rows and columns, respectively, and define
            
Operating on rows
            If dataOperation is OnRows,
            then the method returns the estimated covariance matrix 
            among the  rows
            of data.
            
            If adjustForBias is set to false, then 
             is estimated through 
            the coefficient
            
            where
            
            is the sample mean of the 
            i-th row.
            
            Such estimator is biased. If adjustForBias is set 
            to true, then 
            the estimator is corrected for bias
            and  is evaluated through 
            the coefficient
            
            provided that  is greater than 1;
            otherwise, an exception is thrown.
            
Operating on columns
            If dataOperation is OnColumns,
            then the method returns the estimated covariance matrix among the  columns
            of data.
            
            If adjustForBias is set to false, then 
             is estimated through the coefficient
            
            where
            
            is the sample mean of the 
            j-th column.
            
            Such estimator is biased. If adjustForBias is set to true, then 
            the estimator is corrected for bias
            and  is evaluated through the coefficient
            
            provided that  is greater than 1;
            otherwise, an exception is thrown.
            
In the following example, the covariances among the rows and those among the columns of a data matrix are computed.
using System;
namespace Novacta.Analytics.CodeExamples
{
    public class CovarianceExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[20] {
                1, 2, -3,  6, -2,
                2, 2,  2,  0,  7,
               -3, 2,  3,  2,  9,
                5, 2,  7, -1, -4
            };
            var matrix = DoubleMatrix.Dense(4, 5, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);
            // Covariance can be adjusted for bias.
            bool adjustForBias = true; 
            // Compute the covariances among columns.
            var covarianceOnColumns = Stat.Covariance(matrix, adjustForBias, DataOperation.OnColumns);
            Console.WriteLine();
            Console.WriteLine("Covariances among columns:");
            Console.WriteLine(covarianceOnColumns);
            // Covariance is overloaded to accept data as a read-only matrix:
            // compute the covariances among rows using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var covarianceOnRows = Stat.Covariance(readOnlyMatrix, adjustForBias, DataOperation.OnRows);
            Console.WriteLine();
            Console.WriteLine("Covariances among rows:");
            Console.WriteLine(covarianceOnRows);
        }
    }
}
// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                -3               6                -2               
// 2                2                2                0                7                
// -3               2                3                2                9                
// 5                2                7                -1               -4               
// 
// 
// 
// Covariances among columns:
// 10.9166667       0                5.25             -4.58333333      -15.8333333      
// 0                0                0                0                0                
// 5.25             0                16.9166667       -11.5833333      -1.16666667      
// -4.58333333      0                -11.5833333      9.58333333       -2.5             
// -15.8333333      0                -1.16666667      -2.5             41.6666667       
// 
// 
// 
// Covariances among rows:
// 12.7             -6.1             -6.1             -4.3             
// -6.1             6.8              8.3              -5.85            
// -6.1             8.3              18.3             -12.85           
// -4.3             -5.85            -12.85           19.7             
// 
//| ArgumentNullException | data is null. | 
| ArgumentException | dataOperation is not a field of 
            DataOperation. -or- adjustForBias is true, dataOperation is OnRows and the data number of columns is less than 2. -or- adjustForBias is true, dataOperation is OnColumns and the data number of rows is less than 2.  |