Class FactorAnalysis
- All Implemented Interfaces:
Serializable,Cloneable
Class FactorAnalysis computes principal components or
initial factor loading estimates for a variance-covariance or correlation
matrix using exploratory factor analysis models.
Models available are the principal component model for factor analysis and the common factor model with additions to the common factor model in alpha factor analysis and image analysis. Methods of estimation include principal components, principal factor, image analysis, unweighted least squares, generalized least squares, and maximum likelihood.
For the principal component model there are methods to compute the characteristic roots, characteristic vectors, standard errors for the characteristic roots, and the correlations of the principal component scores with the original variables. Principal components obtained from correlation matrices are the same as principal components obtained from standardized (to unit variance) variables.
The principal component scores are the elements of the vector \(y = \Gamma^Tx\) where \(\Gamma\) is the matrix whose columns are the characteristic vectors (eigenvectors) of the sample covariance (or correlation) matrix and x is the vector of observed (or standardized) random variables. The variances of the principal component scores are the characteristic roots (eigenvalues) of the covariance (correlation) matrix.
Asymptotic variances for the characteristic roots were first obtained by Girshick (1939) and are given more recently by Kendall, Stuart, and Ord (1983, page 331). These variances are computed either for variance-covariance matrices or for correlation matrices.
The correlations of the principal components with the observed (or standardized) variables are the same as the unrotated factor loadings obtained for the principal components model for factor analysis when a correlation matrix is input.
In the factor analysis model used for factor extraction, the basic model is given as \(\Sigma = \Lambda\Lambda^T + \Psi\) where \(\Sigma\) is the \( p \times p\) population covariance matrix. \(\Lambda\) is the \( p \times k\) matrix of factor loadings relating the factors f to the observed variables x, and \(\Psi\) is the \( p \times p\) matrix of covariances of the unique errors e. Here, p represents the number of variables and k is the number of factors. The relationship between the factors, the unique errors, and the observed variables is given as \(x = \Lambda f + e\) where, in addition, it is assumed that the expected values of e, f, and x are zero. (The sample means can be subtracted from x if the expected value of x is not zero.) It is also assumed that each factor has unit variance, the factors are independent of each other, and that the factors and the unique errors are mutually independent. In the common factor model, the elements of the vector of unique errors e are also assumed to be independent of one another so that the matrix \(\Psi\) is diagonal. This is not the case in the principal component model in which the errors may be correlated.
Further differences between the various methods concern the criterion that is optimized and the amount of computer effort required to obtain estimates. Generally speaking, the least-squares and maximum likelihood methods, which use iterative algorithms, require the most computer time with the principal factor, principal component, and the image methods requiring much less time since the algorithms in these methods are not iterative. The algorithm in alpha factor analysis is also iterative, but the estimates in this method generally require somewhat less computer effort than the least-squares and maximum likelihood estimates. In all algorithms one eigensystem analysis is required on each iteration.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBad variance error.static classEigenvalue error.static classNon positive eigenvalue error.static classMatrix not positive definite.static classCovariance matrix not positive semi-definite.static classHessian matrix not semi-definite.static classRank of covariance matrix error.static enumIndicates which method is used for computing the factor score coefficients.static classCovariance matrix singular error. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates alpha factor analysis.static final intIndicates correlation matrix.static final intIndicates generalized least squares method.static final intIndicates image factor analysis.static final intIndicates maximum likelihood method.static final intIndicates principal component model.static final intIndicates principal factor model.static final intIndicates unweighted least squares method.static final intIndicates variance-covariance matrix. -
Constructor Summary
ConstructorsConstructorDescriptionFactorAnalysis(double[][] cov, int matrixType, int nf) Constructor forFactorAnalysis. -
Method Summary
Modifier and TypeMethodDescriptiondouble[][]Returns the correlations of the principal components.double[][]Returns the unrotated factor loadings.double[][]Computes the matrix of factor score coefficients.double[][]getFactorScores(double[][] factorScoreCoefficients, double[][] matrixOfObservations) Computes factor scores.double[]Returns the parameter updates.double[]Returns the cumulative percent of the total variance explained by each principal component.double[]Returns the estimated asymptotic standard errors of the eigenvalues.double[]Returns statistics.double[]Returns the eigenvalues.double[]Returns the unique variances.double[][]Returns the eigenvectors.voidsetConvergenceCriterion1(double eps) Sets the convergence criterion used to terminate the iterations.voidsetConvergenceCriterion2(double epse) Sets the convergence criterion used to switch to exact second derivatives.voidsetDegreesOfFreedom(int ndf) Sets the number of degrees of freedom.voidsetFactorLoadingEstimationMethod(int methodType) Sets the factor loading estimation method.voidsetMaxIterations(int maxit) Sets the maximum number of iterations in the iterative procedure.voidsetMaxStep(int maxstp) Sets the maximum number of step halvings allowed during an iteration.voidsetVarianceEstimationMethod(int init) Sets the variance estimation method.voidsetVariances(double[] uniq) Sets the initial values of the unique variances.
-
Field Details
-
VARIANCE_COVARIANCE_MATRIX
public static final int VARIANCE_COVARIANCE_MATRIXIndicates variance-covariance matrix.- See Also:
-
CORRELATION_MATRIX
public static final int CORRELATION_MATRIXIndicates correlation matrix.- See Also:
-
PRINCIPAL_COMPONENT_MODEL
public static final int PRINCIPAL_COMPONENT_MODELIndicates principal component model.- See Also:
-
PRINCIPAL_FACTOR_MODEL
public static final int PRINCIPAL_FACTOR_MODELIndicates principal factor model.- See Also:
-
UNWEIGHTED_LEAST_SQUARES
public static final int UNWEIGHTED_LEAST_SQUARESIndicates unweighted least squares method.- See Also:
-
GENERALIZED_LEAST_SQUARES
public static final int GENERALIZED_LEAST_SQUARESIndicates generalized least squares method.- See Also:
-
MAXIMUM_LIKELIHOOD
public static final int MAXIMUM_LIKELIHOODIndicates maximum likelihood method.- See Also:
-
IMAGE_FACTOR_ANALYSIS
public static final int IMAGE_FACTOR_ANALYSISIndicates image factor analysis.- See Also:
-
ALPHA_FACTOR_ANALYSIS
public static final int ALPHA_FACTOR_ANALYSISIndicates alpha factor analysis.- See Also:
-
-
Constructor Details
-
FactorAnalysis
public FactorAnalysis(double[][] cov, int matrixType, int nf) Constructor forFactorAnalysis.- Parameters:
cov- Adoublematrix containing the covariance or correlation matrix.matrixType- Anintscalar indicating the type of matrix that is input. Uses class memberVARIANCE_COVARIANCE_MATRIXorCORRELATION_MATRIXformatrixType.nf- Anintscalar indicating the number of factors in the model. Ifnfis not known in advance, several different values ofnfshould be used, and the most reasonable value kept in the final solution. Since, in practice, the non-iterative methods often lead to solutions which differ little from the iterative methods, it is usually suggested that a non-iterative method be used in the initial stages of the factor analysis, and that the iterative methods be used once issues such as the number of factors have been resolved.- Throws:
IllegalArgumentException- is thrown if one of the input arguments is not feasible.
-
-
Method Details
-
getFactorLoadings
public double[][] getFactorLoadings() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the unrotated factor loadings.- Returns:
- A
doublematrix containing the unrotated factor loadings. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
setDegreesOfFreedom
public void setDegreesOfFreedom(int ndf) Sets the number of degrees of freedom.- Parameters:
ndf- Anintvalue specifying the number of degrees of freedom in the input matrix. If this member function is not called 100 degrees of freedom are assumed.
-
setVariances
public void setVariances(double[] uniq) Sets the initial values of the unique variances. Unique variance denotes the component of the variance specific for a variable, as opposed to the part of the variance that is attributable to the common factors.- Parameters:
uniq- Adoublearray of length nvar containing the initial unique variances, wherenvaris the number of variables. If this member function is not called, the elements of uniq are set to 0.0 for the principal component, principal factor and alpha factor analysis models. For all other models, the entries in uniq are set toStrictMath.min(1.0e-6, cov[i][i]), i = 0,..., nvar.
If the iterative methods fail for the unique variances used, new initial estimates should be tried. These may be obtained by use of another factoring method (use the final estimates from the new method as initial estimates in the old method). Another alternative is to call member functionsetVarianceEstimationMethodand set the input argument to 0. This will cause the initial unique variances to be estimated by the code.
-
setConvergenceCriterion1
public void setConvergenceCriterion1(double eps) Sets the convergence criterion used to terminate the iterations.- Parameters:
eps- Adoubleused to terminate the iterations. For the least squares and and maximum likelihood methods convergence is assumed when the relative change in the criterion is less thaneps. For alpha factor analysis, convergence is assumed when the maximum change (relative to the variance) of a uniqueness is less thaneps.epsis not referenced for the other estimation methods. If this member function is not called,epsis set to 0.0001.
-
setConvergenceCriterion2
public void setConvergenceCriterion2(double epse) Sets the convergence criterion used to switch to exact second derivatives.- Parameters:
epse- Adoubleused to switch to exact second derivatives. When the largest relative change in the unique standard deviation vector is less thanepseexact second derivative vectors are used. If this member function is not called,epseis set to 0.1. Not referenced for principal component, principal factor, image factor, or alpha factor methods.
-
setMaxStep
public void setMaxStep(int maxstp) Sets the maximum number of step halvings allowed during an iteration.- Parameters:
maxstp- Anintused as the maximum number of step halvings allowed during an iteration. If this member function is not called,maxstpis set to 8. Not referenced for principal component, principal factor, image factor, or alpha factor methods.
-
setMaxIterations
public void setMaxIterations(int maxit) Sets the maximum number of iterations in the iterative procedure.- Parameters:
maxit- Anintused as the maximum number of iterations allowed during the iterative portion of the algorithm. If this member function is not called,maxitis set to 60. Not referenced for factor loading methods principal component, principal factor, or image factor methods.
-
setVarianceEstimationMethod
public void setVarianceEstimationMethod(int init) Sets the variance estimation method.- Parameters:
init- Anintused to designate the method to be applied for obtaining the initial estimates of the unique variances. If this member function is not called,initis set to 1.
Note that when the factor loading estimation method is PRINCIPAL_COMPONENT_MODEL, the initial estimates ininit Method 0 Initial estimates are taken as the constant 1-nf/(2*nvar) divided by the diagonal elements of the inverse of input matrix cov, wherenvaris the number of variables.1 Initial estimates are input by the user in vector uniq (setVariances).uniqare reset to 0.0.
-
setFactorLoadingEstimationMethod
public void setFactorLoadingEstimationMethod(int methodType) Sets the factor loading estimation method.- Parameters:
methodType- Anintscalar indicating the method to be applied for obtaining the factor loadings. Use class memberPRINCIPAL_COMPONENT_MODEL,PRINCIPAL_FACTOR_MODEL,UNWEIGHTED_LEAST_SQUARES,GENERALIZED_LEAST_SQUARES,MAXIMUM_LIKELIHOOD,IMAGE_FACTOR_ANALYSIS, orALPHA_FACTOR_ANALYSISformethodType. If this member function is not called, thePRINCIPAL_COMPONENT_MODELis used.For the principal component and principal factor methods, the factor loading estimates are computed as $$\hat{\Gamma}\hat{\Delta}^{-1/2}$$ where \(\Gamma\) and the diagonal matrix \(\Delta\) are the eigenvalues and eigenvectors of a matrix. In the principal component model, the eigensystem analysis is performed on the sample covariance (correlation) matrix \(S\) while in the principal factor model the matrix \((S - \Psi)\) is used. If the unique error variances \(\Psi\) are not known in the principal factor model, then they are estimated. This is achieved by calling the member function
setVarianceEstimationMethodand settinginitto 0. If the principal component model is used, the error variances are set to 0.0 automatically.The basic idea in the principal component method is to find factors that maximize the variance in the original data that is explained by the factors. Because this method allows the unique errors to be correlated, some factor analysts insist that the principal component method is not a factor analytic method. Usually however, the estimates obtained via the principal component model and other models in factor analysis will be quite similar.
It should be noted that both the principal component and the principal factor methods give different results when the correlation matrix is used in place of the covariance matrix. Indeed, any rescaling of the sample covariance matrix can lead to different estimates with either of these methods. A further difficulty with the principal factor method is the problem of estimating the unique error variances. Theoretically, these must be known in advance and passed in through member function
setVariances. In practice, the estimates of these parameters produced by calling the member functionsetVarianceEstimationMethodand settinginitto 0 are often used. In either case, the resulting adjusted covariance (correlation) matrix $$(S - \hat{\Psi})$$ may not yield thenfpositive eigenvalues required fornffactors to be obtained. If this occurs, the user must either lower the number of factors to be estimated or give new unique error variance values.For the least-squares and maximum likelihood methods an iterative algorithm is used to obtain the estimates (see Joreskog 1977). As with the principal factor model, the user may either input the initial unique error variances or allow the algorithm to compute initial estimates. Unlike the principal factor method, the code then optimizes the criterion function with respect to both \(\Psi\) and \(\Gamma\). (In the principal factor method, \(\Psi\) is assumed to be known. Given \(\Psi\), estimates for \(\Lambda\) may be obtained.)
The major differences between the estimation methods described in this member function are in the criterion function that is optimized. Let \(S\) denote the sample covariance (correlation) matrix, and let \(\Sigma\) denote the covariance matrix that is to be estimated by the factor model. In the unweighted least-squares method, also called the iterated principal factor method or the minres method (see Harman 1976, page 177), the function minimized is the sum of the squared differences between \(S\) and \(\Sigma\). This is written as \(\Phi_ul = .5 trace((S - \Sigma)^2)\).
Generalized least-squares and maximum likelihood estimates are asymptotically equivalent methods. Maximum likelihood estimates maximize the (normal theory) likelihood \(\{\Phi_ml = trace(\Sigma^{-1}S) - log(|\Sigma^{-1}S|)\}.\) while generalized least squares optimizes the function \(\Phi_gs = trace(\Sigma S^{-1} - I)^2\).
In all three methods, a two-stage optimization procedure is used. This proceeds by first solving the likelihood equations for \(\Lambda\) in terms of \(\Psi\) and substituting the solution into the likelihood. This gives a criterion \(\Phi(\Psi, \Lambda(\Psi))\), which is optimized with respect to \(\Psi\). In the second stage, the estimates $$\hat{\Lambda}$$ are obtained from the estimates for \(\Psi\).
The generalized least-squares and the maximum likelihood methods allow for the computation of a statistic for testing that
nfcommon factors are adequate to fit the model. This is a chi-squared test that all remaining parameters associated with additional factors are zero. If the probability of a larger chi-squared is small (seestat[4]undergetStatistics) so that the null hypothesis is rejected, then additional factors are needed (although these factors may not be of any practical importance). Failure to reject does not legitimize the model. The statisticstat[2]is a likelihood ratio statistic in maximum likelihood estimates. As such, it asymptotically follows a chi-squared distribution with degrees of freedom given instat[3].The Tucker and Lewis (1973) reliability coefficient, \(\rho\), is returned in
stat[1]when the maximum likelihood or generalized least-squares methods are used. This coefficient is an estimate of the ratio of explained to the total variation in the data. It is computed as follows: $$ \rho = \frac{mM_o - mM_k}{mM_o - 1}$$ $$ m = d - \frac{2p + 5}{6} - \frac{2k}{6}$$ $$ M_o = \frac{-ln(|S|)}{p(p-1)/2}$$ $$ M_k = \frac{\Phi}{((p-k)^2 - p - k)/2}$$ where \(|S|\) is the determinant ofcov, p is the number of variables, k is the number of factors, \(\Phi\) is the optimized criterion, and d is the number of degrees of freedom.The term "image analysis" is used here to denote the noniterative image method of Kaiser (1963). It is not the image factor analysis discussed by Harman (1976, page 226). The image method (as well as the alpha factor analysis method) begins with the notion that only a finite number from an infinite number of possible variables have been measured. The image factor pattern is calculated under the assumption that the ratio of the number of factors to the number of observed variables is near zero so that a very good estimate for the unique error variances (for standardized variables) is given as one minus the squared multiple correlation of the variable under consideration with all variables in the covariance matrix.
First, the matrix \(D^2 = (diag(S^{-1}))^{-1}\) is computed where the operator "diag" results in a matrix consisting of the diagonal elements of its argument, and \(S\) is the sample covariance (correlation) matrix. Then, the eigenvalues \(\Lambda\) and eigenvectors \(\Gamma\) of the matrix \(D^{-1} S D^{-1}\) are computed. Finally, the unrotated image factor pattern matrix is computed as \(A = D\Gamma[(\Lambda - I)^2 \Lambda^{-1}]^{1/2}\).
The alpha factor analysis method of Kaiser and Caffrey (1965) finds factor-loading estimates to maximize the correlation between the factors and the complete universe of variables of interest. The basic idea in this method is as follows: only a finite number of variables out of a much larger set of possible variables is observed. The population factors are linearly related to this larger set while the observed factors are linearly related to the observed variables. Let f denote the factors obtainable from a finite set of observed random variables, and let \(\xi\) denote the factors obtainable from the universe of observable variables. Then, the alpha method attempts to find factor-loading estimates so as to maximize the correlation between f and \(\xi\). In order to obtain these estimates, the iterative algorithm of Kaiser and Caffrey (1965) is used.
-
getVariances
public double[] getVariances() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the unique variances.- Returns:
- A
doublearray of length nvar containing the unique variances, wherenvaris the number of variables. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getValues
public double[] getValues() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the eigenvalues.- Returns:
- A
doublearray containing the eigenvalues of the matrix from which the factors were extracted ordered from largest to smallest. If Alpha Factor analysis is used, then the firstnfpositions of the array contain the Alpha coefficients. Here,nfis the number of factors in the model. If the algorithm fails to converge for a particular eigenvalue, that eigenvalue is set to NaN. Note that the eigenvalues are usually not the eigenvalues of the input matrix cov. They are the eigenvalues of the input matrix cov when theprincipal componentmethod is used. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getVectors
public double[][] getVectors() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the eigenvectors.- Returns:
- A
doublematrix containing the eigenvectors of the matrix from which the factors were extracted. The j-th column of the eigenvector matrix corresponds to the j-th eigenvalue. The eigenvectors are normalized to each have Euclidean length equal to one. Also, the sign of each vector is set so that the largest component in magnitude (the first of the largest if there are ties) is made positive. Note that the eigenvectors are usually not the eigenvectors of the input matrix cov. They are the eigenvectors of the input matrix cov when theprincipal componentmethod is used. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getStatistics
public double[] getStatistics() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns statistics.- Returns:
- A
doublearray (Stat) containing output statistics. Stat is not defined and is set to NaN when the method used to obtain the estimates, is the principal component method, principal factor method, image factor analysis method, or alpha analysis method.i Stat[i] 0 Value of the function minimum. 1 Tucker reliability coefficient. 2 Chi-squared test statistic for testing that the number of factors in the model are adequate for the data. 3 Degrees of freedom in chi-squared. This is computed as \(((nvar - nf)^2 - nvar - nf)/2\)
wherenvaris the number of variables andnfis the number of factors in the model.4 Probability of a greater chi-squared statistic. 5 Number of iterations. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getParameterUpdates
public double[] getParameterUpdates() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the parameter updates.- Returns:
- A
doublearray containing the parameter updates when convergence was reached (or the iterations terminated). The parameter updates are only meaningful for the common factor model. The parameter updates are set to 0.0 for the principal component model. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getPercents
public double[] getPercents() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the cumulative percent of the total variance explained by each principal component. Valid for the principal component model.- Returns:
- An
doublearray containing the total variance explained by each principal component. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getStandardErrors
public double[] getStandardErrors() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the estimated asymptotic standard errors of the eigenvalues.- Returns:
- a
doublearray containing the estimated asymptotic standard errors of the eigenvalues. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getCorrelations
public double[][] getCorrelations() throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueExceptionReturns the correlations of the principal components.- Returns:
- A
doublematrix containing the correlations of the principal components with the observed/standardized variables. If a covariance matrix is input to the constructor, then the correlations are with the observed variables. Otherwise, the correlations are with the standardized (to a variance of 1.0) variables. Only valid for the principal components model. - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueException
-
getFactorScores
public double[][] getFactorScores(double[][] factorScoreCoefficients, double[][] matrixOfObservations) Computes factor scores.- Parameters:
factorScoreCoefficients- adoublematrix of sizepbykcontaining the factor score coefficient matrix. Here,pis the number of variables andkthe number of factor scores.matrixOfObservations- adoublematrix of sizenbyp, wherenis the number of observations andpthe number of variables.
If theFactorAnalysisobject was created withmatrixType = VARIANCE_COVARIANCE_MATRIX, the observations x must be centered about the sample or population mean \(\mu\), \(x := x - \mu\).
IfmatrixType = CORRELATION_MATRIXhas been used, the observations must be standardized, \(x := D^{-1/2}(x -\mu)\), \(\mu\) the sample or population mean and D a diagonal matrix with the sample or population variances of x on the diagonal.- Returns:
- a
doublematrix of sizenbykcontaining the factor scores related to the observations inmatrixOfObservations. Here,nis the number of observations andkthe number of factor scores.
-
getFactorScoreCoefficients
public double[][] getFactorScoreCoefficients(FactorAnalysis.ScoreMethod method) throws FactorAnalysis.RankException, FactorAnalysis.NotSemiDefiniteException, FactorAnalysis.NotPositiveSemiDefiniteException, FactorAnalysis.NotPositiveDefiniteException, FactorAnalysis.SingularException, FactorAnalysis.BadVarianceException, FactorAnalysis.EigenvalueException, FactorAnalysis.NonPositiveEigenvalueException, SingularMatrixException, Cholesky.NotSPDException Computes the matrix of factor score coefficients.- Parameters:
method- an enum of typeFactorAnalysis.ScoreMethodindicating which computation method for the factor scores coefficients to use- Returns:
- a
doublematrix of sizenbykcontaining the matrix of factor score coefficients. Here,kdenotes the number of factors in the model andnthe number of variables. The matrix of factor score coefficients W is defined as the matrix that transforms an observation x into its factor scores f, \(f = W^T x\). According to the enum constants inFactorAnalysis.ScoreMethod, 5 methods for computing the factor score coefficients are available:
1. Regression method: \(W=S^{-1}L\)
2. Least-squares method: \(W=L(L^TL)^{-1}\)
3. Bartlett's method: \(W=\Psi^{-1}L(L^T\Psi^{-1}L)^{-1}\)
4. Method of Anderson and Rubin: \(W=\Psi^{-1}L(L^T\Psi^{-1} S \Psi^{-1} L)^{-1/2}\)
5. Image method: \(W = {\rm{diag}}(S)^{-1} L\)
Here, \(S\) is the sample covariance or correlation matrix, \(L\) the matrix of (unrotated) factor loadings and \(\Psi\) the diagonal matrix containing the specific variances. The following table shows which combinations of factor model and factor score coefficient method are feasible:Factor model Factor score coefficient method PRINCIPAL_COMPONENT_MODEL REGRESSION, LEAST_SQUARES PRINCIPAL_FACTOR_MODEL REGRESSION, LEAST_SQUARES UNWEIGHTED_LEAST_SQUARES REGRESSION, LEAST_SQUARES, BARTLETT, ANDERSON_RUBIN GENERALIZED_LEAST_SQUARES REGRESSION, LEAST_SQUARES, BARTLETT, ANDERSON_RUBIN MAXIMUM_LIKELIHOOD REGRESSION, LEAST_SQUARES, BARTLETT, ANDERSON_RUBIN IMAGE_FACTOR_ANALYSIS IMAGE ALPHA_FACTOR_ANALYSIS REGRESSION, LEAST_SQUARES, BARTLETT, ANDERSON_RUBIN - Throws:
FactorAnalysis.RankExceptionFactorAnalysis.NotSemiDefiniteExceptionFactorAnalysis.NotPositiveSemiDefiniteExceptionFactorAnalysis.NotPositiveDefiniteExceptionFactorAnalysis.SingularExceptionFactorAnalysis.BadVarianceExceptionFactorAnalysis.EigenvalueExceptionFactorAnalysis.NonPositiveEigenvalueExceptionSingularMatrixExceptionCholesky.NotSPDException
-