NAG Library Routine Document

g03caf  (factor)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

g03caf computes the maximum likelihood estimates of the arguments 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.

2
Specification

Fortran Interface
Subroutine g03caf ( matrix, weight, n, m, x, ldx, nvar, isx, nfac, wt, e, stat, com, psi, res, fl, ldfl, iop, iwk, wk, lwk, ifail)
Integer, Intent (In):: n, m, ldx, nvar, isx(m), nfac, ldfl, iop(5), lwk
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: iwk(4*nvar+2)
Real (Kind=nag_wp), Intent (In):: x(ldx,m), wt(*)
Real (Kind=nag_wp), Intent (Inout):: fl(ldfl,nfac)
Real (Kind=nag_wp), Intent (Out):: e(nvar), stat(4), com(nvar), psi(nvar), res(nvar*(nvar-1)/2), wk(lwk)
Character (1), Intent (In):: matrix, weight
C Header Interface
#include nagmk26.h
void  g03caf_ ( const char *matrix, const char *weight, const Integer *n, const Integer *m, const double x[], const Integer *ldx, const Integer *nvar, const Integer isx[], const Integer *nfac, const double wt[], double e[], double stat[], double com[], double psi[], double res[], double fl[], const Integer *ldfl, const Integer iop[], Integer iwk[], double wk[], const Integer *lwk, Integer *ifail, const Charlen length_matrix, const Charlen length_weight)

3
Description

Let p variables, x1,x2,,xp, with variance-covariance matrix Σ be observed. The aim of factor analysis is to account for the covariances in these p variables in terms of a smaller number, k, of hypothetical variables, or factors, f1,f2,,fk. 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:
xi=j=1kλijfj+ei,  i=1,2,,p  
where λij, for i=1,2,,p and j=1,2,,k, are the factor loadings and ei, for i=1,2,,p, are independent random variables with variances ψi, for i=1,2,,p. The ψi 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 routine it is assumed that both the k factors and the ei's follow independent Normal distributions.
The model for the variance-covariance matrix, Σ, can be written as:
Σ=ΛΛT+Ψ (1)
where Λ is the matrix of the factor loadings, λij, and Ψ is a diagonal matrix of unique variances, ψi, for i=1,2,,p.
The estimation of the arguments of the model, Λ and Ψ, by maximum likelihood is described by Lawley and Maxwell (1971). The log-likelihood is:
-12n-1logΣ-12n-1traceS,Σ-1+constant,  
where n is the number of observations, S is the sample variance-covariance matrix or, if weights are used, S is the weighted sample variance-covariance matrix and n is the effective number of observations, that is, the sum of the weights. The constant is independent of the arguments of the model. A two stage maximization is employed. It makes use of the function FΨ, which is, up to a constant, -2/n-1 times the log-likelihood maximized over Λ. This is then minimized with respect to Ψ to give the estimates, Ψ^, of Ψ. The function FΨ can be written as:
FΨ=j=k+1pθj-logθj-p-k  
where values θj, for j=1,2,,p are the eigenvalues of the matrix:
S*=Ψ-1/2SΨ-1/2.  
The estimates Λ^, of Λ, are then given by scaling the eigenvectors of S*, which are denoted by V:
Λ^=Ψ1/2VΘ-I1/2.  
where Θ is the diagonal matrix with elements θi, and I is the identity matrix.
The minimization of FΨ is performed using e04lbf 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 S* as described above, the singular value decomposition of the matrix RΨ-1/2 is used, where R is obtained either from the QR decomposition of the (scaled) mean centred data matrix or from the Cholesky decomposition of the correlation/covariance matrix. The routine e04lbf ensures that the values of ψi are greater than a given small positive quantity, δ, so that the communality is always less than one. This avoids the so called Heywood cases.
In addition to the values of Λ, Ψ and the communalities, g03caf returns the residual correlations, i.e., the off-diagonal elements of C-ΛΛT+Ψ where C is the sample correlation matrix. g03caf also returns the test statistic:
χ2=n-1-2p+5/6-2k/3FΨ^  
which can be used to test the goodness-of-fit of the model (1), see Lawley and Maxwell (1971) and Morrison (1967).

4
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

5
Arguments

1:     matrix – Character(1)Input
On entry: selects the type of matrix on which factor analysis is to be performed.
matrix='D'
The data matrix will be input in x and factor analysis will be computed for the correlation matrix.
matrix='S'
The data matrix will be input in x and factor analysis will be computed for the covariance matrix, i.e., the results are scaled as described in Section 9.
matrix='C'
The correlation/variance-covariance matrix will be input in x and factor analysis computed for this matrix.
Constraint: matrix='D', 'S' or 'C'.
2:     weight – Character(1)Input
On entry: if matrix='D' or 'S', weight indicates if weights are to be used.
weight='U'
No weights are used.
weight='W'
Weights are used and must be supplied in wt.
Note:  if matrix='C', weight is not referenced.
Constraint: if matrix='D' or 'S', weight='U' or 'W'.
3:     n – IntegerInput
On entry: if matrix='D' or 'S' the number of observations in the data array x.
If matrix='C' the (effective) number of observations used in computing the (possibly weighted) correlation/variance-covariance matrix input in x.
Constraint: n>nvar.
4:     m – IntegerInput
On entry: the number of variables in the data/correlation/variance-covariance matrix.
Constraint: mnvar.
5:     xldxm – Real (Kind=nag_wp) arrayInput
On entry: the input matrix.
If matrix='D' or 'S', x must contain the data matrix, i.e., xij must contain the ith observation for the jth variable, for i=1,2,,n and j=1,2,,m.
If matrix='C', x must contain the correlation or variance-covariance matrix. Only the upper triangular part is required.
6:     ldx – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which g03caf is called.
Constraints:
  • if matrix='D' or 'S', ldxn;
  • if matrix='C', ldxm.
7:     nvar – IntegerInput
On entry: p, the number of variables in the factor analysis.
Constraint: nvar2.
8:     isxm – Integer arrayInput
On entry: isxj indicates whether or not the jth variable is included in the factor analysis. If isxj1, the variable represented by the jth column of x is included in the analysis; otherwise it is excluded, for j=1,2,,m.
Constraint: isxj>0 for nvar values of j.
9:     nfac – IntegerInput
On entry: k, the number of factors.
Constraint: 1nfacnvar.
10:   wt* – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array wt must be at least n if weight='W' and matrix='D' or 'S', and at least 1 otherwise.
On entry: if weight='W' and matrix='D' or 'S', wt 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 wti=0.0, the ith observation is not included in the analysis.
If weight='U' or matrix='C', wt is not referenced and the effective number of observations is n.
Constraint: if weight='W', the sum of weights >nvar, wti0.0, for i=1,2,,n.
11:   envar – Real (Kind=nag_wp) arrayOutput
On exit: the eigenvalues θi, for i=1,2,,p.
12:   stat4 – Real (Kind=nag_wp) arrayOutput
On exit: the test statistics.
stat1
Contains the value FΨ^.
stat2
Contains the test statistic, χ2.
stat3
Contains the degrees of freedom associated with the test statistic.
stat4
Contains the significance level.
13:   comnvar – Real (Kind=nag_wp) arrayOutput
On exit: the communalities.
14:   psinvar – Real (Kind=nag_wp) arrayOutput
On exit: the estimates of ψi, for i=1,2,,p.
15:   resnvar×nvar-1/2 – Real (Kind=nag_wp) arrayOutput
On exit: the residual correlations. The residual correlation for the ith and jth variables is stored in res j-1 j-2 /2+i , i<j.
16:   flldflnfac – Real (Kind=nag_wp) arrayOutput
On exit: the factor loadings. flij contains λij, for i=1,2,,p and j=1,2,,k.
17:   ldfl – IntegerInput
On entry: the first dimension of the array fl as declared in the (sub)program from which g03caf is called.
Constraint: ldflnvar.
18:   iop5 – Integer arrayInput
On entry: options for the optimization. There are four options to be set:
iprint controls iteration monitoring;
  if iprint0, there is no printing of information else if iprint>0, information is printed at every iprint iterations. The information printed consists of the value of FΨ at that iteration, the number of evaluations of FΨ, the current estimates of the communalities and an indication of whether or not they are at the boundary.
maxfun the maximum number of function evaluations.
acc the required accuracy for the estimates of ψi.
eps a lower bound for the values of ψ, see Section 3.
Let ε=machine precision then if iop1=0, the following default values are used:
  • iprint=-1
  • maxfun=100p
  • acc=10ε
  • eps=ε
If iop10, then
  • iprint=iop2
  • maxfun=iop3
  • acc=10-l where l=iop4
  • eps=10-l where l=iop5
Constraint: if iop10, iopi must be such that maxfun1, εacc<1 and εeps<1, for i=3,4,5.
19:   iwk4×nvar+2 – Integer arrayWorkspace
20:   wklwk – Real (Kind=nag_wp) arrayWorkspace
21:   lwk – IntegerInput
On entry: the dimension of the array wk as declared in the (sub)program from which g03caf is called. The length of the workspace.
Constraints:
  • if matrix='D' or 'S', lwkmax5×nvar×nvar+33×nvar-4/2,n×nvar+7×nvar+nvar×nvar-1/2;
  • if matrix='C', lwk5×nvar×nvar+33×nvar-4/2.
22:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ifail0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Note: g03caf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
ifail=1
On entry,ldfl<nvar,
ornvar<2,
ornnvar,
ornfac<1,
ornvar<nfac,
orm<nvar,
ormatrix='D' or 'S' and ldx<n,
ormatrix='C' and ldx<m,
ormatrix'D', 'S' or 'C',
ormatrix='D' or 'S' and weight'U' or 'W',
oriop10 and iop3 is such that maxfun<1,
oriop10 and iop4 is such that acc1.0,
oriop10 and iop4 is such that acc<machine precision,
oriop10 and iop5 is such that eps1.0,
oriop10 and iop5 is such that eps<machine precision,
ormatrix='C' and lwk<5×nvar×nvar+33×nvar-4/2,
ormatrix='D' or 'S' and
lwk<max5×nvar×nvar+33×nvar-4/2,n×nvar+7×nvar+nvar×nvar-1/2.
ifail=2
On entry,weight='W' and a value of wt<0.0.
ifail=3
On entry, there are not exactly nvar elements of isx>0, or the effective number of observations nvar.
ifail=4
On entry, matrix='D' or 'S' and the data matrix is not of full column rank, or matrix='C' and the input correlation/variance-covariance matrix is not positive definite.
This exit may also be caused by two of the eigenvalues of S* being equal; this is rare (see Lawley and Maxwell (1971)), and may be due to the data/correlation matrix being almost singular.
ifail=5
A singular value decomposition has failed to converge. This is a very unlikely error exit.
ifail=6
The estimation procedure has failed to converge in the given number of iterations. Change iop to either increase number of iterations maxfun or increase the value of acc.
ifail=7
The convergence is not certain but a lower point could not be found. See e04lbf for further details. In this case all results are computed.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

The accuracy achieved is discussed in e04lbf with the value of the argument xtol given by acc as described in parameter iop.

8
Parallelism and Performance

g03caf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g03caf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9
Further Comments

The factor loadings may be orthogonally rotated by using g03baf and factor score coefficients can be computed using g03ccf. The maximum likelihood estimators are invariant to a change in scale. This means that the results obtained will be the same (up to a scaling factor) if either the correlation matrix or the variance-covariance matrix is used. As the correlation matrix ensures that all values of ψi are between 0 and 1 it will lead to a more efficient optimization. In the situation when the data matrix is input the results are always computed for the correlation matrix and then scaled if the results for the covariance matrix are required. When you input the covariance/correlation matrix the input matrix itself is used and you are advised to input the correlation matrix rather than the covariance matrix.

10
Example

This example is taken from Lawley and Maxwell (1971). The correlation matrix for nine variables is input and the arguments of a factor analysis model with three factors are estimated and printed.

10.1
Program Text

Program Text (g03cafe.f90)

10.2
Program Data

Program Data (g03cafe.d)

10.3
Program Results

Program Results (g03cafe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017