data("WansbeekMeijer", package = "GPArotation")
fa.unrotated <- factanal(factors = 2, covmat = NetherlandsTV, rotation = "none")
options(warn = -1)
# Orthogonal rotation
# Single start from random position
fa.lpT1 <- GPForth.lp(loadings(fa.unrotated), p = 1)
# 10 random starts
fa.lpT <- lpT(loadings(fa.unrotated), Tmat=Random.Start(2), p = 1, randomStarts = 10)
print(fa.lpT, digits = 5, sortLoadings = FALSE, Table = TRUE, rotateMat = TRUE)
p <- 1
# Oblique rotation
# Single start
fa.lpQ1 <- GPFoblq.lp(loadings(fa.unrotated), p = p)
# 10 random starts
fa.lpQ <- lpQ(loadings(fa.unrotated), p = p, randomStarts = 10)
summary(fa.lpQ, Structure = TRUE)
# this functions ensures consistent ordering of factors of a
# GPArotation object for cleaner comparison
# Inspired by fungible::orderFactors and fungible::faSort functions
sortFac <- function(x){
# Only works for object of class GPArotation
if (!inherits(x, "GPArotation")) {stop("argument not of class GPArotation")}
cln <- colnames(x$loadings)
# ordering for oblique slightly different from orthogonal
ifelse(x$orthogonal, vx <- colSums(x$loadings^2),
vx <- diag(x$Phi %*% t(x$loadings) %*% x$loadings) )
# sort by squared loadings from high to low
vxo <- order(vx, decreasing = TRUE)
vx <- vx[vxo]
# maintain the right sign
Dsgn <- diag(sign(colSums(x$loadings^3))) [ , vxo]
x$Th <- x$Th %*% Dsgn
x$loadings <- x$loadings %*% Dsgn
if (match("Phi", names(x))) {
# If factor is negative, reverse corresponding factor correlations
x$Phi <- t(Dsgn) %*% x$Phi %*% Dsgn
}
colnames(x$loadings) <- cln
x
}
# seed set to see the results of sorting
set.seed(1020)
fa.lpQ1 <- lpQ(loadings(fa.unrotated),p=1,randomStarts=10)
fa.lpQ0.5 <- lpQ(loadings(fa.unrotated),p=0.5,randomStarts=10)
fa.geo <- geominQ(loadings(fa.unrotated), randomStarts=10)
# with ordered factor loadings
res <- round(cbind(sortFac(fa.lpQ1)$loadings, sortFac(fa.lpQ0.5)$loadings,
sortFac(fa.geo)$loadings),3)
print(c("oblique- Lp 1 Lp 0.5 geomin")); print(res)
# without ordered factor loadings
res <- round(cbind(fa.lpQ1$loadings, fa.lpQ0.5$loadings, fa.geo$loadings),3)
print(c("oblique- Lp 1 Lp 0.5 geomin")); print(res)
options(warn = 0)
Run the code above in your browser using DataLab