#################################################################################### #This is a file with executable R code for chapter 18 of Natalia Levshina's (2015) #How to Do Linguistics with R. Amsterdam/Philadelphia: John Benjamins. #################################################################################### ###Section 18.2 ##Main text install.packages(c("psych", "FactoMineR")) library(Rling);library(psych); library(FactoMineR) data(reg_bnc) str(reg_bnc) rownames(reg_bnc) round(cor(reg_bnc[, -1]), 2) cortest.bartlett(reg_bnc[, -1]) reg.pca <- PCA(reg_bnc, quali.sup = 1, graph = FALSE) head(reg.pca$eig) barplot(reg.pca$eig[,2], names = 1:nrow(reg.pca$eig), xlab = "components", ylab = "Percentage of explained variance") plot(reg.pca, choix = "var", cex = 0.8) dimdesc(reg.pca) plot(reg.pca, axes = c(2,3), choix = "var", cex = 0.8) plot(reg.pca, cex = 0.8, col.ind = "grey", col.quali = "black") plot(reg.pca, axes = c(2, 3), cex = 0.8, col.ind = "grey", col.quali = "black") plotellipses(reg.pca, label = "quali") reg.fa <- factanal(reg_bnc[, -1], factors = 3) reg.fa reg.fa <- factanal(reg_bnc[, -1], factors = 3, scores = "Bartlett") plot(reg.fa$scores[, 2:3], type = "n") text(reg.fa$scores[, 2:3], rownames(reg_bnc), cex = 0.7)