This example illustrates the use of the FactorAnalysis class. The following data were originally analyzed by Emmett(1949). There are 211 observations on 9 variables. Following Lawley and Maxwell (1971), three factors will be obtained by the method of maximum likelihood.
using System;
using Imsl.Stat;
using PrintMatrix = Imsl.Math.PrintMatrix;
using PrintMatrixFormat = Imsl.Math.PrintMatrixFormat;
public class FactorAnalysisEx2
{
public static void Main(String[] args)
{
double[,] cov = {
{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 fl = new FactorAnalysis(cov,
FactorAnalysis.MatrixType.VarianceCovariance, 3);
fl.ConvergenceCriterion1 = .000001;
fl.ConvergenceCriterion2 = .01;
fl.FactorLoadingEstimationMethod =
FactorAnalysis.Model.MaximumLikelihood;
fl.VarianceEstimationMethod = 0;
fl.MaxStep = 10;
fl.DegreesOfFreedom = 210;
PrintMatrixFormat pmf = new PrintMatrixFormat();
pmf.NumberFormat = "0.0000";
new PrintMatrix
("Unique Error Variances").Print(pmf, fl.GetVariances());
new PrintMatrix
("Unrotated Factor Loadings").Print(pmf, fl.GetFactorLoadings());
new PrintMatrix("Eigenvalues").Print(pmf, fl.GetValues());
new PrintMatrix("Statistics").Print(pmf, fl.GetStatistics());
}
}
Unique Error Variances
0
0 0.4505
1 0.4271
2 0.6166
3 0.2123
4 0.3805
5 0.1769
6 0.3995
7 0.4615
8 0.2309
Unrotated Factor Loadings
0 1 2
0 0.6642 -0.3209 0.0735
1 0.6888 -0.2471 -0.1933
2 0.4926 -0.3022 -0.2224
3 0.8372 0.2924 -0.0354
4 0.7050 0.3148 -0.1528
5 0.8187 0.3767 0.1045
6 0.6615 -0.3960 -0.0777
7 0.4579 -0.2955 0.4913
8 0.7657 -0.4274 -0.0117
Eigenvalues
0
0 0.0626
1 0.2295
2 0.5413
3 0.8650
4 0.8937
5 0.9736
6 1.0802
7 1.1172
8 1.1401
Statistics
0
0 0.0350
1 1.0000
2 7.1494
3 12.0000
4 0.8476
5 5.0000
Link to C# source.