Covariance matrix.
Calculate the variance-covariance matrix (Result), assuming matrices X and Y are two variables and all X and Y matrix elements are the observables.
Calculate the variance (Result) of all X vector elements. If NormN boolean parameter is true (default value), the result will be normalized with number of observations (N), otherwise it will be normalized with N-1.
Calculate the variance-covariance matrix (Result), assuming vectors X and Y are two variable and their elements are the observations. An exception is raised if X and Y vector Length or Complex property does not match. If NormN boolean parameter is true (default value), the result will be normalized with number of observations (N), otherwise it will be normalized with N-1.
Example 1
Calculate the covariance matrix from two vectors representing two variables. var Data1, Data2: Vector;
CovMtx : Matrix;
begin
Data1.SetIt(false,[1,2,3]);
Data2.SetIt(false,[5,5.5]);
Covariance(Data1,Data2,CovMtx,False);
// CovMtx = [1.00000000, -2.00000000,
// -2.00000000, 6.083333334]
end;
#include "MtxVecCpp.h"
#include "Statistics.hpp"
void __fastcall Example()
{
Vector data1,data2;
Matrix cov;
data1->SetIt(false,OPENARRAY(double,(1,2,3)));
data2->SetIt(false,OPENARRAY(double,(5,5.5)));
Covariance(data1,data2,cov,false);
// cov = [1.00000000, -2.00000000,
// -2.00000000, 6.083333334]
}
using Dew.Math;
using Dew.Stats.Units;
namespace Dew.Examples
{
private void Example()
{
Vector data1 = new Vector(0);
Vector data2 = new Vector(0);
Matrix cov = new Matrix(0,0);
data1.SetIt(false,new double[] {1,2,3});
data2.SetIt(false,new double[] {5,5.5});
Statistics.Covariance(data1,data2,cov,false);
// cov = [1.00000000, -2.00000000,
// -2.00000000, 6.083333334]
}
}
Declaration
Procedure Covariance(X: TMtx; Result: TMtx; NormN: boolean = true);
Description
Calculate the variance-covariance matrix (Result), assuming matrix X columns are variables and its rows are observations.