Skip to content

Commit 83ec80e

Browse files
authored
Merge pull request #79 from EducationalTestingService/bugfix/varimax-rotation
Fix minor issue with signs in varimax rotation matrix
2 parents 289450b + 8a6eb41 commit 83ec80e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

factor_analyzer/rotator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,10 @@ def _varimax(self, loadings):
503503
# and rotation matrix
504504
basis = np.dot(X, rotation_mtx)
505505

506-
# transform data for singular value decomposition
507-
transformed = np.dot(X.T, basis**3 - (1.0 / n_rows) *
508-
np.dot(basis, np.diag(np.diag(np.dot(basis.T, basis)))))
506+
# transform data for singular value decomposition using updated formula :
507+
# B <- t(x) %*% (z^3 - z %*% diag(drop(rep(1, p) %*% z^2))/p)
508+
diagonal = np.diag(np.squeeze(np.repeat(1, n_rows).dot(basis**2)))
509+
transformed = X.T.dot(basis**3 - basis.dot(diagonal) / n_rows)
509510

510511
# perform SVD on
511512
# the transformed matrix
@@ -516,7 +517,7 @@ def _varimax(self, loadings):
516517
d = np.sum(S)
517518

518519
# check convergence
519-
if old_d != 0 and d / old_d < 1 + self.tol:
520+
if d < old_d * (1 + self.tol):
520521
break
521522

522523
# take inner product of loading matrix

0 commit comments

Comments
 (0)