Example: Principal Components

This example illustrates the use of the FactorAnalysis class for a nine-variable matrix. FactorAnalysis.Model.PrincipalComponent and input matrix type FactorAnalysis.MatrixType.Correlation are selected.

using System;
using Imsl.Stat;
using PrintMatrix = Imsl.Math.PrintMatrix;
using PrintMatrixFormat = Imsl.Math.PrintMatrixFormat;

public class FactorAnalysisEx1
{
    public static void  Main(String[] args)
    {
        double[,] corr = {   {1.0, 0.523, 0.395, 0.471,
                                0.346, 0.426, 0.576, 0.434, 0.639},
                              {0.523, 1.0, 0.479, 0.506, 
                                0.418, 0.462, 0.547, 0.283, 0.645},
                              {0.395, 0.479, 1.0, 0.355,
                                0.27, 0.254, 0.452, 0.219, 0.504}, 
                              {0.471, 0.506, 0.355, 1.0, 
                                0.691, 0.791, 0.443, 0.285, 0.505},
                              {0.346, 0.418, 0.27, 0.691,
                                1.0, 0.679, 0.383, 0.149, 0.409},
                              {0.426, 0.462, 0.254, 0.791,
                                0.679, 1.0, 0.372, 0.314, 0.472},
                              {0.576, 0.547, 0.452, 0.443, 
                                0.383, 0.372, 1.0, 0.385, 0.68}, 
                              {0.434, 0.283, 0.219, 0.285, 
                                0.149, 0.314, 0.385, 1.0, 0.47},
                              {0.639, 0.645, 0.504, 0.505, 
                                0.409, 0.472, 0.68, 0.47, 1.0}};

        FactorAnalysis pc = new FactorAnalysis(corr, 
            FactorAnalysis.MatrixType.Correlation, 9);
        pc.FactorLoadingEstimationMethod = 
            FactorAnalysis.Model.PrincipalComponent;
        pc.DegreesOfFreedom = 100;

        PrintMatrixFormat pmf = new PrintMatrixFormat();
        pmf.NumberFormat = "0.0000";
        new PrintMatrix("Eigenvalues").Print(pmf, pc.GetValues());
        new PrintMatrix("Percents").Print(pmf, pc.GetPercents());
        new PrintMatrix
            ("Standard Errors").Print(pmf, pc.GetStandardErrors());
        new PrintMatrix("Eigenvectors").Print(pmf, pc.GetVectors());
        new PrintMatrix
            ("Unrotated Factor Loadings").Print(pmf, pc.GetFactorLoadings());
    }
}

Output

Eigenvalues
     0     
0  4.6769  
1  1.2640  
2  0.8444  
3  0.5550  
4  0.4471  
5  0.4291  
6  0.3102  
7  0.2770  
8  0.1962  

 Percents
     0     
0  0.5197  
1  0.6601  
2  0.7539  
3  0.8156  
4  0.8653  
5  0.9130  
6  0.9474  
7  0.9782  
8  1.0000  

Standard Errors
     0     
0  0.6498  
1  0.1771  
2  0.0986  
3  0.0879  
4  0.0882  
5  0.0890  
6  0.0944  
7  0.0994  
8  0.1113  

                                   Eigenvectors
     0        1        2        3        4        5        6        7        8     
0  0.3462  -0.2354   0.1386  -0.3317  -0.1088   0.7974   0.1735  -0.1240  -0.0488  
1  0.3526  -0.1108  -0.2795  -0.2161   0.7664  -0.2002   0.1386  -0.3032  -0.0079  
2  0.2754  -0.2697  -0.5585   0.6939  -0.1531   0.1511   0.0099  -0.0406  -0.0997  
3  0.3664   0.4031   0.0406   0.1196   0.0017   0.1152  -0.4022  -0.1178   0.7060  
4  0.3144   0.5022  -0.0733  -0.0207  -0.2804  -0.1796   0.7295   0.0075   0.0046  
5  0.3455   0.4553   0.1825   0.1114   0.1202   0.0696  -0.3742   0.0925  -0.6780  
6  0.3487  -0.2714  -0.0725  -0.3545  -0.5242  -0.4355  -0.2854  -0.3408  -0.1089  
7  0.2407  -0.3159   0.7383   0.4329   0.0861  -0.1969   0.1862  -0.1623   0.0505  
8  0.3847  -0.2533  -0.0078  -0.1468   0.0459  -0.1498  -0.0251   0.8521   0.1225  

                             Unrotated Factor Loadings
     0        1        2        3        4        5        6        7        8     
0  0.7487  -0.2646   0.1274  -0.2471  -0.0728   0.5224   0.0966  -0.0652  -0.0216  
1  0.7625  -0.1245  -0.2568  -0.1610   0.5124  -0.1312   0.0772  -0.1596  -0.0035  
2  0.5956  -0.3032  -0.5133   0.5170  -0.1024   0.0990   0.0055  -0.0214  -0.0442  
3  0.7923   0.4532   0.0373   0.0891   0.0012   0.0755  -0.2240  -0.0620   0.3127  
4  0.6799   0.5646  -0.0674  -0.0154  -0.1875  -0.1177   0.4063   0.0039   0.0021  
5  0.7472   0.5119   0.1677   0.0830   0.0804   0.0456  -0.2084   0.0487  -0.3003  
6  0.7542  -0.3051  -0.0666  -0.2641  -0.3505  -0.2853  -0.1589  -0.1794  -0.0482  
7  0.5206  -0.3552   0.6784   0.3225   0.0576  -0.1290   0.1037  -0.0854   0.0224  
8  0.8319  -0.2848  -0.0071  -0.1094   0.0307  -0.0981  -0.0140   0.4485   0.0543  


Link to C# source.