public class TMtxPCA : 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 Dew.Stats.TMtxPCA.PCAMode property define whether PCA will use correlation or covariance matrix to calculate PCA.
- Define the actual Dew.Stats.TMtxPCA.Data (by changing Data matrix values).
- Call the Dew.Stats.TMtxPCA.Recalc method to calculate PCA results.
Results:
- Dew.Stats.TMtxPCA.EigValues - Data eigenvalues
- Dew.Stats.TMtxPCA.PC - Data eigenvectors
- Dew.Stats.TMtxPCA.TotalVarPct - the percentage of the total variation in the variables (columns)
- Dew.Stats.TMtxPCA.ZScores - Z-Scores (eigenvectors in PC space).
Examples
csharp
using Dew.Stats;
using Dew.Stats.Units;
using Dew.Math;
namespace Dew.Examples
{
private void Example(StatTools.TMtxPCA MtxPCA1)
{
// ...
MtxPCA1.Data.SetIt(4,3,false,new double[]
{1,2,3,
5,7,9,
1,11,13,
3,7,4});
MtxPCA1.PCAMode = TPCAMode.PCARawData; // using data matrix to evaluate PCA
MtxPCA1.Recalc(); // force recalculation
// ...
}
}
Properties
| Name | Type | Description |
|---|---|---|
| AutoUpdate | Boolean | If true then changing any of the TMtxPCA properties will trigger the Dew.Stats.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. |