Skip to content

Commit

Permalink
Merge pull request #79 from EducationalTestingService/bugfix/varimax-…
Browse files Browse the repository at this point in the history
…rotation

Fix minor issue with signs in varimax rotation matrix
  • Loading branch information
desilinguist authored May 20, 2021
2 parents 289450b + 8a6eb41 commit 83ec80e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions factor_analyzer/rotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 83ec80e

Please sign in to comment.