naginterfaces.library.mv.factor¶
- naginterfaces.library.mv.factor(matrix, n, x, nvar, isx, nfac, iop, wt=None, io_manager=None)[source]¶
factor
computes the maximum likelihood estimates of the parameters of a factor analysis model. Either the data matrix or a correlation/covariance matrix may be input. Factor loadings, communalities and residual correlations are returned.For full information please refer to the NAG Library document for g03ca
https://www.nag.com/numeric/nl/nagdoc_29/flhtml/g03/g03caf.html
- Parameters
- matrixstr, length 1
Selects the type of matrix on which factor analysis is to be performed.
The data matrix will be input in and factor analysis will be computed for the correlation matrix.
The data matrix will be input in and factor analysis will be computed for the covariance matrix, i.e., the results are scaled as described in Further Comments.
The correlation/variance-covariance matrix will be input in and factor analysis computed for this matrix.
See Further Comments.
- nint
If or the number of observations in the data array .
If the (effective) number of observations used in computing the (possibly weighted) correlation/variance-covariance matrix input in .
- xfloat, array-like, shape
Note: the required extent for this argument in dimension 1 is determined as follows: if : ; if : ; otherwise: .
The input matrix.
If or , must contain the data matrix, i.e., must contain the th observation for the th variable, for , for .
If , must contain the correlation or variance-covariance matrix.
Only the upper triangular part is required.
- nvarint
, the number of variables in the factor analysis.
- isxint, array-like, shape
indicates whether or not the th variable is included in the factor analysis. If , the variable represented by the th column of is included in the analysis; otherwise it is excluded, for .
- nfacint
, the number of factors.
- iopint, array-like, shape
Options for the optimization. There are four options to be set:
controls iteration monitoring;
if , there is no printing of information else if , information is printed at every iprint iterations. The information printed consists of the value of at that iteration, the number of evaluations of , the current estimates of the communalities and an indication of whether or not they are at the boundary.
the maximum number of function evaluations.
the required accuracy for the estimates of .
a lower bound for the values of , see Notes.
Let then if , the following default values are used:
If , then
where
where
- wtNone or float, array-like, shape , optional
Note: the required length for this argument is determined as follows: if : ; otherwise: .
If and or , must contain the weights to be used in the factor analysis. The effective number of observations in the analysis will then be the sum of weights. If , the th observation is not included in the analysis.
If or , is not referenced and the effective number of observations is .
- io_managerFileObjManager, optional
Manager for I/O in this routine.
- Returns
- efloat, ndarray, shape
The eigenvalues , for .
- statfloat, ndarray, shape
The test statistics.
Contains the value .
Contains the test statistic, .
Contains the degrees of freedom associated with the test statistic.
Contains the significance level.
- comfloat, ndarray, shape
The communalities.
- psifloat, ndarray, shape
The estimates of , for .
- resfloat, ndarray, shape
The residual correlations. The residual correlation for the th and th variables is stored in , .
- flfloat, ndarray, shape
The factor loadings. contains , for , for .
- Raises
- NagValueError
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: , or .
- (errno )
On entry, .
Constraint: when or , or .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
The effective number of observations .
- (errno )
The number of variables number of included observations.
- (errno )
On entry, and values of
Constraint: exactly elements of .
- (errno )
Two eigenvalues of are equal.
- (errno )
On entry, the data matrix is not of full column rank or the input correlation/covariance matrix is not positive definite.
- (errno )
The singular value decomposition has failed to converge.
- (errno )
The estimation procedure has failed to converge in iterations.
- Warns
- NagAlgorithmicWarning
- (errno )
The convergence is not certain but a lower point could not be found.
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
Let variables, , with variance-covariance matrix be observed. The aim of factor analysis is to account for the covariances in these variables in terms of a smaller number, , of hypothetical variables, or factors, . These are assumed to be independent and to have unit variance. The relationship between the observed variables and the factors is given by the model:
where , for , for , are the factor loadings and , for , are independent random variables with variances , for . The represent the unique component of the variation of each observed variable. The proportion of variation for each variable accounted for by the factors is known as the communality. For this function it is assumed that both the factors and the ’s follow independent Normal distributions.
The model for the variance-covariance matrix, , can be written as:
where is the matrix of the factor loadings, , and is a diagonal matrix of unique variances, , for .
The estimation of the parameters of the model, and , by maximum likelihood is described by Lawley and Maxwell (1971). The log-likelihood is:
where is the number of observations, is the sample variance-covariance matrix or, if weights are used, is the weighted sample variance-covariance matrix and is the effective number of observations, that is, the sum of the weights. The constant is independent of the parameters of the model. A two stage maximization is employed. It makes use of the function , which is, up to a constant, times the log-likelihood maximized over . This is then minimized with respect to to give the estimates, , of . The function can be written as:
where values , for are the eigenvalues of the matrix:
The estimates , of , are then given by scaling the eigenvectors of , which are denoted by :
where is the diagonal matrix with elements , and is the identity matrix.
The minimization of is performed using
opt.bounds_mod_deriv2_comp
which uses a modified Newton algorithm. The computation of the Hessian matrix is described by Clark (1970). However, instead of using the eigenvalue decomposition of the matrix as described above, the singular value decomposition of the matrix is used, where is obtained either from the decomposition of the (scaled) mean centred data matrix or from the Cholesky decomposition of the correlation/covariance matrix. The functionopt.bounds_mod_deriv2_comp
ensures that the values of are greater than a given small positive quantity, , so that the communality is always less than . This avoids the so called Heywood cases.In addition to the values of , and the communalities,
factor
returns the residual correlations, i.e., the off-diagonal elements of where is the sample correlation matrix.factor
also returns the test statistic:which can be used to test the goodness-of-fit of the model (1), see Lawley and Maxwell (1971) and Morrison (1967).
- References
Clark, M R B, 1970, A rapidly convergent method for maximum likelihood factor analysis, British J. Math. Statist. Psych.
Hammarling, S, 1985, The singular value decomposition in multivariate statistics, SIGNUM Newsl. (20(3)), 2–25
Lawley, D N and Maxwell, A E, 1971, Factor Analysis as a Statistical Method, (2nd Edition), Butterworths
Morrison, D F, 1967, Multivariate Statistical Methods, McGraw–Hill