EM algorithm for improving factors found with during factor analysis. For a demonstration of how the function works, see demo.pdf
- R 4.0.5
- the openblas package
Given a matrix of observations, a matrix of factor loadings, and a diagonal matrix of the variance of the errors, the generic function em iteratively computes a new factor loadings and variance of errors until they converge with the previous terms.
em returns a list of the new factor loadings, variance of errors, and the score of the new factor loadings.
em(Z,L,psi,tol,maxite)
| Arguments | Description |
|---|---|
Z |
a normalized numeric data matrix or data frame that provided the data for factor analysis |
L |
a numeric data matrix of factor loadings |
psi |
a diagonal numeric data matrix of the variance of the errror term, ε |
tol |
maximum error between the new and old L and Ψ. Recommended value: 10^-5 |
maxite |
maximum iterations before function quits. Recommended value: 1000 |
em uses cov to determine the correlation matrix of Z, solve to invert matrices, and diag to obtain a new Ψ.
em returns a generic list containing the following components:
| Values | Description |
|---|---|
L_new |
a numeric data matrix of improved factor loadings |
psi_new |
a diagonal numeric data matrix of the new variance of the error term |
scores |
a numeric data matrix of the scores calculated with the regression method, using L_new |
You can use the priciple component method to calculate L.
Given an nxp matrix of observations, X, L would be a pxk matrix where k ≤ 0.5p.
k is determined by plotting a scree diagram of the variance of each component against the number of components in the model. A smaller k is preferred.
L is then a matrix of the vectors
for j=1,...,k, where
is an eigenvalue and its corresponding eigenvector of the correlation matrix R. Note that the eigenvalue-eigenvector pair are arranged from largest to smallest eigenvalue.
psi is then calculated with
, for i=1,...,p,
where the non-diagonal entries are zero.
- H. Peng, EM algorithm for factor models, 2021, https://www.math.hkbu.edu.hk/~hpeng/Math3806/EM-factor.html (accessed 2021/05/14).
- R. A. Johnson, D. W. Wichern, Applied Multivariate Statistical Analysis, Pearson Prentice Hall, Upper Saddle River, New Jersey, 2007.