# \donttest{
library(parameters)
if (require("psych", quietly = TRUE)) {
# Principal Component Analysis (PCA) ---------
pca <- psych::principal(attitude)
model_parameters(pca)
pca <- psych::principal(attitude, nfactors = 3, rotate = "none")
model_parameters(pca, sort = TRUE, threshold = 0.2)
principal_components(attitude, n = 3, sort = TRUE, threshold = 0.2)
# Exploratory Factor Analysis (EFA) ---------
efa <- psych::fa(attitude, nfactors = 3)
model_parameters(efa, threshold = "max", sort = TRUE, labels = as.character(1:ncol(attitude)))
# Omega ---------
omega <- psych::omega(mtcars, nfactors = 3)
params <- model_parameters(omega)
params
summary(params)
}
# FactoMineR ---------
if (require("FactoMineR", quietly = TRUE)) {
model <- FactoMineR::PCA(iris[, 1:4], ncp = 2)
model_parameters(model)
attributes(model_parameters(model))$scores
model <- FactoMineR::FAMD(iris, ncp = 2)
model_parameters(model)
}
# }
# lavaan
library(parameters)
# lavaan -------------------------------------
if (require("lavaan", quietly = TRUE)) {
# Confirmatory Factor Analysis (CFA) ---------
structure <- " visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 "
model <- lavaan::cfa(structure, data = HolzingerSwineford1939)
model_parameters(model)
model_parameters(model, standardize = TRUE)
# filter parameters
model_parameters(
model,
parameters = list(
To = "^(?!visual)",
From = "^(?!(x7|x8))"
)
)
# Structural Equation Model (SEM) ------------
structure <- "
# latent variable definitions
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + a*y2 + b*y3 + c*y4
dem65 =~ y5 + a*y6 + b*y7 + c*y8
# regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
# residual correlations
y1 ~~ y5
y2 ~~ y4 + y6
y3 ~~ y7
y4 ~~ y8
y6 ~~ y8
"
model <- lavaan::sem(structure, data = PoliticalDemocracy)
model_parameters(model)
model_parameters(model, standardize = TRUE)
}
Run the code above in your browser using DataLab