reorder_fa {lazy.tools} | R Documentation |
Reorder the rows and columns of factor pattern matrix
reorder_fa(A, unclass = 0, sortcols = 1, print = 0)
A |
Factor Pattern matrix or an object with $loadings. |
unclass |
= 1 to unclass the result |
sortcols |
= 0 not to sort factors (columns of A) according to factor contributions. |
print |
= 1 to print the result |
First, if sortcols == 1, the columns of A are reordered
according to the magnitude of diag(t(A)%*%A)
.
Then, for each row, the column number of the maximum elements of abs(A)
is recorded (as max.col(abs(A))) and the rows of A are sorted according
to these column numbers.
Finally, within each max.col group, the rows are again sorted
according to the magnitude of A.
A list of
loadings = reordered loadings matrix
row_order = sort order of the rows
col_order = sort order of the cols
set.seed(1701) n <- 20; ndim <- 4 A0 <- matrix(runif(n*ndim),n,ndim) A0v <- varimax(A0)$loadings resr <- reorder_fa(A0v) A0vr <- resr$loadings Print(A0v,A0vr, fmt="6.3", fuzz=0.7) # reordered matrix from original dif1 <- A0vr-A0v[resr$row_order,resr$col_order] # original from reordered matrix A0v2 <- A0vr; A0v2[resr$row_order,resr$col_order] <- A0vr rownames(A0v2)[resr$row_order] <- rownames(A0vr) Print(A0v,A0v2, fmt="6.3") dif2 <- A0v2-A0v Print(dif1, dif2) # attributes print(A0vr) print(reorder_fa(A0v, unclass=1))