You are here: Symbol Reference > Statistics Namespace > Functions > Statistics.PCA Function
Stats Master VCL
ContentsIndex
PreviousUpNext
Statistics.PCA Function

Performs a principal component analysis (PCA).

Pascal
procedure PCA(const CovMat: TMtx; const PC: TMtx; const EigenVec: TVec; const VarPct: TVec = nil); overload;

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.

Uses MtxExpr, Statistics;
procedure Example;
var Data, PC: Matrix;
  Variances, ZS: Vector;
begin
  Data.SetIt(2,4,false,[1,3,5,2,
                        2,5,7,9]);

  Covariance(data,covMat,false);
  PCA(covMat,PC,ZS,Variances); //requires cov matrix

   //      Z = [29 ,  0, 0 ,0 ]
  //variance = [100,  0, 0 ,0 ]

end;
#include "MtxExpr.hpp"
#include "Statistics.hpp"
void __fastcall Example()
{
  sMatrix data, PC, covMat;
  sVector Z,variances;

  data.SetIt(2,4,false,OPENARRAY(double,(1,3,5,2,
                                          2,5,7,9)));

  Covariance(data,covMat,false);
  PCA(covMat,PC,Z,variances); //requires cov matrix

       //      Z = [29 ,  0, 0 ,0 ]
      //variance = [100,  0, 0 ,0 ]
}
Examples on GitHub
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!