# NOT RUN {
library(parameters)
# }
# NOT RUN {
# Principal Component Analysis (PCA) -------------------
if (require("psych")) {
principal_components(mtcars[, 1:7], n = "all", threshold = 0.2)
principal_components(mtcars[, 1:7],
n = 2, rotation = "oblimin",
threshold = "max", sort = TRUE
)
principal_components(mtcars[, 1:7], n = 2, threshold = 2, sort = TRUE)
pca <- principal_components(mtcars[, 1:5], n = 2, rotation = "varimax")
pca # Print loadings
summary(pca) # Print information about the factors
predict(pca, names = c("Component1", "Component2")) # Back-predict scores
# which variables from the original data belong to which extracted component?
closest_component(pca)
# rotated_data(pca) # TODO: doesn't work
}
# Automated number of components
principal_components(mtcars[, 1:4], n = "auto")
# }
# NOT RUN {
# Factor Analysis (FA) ------------------------
if (require("psych")) {
factor_analysis(mtcars[, 1:7], n = "all", threshold = 0.2)
factor_analysis(mtcars[, 1:7], n = 2, rotation = "oblimin", threshold = "max", sort = TRUE)
factor_analysis(mtcars[, 1:7], n = 2, threshold = 2, sort = TRUE)
efa <- factor_analysis(mtcars[, 1:5], n = 2)
summary(efa)
predict(efa)
# }
# NOT RUN {
# Automated number of components
factor_analysis(mtcars[, 1:4], n = "auto")
# }
# NOT RUN {
}
# }
Run the code above in your browser using DataLab