ABC6 <- ABC[,6:11]
## ordinal PCA
fitord <- princals(ABC6) ## ordinal PCA
fitord
summary(fitord)
plot(fitord, plot.type = "transplot")
plot(fitord, "loadplot", main = "Loadings Plot ABC Data") ## aspect ratio = 1
plot(fitord, "biplot", main = "Biplot ABC Data")
plot(fitord, "screeplot")
## linear restrictions (mimics standard PCA)
abc_knots <- knotsGifi(ABC6, "E") ## 0 interior knots
fitlin <- princals(ABC6, knots = abc_knots, ordinal = TRUE)
fitlin
fitlin$evals
plot(fitlin, plot.type = "transplot")
## compare with standard PCA
ABCnum <- makeNumeric(ABC6)
fitpca <- prcomp(ABCnum, scale = TRUE)
fitpca$sdev^2
## more complicated specifications
if (FALSE) {
data(epi.bfi, package = "psychTools")
epi6 <- epi.bfi[,1:6]
fitepi1 <- princals(epi6, knots = knotsGifi(epi6, "Q")) ## monotone splines (degree 2)
fitepi1
plot(fitepi1, "transplot")
## no interior knots vars 1 and 2; data knots vars 3 and 4; 5
## interior percentile knots var 5; no interior knots var 6)
knotList <- c(knotsGifi(epi6[,1:2], "E"),
knotsGifi(epi6[,3:4], "D"),
knotsGifi(epi6[,5], "Q", n = 5),
knotsGifi(epi6[,6], "E"))
knotList
ordvec <- c(TRUE, FALSE, TRUE, FALSE, FALSE, TRUE) ## ordinal restrictions
degvec <- c(3, -1, 2, 2, 3, 1) ## spline degrees (second variable nominal)
fitepi2 <- princals(epi6, knots = knotList, ordinal = ordvec, degrees = degvec)
fitepi2
plot(fitepi2, "transplot")
}
Run the code above in your browser using DataLab