% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reorder_fa.R
\name{reorder_fa}
\alias{reorder_fa}
\title{Reorder the rows and columns of factor pattern matrix}
\usage{
reorder_fa(A, unclass = 0, sortcols = 1, print = 0)
}
\arguments{
\item{A}{Factor Pattern matrix or an object with $loadings.}

\item{unclass}{= 1 to unclass the result}

\item{sortcols}{= 0 not to sort factors (columns of A) according to
factor contributions.}

\item{print}{= 1 to print the result}
}
\value{
A list of \cr
loadings = reordered loadings matrix \cr
row_order = sort order of the rows \cr
col_order = sort order of the cols
}
\description{
Reorder the rows and columns of factor pattern matrix
}
\details{
First, if sortcols == 1, the columns of \code{A} are reordered
according to the magnitude of \code{diag(t(A)\%*\%A)}. \cr
Then, for each row, the column number of the maximum elements of
\code{abs(A)}
is recorded (as \code{max.col(abs(A))}) and the rows of \code{A}
are sorted according
to these column numbers. \cr
Finally, within each max.col group, the rows are again sorted
according to the magnitude of \code{A}.
}
\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)

}
