statsmodels.multivariate.factor_rotation.rotate_factors#
- statsmodels.multivariate.factor_rotation.rotate_factors(A, method, *method_args, **algorithm_kwargs)[source]#
Subroutine for orthogonal and oblique rotation of the matrix \(A\)
For orthogonal rotations \(A\) is rotated to \(L\) according to
\[L = AT,\]where \(T\) is an orthogonal matrix. And, for oblique rotations \(A\) is rotated to \(L\) according to
\[L = A(T^*)^{-1},\]where \(T\) is a normal matrix.
- Parameters:
- A
ndarray non rotated factors
- method
str should be one of the methods listed below
- method_args
tuple additional arguments that should be provided with each method
- algorithm_kwargs
dict - algorithm{‘gpa’, ‘gpa_der_free’, ‘analytic’}, optional
should be one of:
‘gpa’: a numerical method
‘gpa_der_free’: a derivative free numerical method
‘analytic’ : an analytic method
Depending on the algorithm, there are algorithm specific keyword arguments. For the gpa and gpa_der_free, the following keyword arguments are available:
- max_triesint, optional
maximum number of iterations. The default is 501.
- tolfloat, optional
stop criterion, algorithm stops if Frobenius norm of gradient is smaller then tol
For analytic, the supported arguments depend on the method, see above.
See the lower level functions for more details.
- A
- Returns:
Notes
What follows is a list of available methods. Depending on the method additional argument are required and different algorithms are available. The algorithm_kwargs are additional keyword arguments passed to the selected algorithm (see the parameters section). Unless stated otherwise, only the gpa and gpa_der_free algorithm are available.
Below,
\(L\) is a \(p\times k\) matrix;
\(N\) is \(k\times k\) matrix with zeros on the diagonal and ones elsewhere;
\(M\) is \(p\times p\) matrix with zeros on the diagonal and ones elsewhere;
\(C\) is a \(p\times p\) matrix with elements equal to \(1/p\);
\((X,Y)=\operatorname{Tr}(X^*Y)\) is the Frobenius norm;
\(\circ\) is the element-wise product or Hadamard product.
- obliminorthogonal or oblique rotation that minimizes
- \[\phi(L) = \frac{1}{4}(L\circ L,(I-\gamma C)(L\circ L)N).\]
For orthogonal rotations:
\(\gamma=0\) corresponds to quartimax,
\(\gamma=\frac{1}{2}\) corresponds to biquartimax,
\(\gamma=1\) corresponds to varimax,
\(\gamma=\frac{1}{p}\) corresponds to equamax.
For oblique rotations:
\(\gamma=0\) corresponds to quartimin,
\(\gamma=\frac{1}{2}\) corresponds to biquartimin.
method_args:
- gammafloat
oblimin family parameter
- rotation_method{‘orthogonal’, ‘oblique’}
should be one of {orthogonal, oblique}
orthomax : orthogonal rotation that minimizes
\[\phi(L) = -\frac{1}{4}(L\circ L,(I-\gamma C)(L\circ L)),\]where \(0\leq\gamma\leq1\). The orthomax family is equivalent to the oblimin family (when restricted to orthogonal rotations). Furthermore,
\(\gamma=0\) corresponds to quartimax,
\(\gamma=\frac{1}{2}\) corresponds to biquartimax,
\(\gamma=1\) corresponds to varimax,
\(\gamma=\frac{1}{p}\) corresponds to equamax.
method_args:
- gammafloat
orthomax family parameter, between 0 and 1
CF : Crawford-Ferguson family for orthogonal and oblique rotation which minimizes:
\[\phi(L) =\frac{1-\kappa}{4} (L\circ L,(L\circ L)N) -\frac{1}{4}(L\circ L,M(L\circ L)),\]where \(0\leq\kappa\leq1\). For orthogonal rotations the oblimin (and orthomax) family of rotations is equivalent to the Crawford-Ferguson family. To be more precise:
\(\kappa=0\) corresponds to quartimax,
\(\kappa=\frac{1}{p}\) corresponds to varimax,
\(\kappa=\frac{k-1}{p+k-2}\) corresponds to parsimax,
\(\kappa=1\) corresponds to factor parsimony.
method_args:
- kappafloat
Crawford-Ferguson family parameter, between 0 and 1
- rotation_method{‘orthogonal’, ‘oblique’}
should be one of {orthogonal, oblique}
- quartimaxorthogonal rotation method
minimizes the orthomax objective with \(\gamma=0\)
- biquartimaxorthogonal rotation method
minimizes the orthomax objective with \(\gamma=\frac{1}{2}\)
- varimaxorthogonal rotation method
minimizes the orthomax objective with \(\gamma=1\)
- equamaxorthogonal rotation method
minimizes the orthomax objective with \(\gamma=\frac{1}{p}\)
- parsimaxorthogonal rotation method
minimizes the Crawford-Ferguson family objective with \(\kappa=\frac{k-1}{p+k-2}\)
- parsimonyorthogonal rotation method
minimizes the Crawford-Ferguson family objective with \(\kappa=1\)
- quartiminoblique rotation method that
minimizes the oblimin objective with \(\gamma=0\)
- biquartiminoblique rotation method that
minimizes the oblimin objective with \(\gamma=\frac{1}{2}\)
- targetorthogonal or oblique rotation that rotates towards a target
matrix \(H\) by minimizing the objective
\[\phi(L) =\frac{1}{2}\|L-H\|^2.\]method_args:
- Hndarray
target matrix
- rotation_method{‘orthogonal’, ‘oblique’}
should be one of {orthogonal, oblique}
For orthogonal rotations the algorithm can be set to analytic in which case the following keyword arguments are available:
- full_rankbool, optional
if set to true full rank is assumed
partial_target : orthogonal (default) or oblique rotation that partially rotates towards a target matrix \(H\) by minimizing the objective:
\[\phi(L) =\frac{1}{2}\|W\circ(L-H)\|^2.\]method_args:
- Hndarray
target matrix
- Wndarray, optional
matrix with weights, entries can either be one or zero. The default is a matrix of ones, i.e., equal weight for all entries.
Examples
>>> import numpy as np >>> A = np.random.randn(8,2) >>> L, T = rotate_factors(A,'varimax') >>> np.allclose(L,A.dot(T)) True >>> L, T = rotate_factors(A,'orthomax',0.5) >>> np.allclose(L,A.dot(T)) True >>> L, T = rotate_factors(A,'quartimin',0.5) >>> np.allclose(L,A.dot(np.linalg.inv(T.T))) True