NAG FL Interface
g03caf (factor)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g03caf 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.

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 <nag.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)
The routine may be called by the names g03caf or nagf_mv_factor.

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 parameters of the model, Λ and Ψ, by maximum likelihood is described by Lawley and Maxwell (1971). The log-likelihood is:
-12(n-1)log(|Σ|)-12(n-1)trace(S,Σ-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 parameters 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(Θ-I)1/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 1. 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/3]F(Ψ^)  
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 Integer Input
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 Integer Input
On entry: the number of variables in the data/correlation/variance-covariance matrix.
Constraint: mnvar.
5: x(ldx,m) Real (Kind=nag_wp) array Input
On entry: the input matrix.
If matrix='D' or 'S', x must contain the data matrix, i.e., x(i,j) 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 Integer Input
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 Integer Input
On entry: p, the number of variables in the factor analysis.
Constraint: nvar2.
8: isx(m) Integer array Input
On entry: isx(j) indicates whether or not the jth variable is included in the factor analysis. If isx(j)1, the variable represented by the jth column of x is included in the analysis; otherwise it is excluded, for j=1,2,,m.
Constraint: isx(j)>0 for nvar values of j.
9: nfac Integer Input
On entry: k, the number of factors.
Constraint: 1nfacnvar.
10: wt(*) Real (Kind=nag_wp) array Input
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 wt(i)=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.
Constraints:
if weight='W',
  • wt(i)0.0, for i=1,2,,n;
  • the sum of weights >nvar.
11: e(nvar) Real (Kind=nag_wp) array Output
On exit: the eigenvalues θi, for i=1,2,,p.
12: stat(4) Real (Kind=nag_wp) array Output
On exit: the test statistics.
stat(1)
Contains the value F(Ψ^).
stat(2)
Contains the test statistic, χ2.
stat(3)
Contains the degrees of freedom associated with the test statistic.
stat(4)
Contains the significance level.
13: com(nvar) Real (Kind=nag_wp) array Output
On exit: the communalities.
14: psi(nvar) Real (Kind=nag_wp) array Output
On exit: the estimates of ψi, for i=1,2,,p.
15: res(nvar×(nvar-1)/2) Real (Kind=nag_wp) array Output
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: fl(ldfl,nfac) Real (Kind=nag_wp) array Output
On exit: the factor loadings. fl(i,j) contains λij, for i=1,2,,p and j=1,2,,k.
17: ldfl Integer Input
On entry: the first dimension of the array fl as declared in the (sub)program from which g03caf is called.
Constraint: ldflnvar.
18: iop(5) Integer array Input
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 iop(1)=0, the following default values are used:
  • iprint=−1
  • maxfun=100p
  • acc=10ε
  • eps=ε
If iop(1)0, then
  • iprint=iop(2)
  • maxfun=iop(3)
  • acc=10-l where l=iop(4)
  • eps=10-l where l=iop(5)
Constraint: if iop(1)0, iop(i) must be such that maxfun1, εacc<1 and εeps<1, for i=3,4,5.
19: iwk(4×nvar+2) Integer array Workspace
20: wk(lwk) Real (Kind=nag_wp) array Workspace
21: lwk Integer Input
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', lwkmax((5×nvar×nvar+33×nvar-4)/2,n×nvar+7×nvar+nvar×(nvar-1)/2);
  • if matrix='C', lwk(5×nvar×nvar+33×nvar-4)/2.
22: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value −1 is recommended since useful values can be provided in some output arguments even when ifail0 on exit. 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).
Errors or warnings detected by the routine:
Note: in some cases g03caf may return useful information.
ifail=1
On entry, iop(1)1 and iop(3)=value.
Constraint: maxfun1.
On entry, iop(1)1 and iop(4)=value.
Constraint: 1accmachine precision.
On entry, iop(1)1 and iop(5)=value.
Constraint: 1epsmachine precision.
On entry, ldfl=value and nvar=value.
Constraint: ldflnvar.
On entry, ldx=value and m=value.
Constraint: ldxm.
On entry, ldx=value and n=value.
Constraint: ldxn.
On entry, lwk=value.
Constraint: lwkvalue.
On entry, m=value and nvar=value.
Constraint: mnvar.
On entry, matrix=value.
Constraint: matrix='D', 'S' or 'C'.
On entry, n=value and nvar=value.
Constraint: n>nvar.
On entry, nfac=value.
Constraint: nfac1.
On entry, nfac=value and nvar=value.
Constraint: nfacnvar.
On entry, nvar=value.
Constraint: nvar>1.
On entry, weight=value.
Constraint: when matrix='D' or 'S', weight='U' or 'W'.
ifail=2
On entry, i=value and wt(i)<0.0.
Constraint: wt(i)0.0.
ifail=3
On entry, nvar=value and value values of isx>0
Constraint: exactly nvar elements of isx>0.
The effective number of observations 1.
The number of variables number of included observations.
ifail=4
On entry, the data matrix is not of full column rank or the input correlation/covariance matrix is not positive definite.
Two eigenvalues of S* are equal. This error exit is rare (see Lawley and Maxwell (1971)), and may be due to the data/correlation matrix being almost singular.
ifail=5
The singular value decomposition has failed to converge. This is an unlikely error exit.
ifail=6
The estimation procedure has failed to converge in value iterations. Change iop to either increase the 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. All results are computed.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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

Background information to multithreading can be found in the Multithreading documentation.
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 parameters 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)