reorder_fa {lazy.tools}R Documentation

Reorder the rows and columns of factor pattern matrix

Description

Reorder the rows and columns of factor pattern matrix

Usage

reorder_fa(A, unclass = 0, sortcols = 1, print = 0)

Arguments

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

Details

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.

Value

A list of
loadings = reordered loadings matrix
row_order = sort order of the rows
col_order = sort order of the cols

Examples

set.seed(1701)
n <- 20; ndim <- 4
A0 <- matrix(runif(n*ndim),n,ndim)
dimnames(A0)=list( paste("v",1:n,sep=""),paste("f",1:ndim,sep=""))
A0v <- varimax(A0)$loadings
A0v <- A0v*matrix(sample(c(-1,1,1),n*ndim,replace=TRUE),n,ndim)
A0v[,3:4] <- -A0v[,3:4]

resrc <- reorder_fa(A0v)
A0vrc <- resrc$loadings
Print(A0v,A0vrc, fmt="6.3", fuzz=0.7)

resr <- reorder_fa(A0v, sortcols=0)
A0vr <- resr$loadings
Print(A0v,A0vr, fmt="6.3", fuzz=0.7)

# reordered matrix from original
dif1 <- A0vrc-A0v[resrc$row_order,resrc$col_order]

# original from reordered matrix
A0v2 <- A0vrc; A0v2[resrc$row_order,resrc$col_order] <- A0vrc
rownames(A0v2)[resrc$row_order] <- rownames(A0vrc)
Print(A0v,A0v2, fmt="6.3")
dif2 <- A0v2-A0v
Print(dif1, dif2)

# reducing the number of negative signs
A0vrcs <- reflect_fa( A0vrc )$loadings
Print(A0vrc, A0vrcs, fmt="6.3")

# attributes
print(reorder_fa(A0v)$loadings)
print(reorder_fa(A0v, unclass=1)$loadings)


[Package lazy.tools version 0.1.4 ]