Not yet tested.
This project is to implement methods about factor analysis.
- Rotator
- Varimax rotation.
- Promax rotation.
- Factor extraction method
- Maximum-likelihood estimation.
See programme comments.
- Python 3.8 =<
- numpy
pip install numpy
This section describes the implementation of Varimax rotation. Given a matrix
Therefore, the relationship between
The objective is to find the rotation matrix
The gradient ascent method is employed to solve for
Note:
-
$\Lambda^3$ refers to each element of$\Lambda$ raised to the power of 3. It amplifies each loading in$\Lambda$ . -
$\text{diag}(\Lambda^T \Lambda)$ is the diagonal matrix obtained from the product of$\Lambda^T$ and$\Lambda$ , enhancing the diagonal elements of$\Lambda$ . -
$p$ represents the number of variables. The term$\frac{1}{p}$ scales down the components of$\Lambda \text{diag}(\Lambda^T \Lambda)$ . -
$\gamma$ acts as a scaling factor.
Next, decompose
Here,
The rotation matrix
In the context of Promax rotation, let's denote the Promax loadings as
The rotation matrix
The updating rule for
This equation adjusts the correlation matrix
The iteration continues until the difference between
The MLE approach in Factor Analysis aims to find the factor loadings (matrix
-
Standardization:
- Standardize the input data
$X$ by subtracting the mean of each variable.
- Standardize the input data
-
Initialization:
- Initialize the factor loadings matrix
$\Lambda$ with random values.$\Lambda$ has dimensions$p \times m$ , where$p$ is the number of variables and$m$ is the number of factors. - Initialize the unique variances vector
$\Psi$ with random values.$\Psi$ has length$p$ .
- Initialize the factor loadings matrix
-
Iteration:
-
E-step (Expectation step):
-
Compute the expected factor covariance matrix: factor_cov
$= \Lambda \Lambda^T + \text{diag}(\Psi)$ -
Calculate its inverse: factor_cov_inv
$=$ (factor_cov)$^{-1}$
-
-
M-step (Maximization step):
- Update factor loadings
$\Lambda$ :$\Lambda_{\text{new}} = S \Lambda \times$ factor_ cov_ inv , where$S$ is the sample covariance matrix of the observed data. - Update unique variances
$\Psi$ :$\Psi_{\text{new}} = \text{diag}(S) - \text{diag}(\Lambda_{\text{new}} \Lambda_{\text{new}}^T)$
- Update factor loadings
-
Check for convergence. The algorithm stops if the change in
$\Lambda$ and$\Psi$ is smaller than a pre-defined tolerance level.
-
-
Output:
- The factor loadings matrix
$\Lambda$ , which represents the relationship between observed variables and underlying latent factors. - The unique variances
$\Psi$ , which represent the variances in the observed variables not explained by the common factors. - Communalities, which represent the proportion of variance in each observed variable that is accounted for by the common factors.
- The factor loadings matrix
The MLE approach for Factor Analysis seeks the factor loadings and unique variances that best explain the observed covariance (or correlation) matrix of the input data.
.
├── README.md
├── sandbox
│ └── README.md
└── src
└── rotator.py