type TMtxPCA = class(TMtxComponent);
Performs Principle Component Analysis (PCA).
Principal Components Analysis - PCA - is a data analysis tool that is usually used to reduce the dimensionality (number of variables) of a large number of interrelated variables, while retaining as much of the information (variation) as possible. PCA calculates an uncorrelated set of variables (factors or PCs). These factors are ordered so that the first few retain most of the variation present in all of the original variables.
The PCA procedure is reduced to an eigenvalue-eigenvector problem. PCA routines perform a PCA on either a correlation or a covariance matrix. Data matrix can be either "raw" data or pre-calculated correlation/covariance matrix.
How to use TMtxPCA component?
- Drop a TMtxPCA component on the form.
- By setting the TMtxPCA.PCAMode property define whether PCA will use correlation or covariance matrix to calculate PCA.
- Define the actual TMtxPCA.Data (by changing Data matrix values).
- Call the TMtxPCA.Recalc method to calculate PCA results.
Results:
- TMtxPCA.EigValues - Data eigenvalues
- TMtxPCA.PC - Data eigenvectors
- TMtxPCA.TotalVarPct - the percentage of the total variation in the variables (columns)
- TMtxPCA.ZScores - Z-Scores (eigenvectors in PC space).
Examples
delphi
Uses StatTools, MtxVec, Statistics;
procedure Example(MtxPCA1: TMtxPCA);
begin
// ...
MtxPCA1.Data.SetIt(4,3,false,[1,2,3,
5,7,9,
1,11,13,
3,7,4]);
MtxPCA1.PCAMode := PCARawData; // using data matrix to evaluate PCA
MtxPCA1.Recalc; // force recalculation
// ...
end;
Properties
| Name | Type | Description |
|---|---|---|
| AutoUpdate | Boolean | If true then changing any of the TMtxPCA properties will trigger the TMtxPCA.Recalc method. |
| BlockAssign | Boolean | Block streaming of specific properties when storing only a "template". |
| Data | TMtx | Defines the data to be analyzed by PCA. |
| Dirty | Boolean | When any of the TMtxPCA properties changes, this property is automatically set to true. |
| EditorActive | Boolean | Returns True, if the component editor is displayed. |
| EigValues | TVec | Returns the eigenvalues. |
| PC | TMtx | Returns the principal components (PC). |
| PCAMode | TPCAMode | PCA type. |
| Reference | TReferenceList | Stores a list of components that have to be notified, when this component is destroyed. |
| TotalVarPct | TVec | Returns the percentage of the total variation in the variables. |
| ZScores | TMtx | Returns the Z-Scores. |
Methods
| Name | Description |
|---|---|
| AllowStreaming | Returns the negatated value of BlockAssign. |
| Assign | Assign values of all published properties from Source. |
| AssignTemplate | Assign values of "template-like" published properties from Source. |
| EditorClass | To be overriden in descendanr classses. |
| LoadFromStream | Load the component from Src stream. |
| LoadTemplateFromFile | Load a template from file. |
| LoadTemplateFromStream | Load a template from stream. |
| Recalc | Triggers PCA recalculation. |
| Reset | Reset is called after loading the data from stream or file. |
| SaveTemplateToFile | Save template to file. |
| SaveTemplateToStream | Save template to stream. |
| SaveToStream | Save the component to Dst stream. |