From 8a6eb419b4934d0c204ae801dcbff598f1d77ab5 Mon Sep 17 00:00:00 2001 From: jbiggsets Date: Mon, 17 May 2021 08:58:42 -0400 Subject: [PATCH] fix minor issue with signs in varimax rotation --- factor_analyzer/rotator.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/factor_analyzer/rotator.py b/factor_analyzer/rotator.py index e3fba72..847e02d 100644 --- a/factor_analyzer/rotator.py +++ b/factor_analyzer/rotator.py @@ -503,9 +503,10 @@ def _varimax(self, loadings): # and rotation matrix basis = np.dot(X, rotation_mtx) - # transform data for singular value decomposition - transformed = np.dot(X.T, basis**3 - (1.0 / n_rows) * - np.dot(basis, np.diag(np.diag(np.dot(basis.T, basis))))) + # transform data for singular value decomposition using updated formula : + # B <- t(x) %*% (z^3 - z %*% diag(drop(rep(1, p) %*% z^2))/p) + diagonal = np.diag(np.squeeze(np.repeat(1, n_rows).dot(basis**2))) + transformed = X.T.dot(basis**3 - basis.dot(diagonal) / n_rows) # perform SVD on # the transformed matrix @@ -516,7 +517,7 @@ def _varimax(self, loadings): d = np.sum(S) # check convergence - if old_d != 0 and d / old_d < 1 + self.tol: + if d < old_d * (1 + self.tol): break # take inner product of loading matrix