f <- factanal(x,4,covmat=Harman74.cor$cov)
factor2cluster(f)
# Factor1 Factor2 Factor3 Factor4
#VisualPerception 0 1 0 0
#Cubes 0 1 0 0
#PaperFormBoard 0 1 0 0
#Flags 0 1 0 0
#GeneralInformation 1 0 0 0
#PargraphComprehension 1 0 0 0
#SentenceCompletion 1 0 0 0
#WordClassification 1 0 0 0
#WordMeaning 1 0 0 0
#Addition 0 0 1 0
#Code 0 0 1 0
#CountingDots 0 0 1 0
#StraightCurvedCapitals 0 0 1 0
#WordRecognition 0 0 0 1
#NumberRecognition 0 0 0 1
#FigureRecognition 0 0 0 1
#ObjectNumber 0 0 0 1
#NumberFigure 0 0 0 1
#FigureWord 0 0 0 1
#Deduction 0 1 0 0
#NumericalPuzzles 0 0 1 0
#ProblemReasoning 0 1 0 0
#SeriesCompletion 0 1 0 0
#ArithmeticProblems 0 0 1 0
## The function is currently defined as
function (loads,loading=TRUE,cut=.0)
{
if (loading) {l <- loads$loadings
colnames(l) <- colnames(loads$loading) } else {
l <- loads
colnames(l) <- colnames(loads) }
l <- as.matrix(l)
nrows <- dim(l)[1]
ncols <- dim(l)[2]
if (ncols ==1) {m1 <- matrix(rep(1,nrows),ncol=1) } else {
m1 <- matrix(apply(t(apply(l, 1, abs)), 1, which.max),
ncol = 1)}
id <- matrix(c(1:nrows, m1), ncol = 2) #index row and column
factor2cluster <- matrix(rep(0, ncols * nrows), ncol = ncols)
factor2cluster[id] <- sign(l[id])*( (abs(l[id]) >cut)+0) #only loadings > cut
rownames(factor2cluster) <- rownames(l)
colnames(factor2cluster) <- colnames(l)
nitems <- colSums(abs(factor2cluster))
for (i in ncols:1) {if (nitems[i]<1) {factor2cluster <- factor2cluster[,-i]} }#remove columns with no variables
return(factor2cluster)
}
Run the code above in your browser using DataLab