NAG Library Routine Document

1Purpose

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.

2Specification

Fortran Interface
 Subroutine g03caf ( n, m, x, ldx, nvar, isx, nfac, wt, e, stat, com, psi, res, fl, ldfl, iop, iwk, wk, lwk,
 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
#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)

3Description

Let $p$ variables, ${x}_{1},{x}_{2},\dots ,{x}_{p}$, with variance-covariance matrix $\Sigma$ 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, ${f}_{1},{f}_{2},\dots ,{f}_{k}$. 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 ${\lambda }_{\mathit{i}\mathit{j}}$, for $\mathit{i}=1,2,\dots ,p$ and $\mathit{j}=1,2,\dots ,k$, are the factor loadings and ${e}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$, are independent random variables with variances ${\psi }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$. The ${\psi }_{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 ${e}_{i}$'s follow independent Normal distributions.
The model for the variance-covariance matrix, $\Sigma$, can be written as:
 $Σ=ΛΛT+Ψ$ (1)
where $\Lambda$ is the matrix of the factor loadings, ${\lambda }_{ij}$, and $\Psi$ is a diagonal matrix of unique variances, ${\psi }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$.
The estimation of the parameters of the model, $\Lambda$ and $\Psi$, 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 parameters of the model. A two stage maximization is employed. It makes use of the function $F\left(\Psi \right)$, which is, up to a constant, $-2/\left(n-1\right)$ times the log-likelihood maximized over $\Lambda$. This is then minimized with respect to $\Psi$ to give the estimates, $\stackrel{^}{\Psi }$, of $\Psi$. The function $F\left(\Psi \right)$ can be written as:
 $FΨ=∑j=k+1pθj-log⁡θj-p-k$
where values ${\theta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$ are the eigenvalues of the matrix:
 $S*=Ψ-1/2SΨ-1/2.$
The estimates $\stackrel{^}{\Lambda }$, of $\Lambda$, are then given by scaling the eigenvectors of ${S}^{*}$, which are denoted by $V$:
 $Λ^=Ψ1/2VΘ-I1/2.$
where $\Theta$ is the diagonal matrix with elements ${\theta }_{i}$, and $I$ is the identity matrix.
The minimization of $F\left(\Psi \right)$ 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{\Psi }^{-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 ${\psi }_{i}$ are greater than a given small positive quantity, $\delta$, so that the communality is always less than $1$. This avoids the so called Heywood cases.
In addition to the values of $\Lambda$, $\Psi$ and the communalities, g03caf returns the residual correlations, i.e., the off-diagonal elements of $C-\left(\Lambda {\Lambda }^{\mathrm{T}}+\Psi \right)$ 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).

4References

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

5Arguments

1:     $\mathbf{matrix}$ – Character(1)Input
On entry: selects the type of matrix on which factor analysis is to be performed.
${\mathbf{matrix}}=\text{'D'}$
The data matrix will be input in x and factor analysis will be computed for the correlation matrix.
${\mathbf{matrix}}=\text{'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.
${\mathbf{matrix}}=\text{'C'}$
The correlation/variance-covariance matrix will be input in x and factor analysis computed for this matrix.
Constraint: ${\mathbf{matrix}}=\text{'D'}$, $\text{'S'}$ or $\text{'C'}$.
2:     $\mathbf{weight}$ – Character(1)Input
On entry: if ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$, weight indicates if weights are to be used.
${\mathbf{weight}}=\text{'U'}$
No weights are used.
${\mathbf{weight}}=\text{'W'}$
Weights are used and must be supplied in wt.
Note:  if ${\mathbf{matrix}}=\text{'C'}$, weight is not referenced.
Constraint: if ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$, ${\mathbf{weight}}=\text{'U'}$ or $\text{'W'}$.
3:     $\mathbf{n}$ – IntegerInput
On entry: if ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$ the number of observations in the data array x.
If ${\mathbf{matrix}}=\text{'C'}$ the (effective) number of observations used in computing the (possibly weighted) correlation/variance-covariance matrix input in x.
Constraint: ${\mathbf{n}}>{\mathbf{nvar}}$.
4:     $\mathbf{m}$ – IntegerInput
On entry: the number of variables in the data/correlation/variance-covariance matrix.
Constraint: ${\mathbf{m}}\ge {\mathbf{nvar}}$.
5:     $\mathbf{x}\left({\mathbf{ldx}},{\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the input matrix.
If ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$, x must contain the data matrix, i.e., ${\mathbf{x}}\left(\mathit{i},\mathit{j}\right)$ must contain the $\mathit{i}$th observation for the $\mathit{j}$th variable, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,{\mathbf{m}}$.
If ${\mathbf{matrix}}=\text{'C'}$, x must contain the correlation or variance-covariance matrix. Only the upper triangular part is required.
6:     $\mathbf{ldx}$ – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which g03caf is called.
Constraints:
• if ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$, ${\mathbf{ldx}}\ge {\mathbf{n}}$;
• if ${\mathbf{matrix}}=\text{'C'}$, ${\mathbf{ldx}}\ge {\mathbf{m}}$.
7:     $\mathbf{nvar}$ – IntegerInput
On entry: $p$, the number of variables in the factor analysis.
Constraint: ${\mathbf{nvar}}\ge 2$.
8:     $\mathbf{isx}\left({\mathbf{m}}\right)$ – Integer arrayInput
On entry: ${\mathbf{isx}}\left(\mathit{j}\right)$ indicates whether or not the $\mathit{j}$th variable is included in the factor analysis. If ${\mathbf{isx}}\left(\mathit{j}\right)\ge 1$, the variable represented by the $\mathit{j}$th column of x is included in the analysis; otherwise it is excluded, for $\mathit{j}=1,2,\dots ,{\mathbf{m}}$.
Constraint: ${\mathbf{isx}}\left(j\right)>0$ for nvar values of $j$.
9:     $\mathbf{nfac}$ – IntegerInput
On entry: $k$, the number of factors.
Constraint: $1\le {\mathbf{nfac}}\le {\mathbf{nvar}}$.
10:   $\mathbf{wt}\left(*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array wt must be at least ${\mathbf{n}}$ if ${\mathbf{weight}}=\text{'W'}$ and ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{weight}}=\text{'W'}$ and ${\mathbf{matrix}}=\text{'D'}$ or $\text{'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 ${\mathbf{wt}}\left(i\right)=0.0$, the $i$th observation is not included in the analysis.
If ${\mathbf{weight}}=\text{'U'}$ or ${\mathbf{matrix}}=\text{'C'}$, wt is not referenced and the effective number of observations is $n$.
Constraint: if ${\mathbf{weight}}=\text{'W'}$, $\text{the sum of weights}>{\mathbf{nvar}}$, ${\mathbf{wt}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,n$.
11:   $\mathbf{e}\left({\mathbf{nvar}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the eigenvalues ${\theta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$.
12:   $\mathbf{stat}\left(4\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the test statistics.
${\mathbf{stat}}\left(1\right)$
Contains the value $F\left(\stackrel{^}{\Psi }\right)$.
${\mathbf{stat}}\left(2\right)$
Contains the test statistic, ${\chi }^{2}$.
${\mathbf{stat}}\left(3\right)$
Contains the degrees of freedom associated with the test statistic.
${\mathbf{stat}}\left(4\right)$
Contains the significance level.
13:   $\mathbf{com}\left({\mathbf{nvar}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the communalities.
14:   $\mathbf{psi}\left({\mathbf{nvar}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the estimates of ${\psi }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$.
15:   $\mathbf{res}\left({\mathbf{nvar}}×\left({\mathbf{nvar}}-1\right)/2\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the residual correlations. The residual correlation for the $i$th and $j$th variables is stored in ${\mathbf{res}}\left(\left(j-1\right)\left(j-2\right)/2+i\right)$, $i.
16:   $\mathbf{fl}\left({\mathbf{ldfl}},{\mathbf{nfac}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the factor loadings. ${\mathbf{fl}}\left(\mathit{i},\mathit{j}\right)$ contains ${\lambda }_{\mathit{i}\mathit{j}}$, for $\mathit{i}=1,2,\dots ,p$ and $\mathit{j}=1,2,\dots ,k$.
17:   $\mathbf{ldfl}$ – IntegerInput
On entry: the first dimension of the array fl as declared in the (sub)program from which g03caf is called.
Constraint: ${\mathbf{ldfl}}\ge {\mathbf{nvar}}$.
18:   $\mathbf{iop}\left(5\right)$ – Integer arrayInput
On entry: options for the optimization. There are four options to be set:
 $\mathit{iprint}$ controls iteration monitoring; if $\mathit{iprint}\le 0$, there is no printing of information else if $\mathit{iprint}>0$, information is printed at every iprint iterations. The information printed consists of the value of $F\left(\Psi \right)$ at that iteration, the number of evaluations of $F\left(\Psi \right)$, the current estimates of the communalities and an indication of whether or not they are at the boundary. $\mathit{maxfun}$ the maximum number of function evaluations. $\mathit{acc}$ the required accuracy for the estimates of ${\psi }_{i}$. $\mathit{eps}$ a lower bound for the values of $\psi$, see Section 3.
Let  then if ${\mathbf{iop}}\left(1\right)=0$, the following default values are used:
• $\mathit{iprint}=-1$
• $\mathit{maxfun}=100p$
• $\mathit{acc}=10\sqrt{\epsilon }$
• $\mathit{eps}=\epsilon$
If ${\mathbf{iop}}\left(1\right)\ne 0$, then
• $\mathit{iprint}={\mathbf{iop}}\left(2\right)$
• $\mathit{maxfun}={\mathbf{iop}}\left(3\right)$
• $\mathit{acc}={10}^{-l}$ where $l={\mathbf{iop}}\left(4\right)$
• $\mathit{eps}={10}^{-l}$ where $l={\mathbf{iop}}\left(5\right)$
Constraint: if ${\mathbf{iop}}\left(1\right)\ne 0$, ${\mathbf{iop}}\left(\mathit{i}\right)$ must be such that $\mathit{maxfun}\ge 1$, $\epsilon \le \mathit{acc}<1$ and $\epsilon \le \mathit{eps}<1$, for $\mathit{i}=3,4,5$.
19:   $\mathbf{iwk}\left(4×{\mathbf{nvar}}+2\right)$ – Integer arrayWorkspace
20:   $\mathbf{wk}\left({\mathbf{lwk}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
21:   $\mathbf{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 ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$, ${\mathbf{lwk}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left(5×{\mathbf{nvar}}×{\mathbf{nvar}}+33×{\mathbf{nvar}}-4\right)/2,{\mathbf{n}}×{\mathbf{nvar}}+7×{\mathbf{nvar}}+{\mathbf{nvar}}×\left({\mathbf{nvar}}-1\right)/2\right)$;
• if ${\mathbf{matrix}}=\text{'C'}$, ${\mathbf{lwk}}\ge \left(5×{\mathbf{nvar}}×{\mathbf{nvar}}+33×{\mathbf{nvar}}-4\right)/2$.
22:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . 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  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 ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value  is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{iop}}\left(1\right)\ne 1$ and ${\mathbf{iop}}\left(3\right)=〈\mathit{\text{value}}〉$.
Constraint: $\mathit{maxfun}\ge 1$.
On entry, ${\mathbf{iop}}\left(1\right)\ne 1$ and ${\mathbf{iop}}\left(4\right)=〈\mathit{\text{value}}〉$.
Constraint: .
On entry, ${\mathbf{iop}}\left(1\right)\ne 1$ and ${\mathbf{iop}}\left(5\right)=〈\mathit{\text{value}}〉$.
Constraint: .
On entry, ${\mathbf{ldfl}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nvar}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldfl}}\ge {\mathbf{nvar}}$.
On entry, ${\mathbf{ldx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldx}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{ldx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldx}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{lwk}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lwk}}\ge 〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nvar}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge {\mathbf{nvar}}$.
On entry, ${\mathbf{matrix}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{matrix}}=\text{'D'}$, $\text{'S'}$ or $\text{'C'}$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nvar}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>{\mathbf{nvar}}$.
On entry, ${\mathbf{nfac}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nfac}}\ge 1$.
On entry, ${\mathbf{nfac}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nvar}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nfac}}\le {\mathbf{nvar}}$.
On entry, ${\mathbf{nvar}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nvar}}>1$.
On entry, ${\mathbf{weight}}=〈\mathit{\text{value}}〉$.
Constraint: when ${\mathbf{matrix}}=\text{'D'}$ or $\text{'S'}$, ${\mathbf{weight}}=\text{'U'}$ or $\text{'W'}$.
${\mathbf{ifail}}=2$
On entry, $i=〈\mathit{\text{value}}〉$ and ${\mathbf{wt}}\left(i\right)<0.0$.
Constraint: ${\mathbf{wt}}\left(i\right)\ge 0.0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{nvar}}=〈\mathit{\text{value}}〉$ and $〈\mathit{\text{value}}〉$ values of ${\mathbf{isx}}>0$
Constraint: exactly nvar elements of ${\mathbf{isx}}>0$.
The effective number of observations $\text{}\le 1$.
The number of variables $\text{}\ge \text{}$ number of included observations.
${\mathbf{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.
${\mathbf{ifail}}=5$
The singular value decomposition has failed to converge. This is an unlikely error exit.
${\mathbf{ifail}}=6$
The estimation procedure has failed to converge in $〈\mathit{\text{value}}〉$ iterations. Change iop to either increase the number of iterations $\mathit{maxfun}$ or increase the value of $\mathit{acc}$.
${\mathbf{ifail}}=7$
The convergence is not certain but a lower point could not be found. All results are computed.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7Accuracy

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

8Parallelism 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.

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 ${\psi }_{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.

10Example

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.1Program Text

Program Text (g03cafe.f90)

10.2Program Data

Program Data (g03cafe.d)

10.3Program Results

Program Results (g03cafe.r)