Dew Stats Master .NET
PCA Routines
Summary
Performs a principal component analysis (PCA).

Unit
Statistics

Declaration
Procedure PCA(Data: TMtx; PC, ZScores: TMtx; EigenVec: TVec; VarPct: TVec = nil; PCAMode: TPCAMode = PCACorrMat);

Description
Perform a PCA on Data matrix, where Data columns are variables and rows are the observables.The (optional) PCAMode parameter defines whether the analysis should be run on correlation or covariance matrix. PCA procedure returns the principal components in matrix PC, the Z-scores (data, transformed in the PC space) in ZScores, the eigenvalues of the covariance matrix (variances) in the EigenVec vector and (optional) the percentage of total variance in VarPct vector. The PC, ZScores, EigenVec and VarPct dimensions are adjusted automatically.
Categories
Multivariate analysis routines
 See Also 
PCAResiduals 
BarlettTest 

Example 1

In this example we derive the covariance matrix from original Data and get the same results as in first example.

Uses Statistics, MtxExpr; procecure Example; var Data,CovMat, PC: Matrix; Variances,VarPercent : Vector; begin Data.SetIt(2,4,false,[1,3,5,2 2,5,7,9]); Covariance(Data,CovMat,false); PCA(CovMat,PC,Variances,VarPercent); // ... Variances = [29,0,0,0] // VarPercent = [100,0,0,0] end;
#include "Statistics.hpp" #include "MtxVecCpp.h" void __fastcall Example() { Matrix data, cov, PC; Vector variances, varPercent; data->SetIt(2,4,false,OPENARRAY(double, (1,3,5,2 2,5,7,9))); Covariance(data,cov,false); PCA(cov,PC,variances,varPercent,PCACorrMat); // ... variances = [29,0,0,0] // varPercent = [100,0,0,0] }
using Dew.Math; using Dew.Stat.Units; namespace Dew.Examples { private void Example() { Matrix data = new Matrix(0,0); Matrix cov = new Matrix(0,0); Matrix PC = new Matrix(0,0); Vector variances = new Vector(0); Vector varPercent = new Vector(0); data->SetIt(2,4,false,new double[] {1,3,5,2 2,5,7,9}); Statistics.Covariance(data,cov,false); Statistics.PCA(cov,PC,variances,varPercent,TPCAMode.PCACorrMat); // ... variances = [29,0,0,0] // varPercent = [100,0,0,0] } }



Declaration
Procedure PCA(CovMat: TMtx; PC: TMtx; EigenVec: TVec; VarPct: TVec = nil);

Description
Perform a PCA by using the original data covariance matrix CovMat. Return the principal components in PC matrix, eigenvalues of the covariance matrix (variances) in vector EigenVec and (optional) the percentage of total variance in vector VarPct. The PC, EigenVec and VarPct dimensions are adjusted automatically.

Example 1

Uses MtxExpr, Statistics; procedure Example; var Data, PC, ZS: Matrix; Variances : Vector; begin Data.SetIt(2,4,false,[1,3,5,2, 2,5,7,9]); PCA(Data,PC,ZS,Variances); // ... Variances = [29,0] end;
#include "MtxVecCpp.h" #include "Statistics.hpp" void __fastcall Example() { Matrix data, PC, Z; Vector variances; data->SetIt(2,4,false,OPENARRAY(double,(1,3,5,2, 2,5,7,9))); PCA(data,PC,Z,variances,NULL); // ... variances = [29,0] }
using Dew.Math; using Dew.Stats; using Dew.Stats.Units; namespace Dew.Examples { private void Example { Matrix data = new Matrix(0,0); Matrix PC = new Matrix(0,0); Matrix Z = new Matrix(0,0); Vector variances = new Vector(0); data.SetIt(false, new double[] { 1,3,5,2, 2,5,7,9}); Statistics.PCA(data,PC,Z,variances,null); // ... variances = [29,0] } }

Copyright 2008 Dew Research
http://www.dewresearch.com