TMtxPCA Class

Source: StatTools.cs · Assembly: Dew.Stats
ComponentTMtxComponentTMtxPCA

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

NameTypeDescription
AutoUpdateBooleanIf true then changing any of the TMtxPCA properties will trigger the Dew.Stats.TMtxPCA.Recalc method.
BlockAssignBooleanBlock streaming of specific properties when storing only a "template".
DataTMtxDefines the data to be analyzed by PCA.
DirtyBooleanWhen any of the TMtxPCA properties changes, this property is automatically set to true.
EditorActiveBooleanReturns True, if the component editor is displayed.
EigValuesTVecReturns the eigenvalues.
PCTMtxReturns the principal components (PC).
PCAModeTPCAModePCA type.
ReferenceTReferenceListStores a list of components that have to be notified, when this component is destroyed.
TotalVarPctTVecReturns the percentage of the total variation in the variables.
ZScoresTMtxReturns the Z-Scores.

Methods

NameDescription
AllowStreamingReturns the negatated value of BlockAssign.
AssignAssign values of all published properties from Source.
AssignTemplateAssign values of "template-like" published properties from Source.
EditorClassTo be overriden in descendanr classses.
LoadFromStreamLoad the component from Src stream.
LoadTemplateFromFileLoad a template from file.
LoadTemplateFromStreamLoad a template from stream.
RecalcTriggers PCA recalculation.
ResetReset is called after loading the data from stream or file.
SaveTemplateToFileSave template to file.
SaveTemplateToStreamSave template to stream.
SaveToStreamSave the component to Dst stream.