Es necesario instalar la libreria PsyMetricTools desde github.
if (!require("devtools")) {
install.packages("devtools")
}
devtools::install_github("jventural/PsyMetricTools")
Instalar la libreria “pacman”
install.packages("pacman")
La biblioteca “pacman” es una herramienta que, al utilizar la función
p_load
, permite instalar automáticamente una biblioteca si
no está previamente instalada, y simplemente cargarla si ya está
presente en el entorno.
pacman::p_load(tidyverse,ggplot2,psych,PsyMetricTools,lavaan,readxl)
El conjunto de datos psych::bfi
(que contiene datos de
personalidad del Big Five Inventory) se carga y se convierte en un
tibble (as_tibble()
), luego se eliminan las filas que
contienen valores faltantes (na.omit()
), y finalmente se
eliminan las columnas de género, educación y edad
(select(-gender, -education, -age)
), quedando solo las
variables relacionadas con la personalidad.
# data
big5 <- psych::bfi %>%
as_tibble() %>%
na.omit() %>%
select(-gender, -education, -age)
Se genera un vector de nombres nuevos para las columnas llamado
nuevos_nombres
, utilizando la función paste0()
para concatenar el prefijo “bif” con los números del 1 al 25.
# Renombrar las columnas
nuevos_nombres <- paste0("bif", 1:25)
Se renombran las columnas del conjunto de datos big5
utilizando los nombres generados en el paso anterior
(nuevos_nombres
) mediante la función
rename_with()
, aplicada a todas las columnas
(everything()
), y se almacena el resultado en un nuevo
objeto llamado big5_new
.
# Aplicar los nuevos nombres a las columnas
big5_new <- big5 %>%
rename_with(~ nuevos_nombres, everything())
generate_modelos
, que crea un modelo con 5 factores y 25
ítems, utilizando como nombres de los ítems el prefijo “bif”. No se
excluyen ítems específicos (exclude_items = NULL
).modelos1 <- generate_modelos(n_factors = 5, n_items = 25, name_items = "bif", exclude_items = NULL)
specification_models
, utilizando los modelos generados
anteriormente (modelos1
), junto con el conjunto de datos
big5_new
y el estimador “WLSMV” (Weighted Least Squares
Mean and Variance adjusted).Specifications1 <- specification_models(modelos1, data = big5_new,
estimator = "WLSMV",
rotation = "oblimin", verbose = FALSE)
extract_fit_measures
y se almacenan en el objeto
Bondades_Original1
. Luego se imprimen estas bondades de
ajuste.Bondades_Original1 <- extract_fit_measures(Specifications1)
Bondades_Original1
## Modelos chisq.scaled df.scaled srmr wrmr cfi.scaled tli.scaled rmsea.scaled
## 1 f1 14835.629 275 0.141 6.617 0.518 0.474 0.154
## 2 f2 9749.132 251 0.097 4.454 0.686 0.624 0.130
## 3 f3 6794.863 228 0.074 3.271 0.783 0.714 0.114
## 4 f4 4144.169 206 0.051 2.265 0.870 0.810 0.092
## 5 f5 1685.623 185 0.029 1.287 0.950 0.919 0.060
lavCor
, aplicándola al quinto modelo especificado
en Specifications1[[5]]
. Se indica que las variables son
ordenadas (ordered = TRUE
) y se especifica que el tipo de
salida debe ser una matriz de correlaciones
(output = "cor"
). Esta matriz se almacena en
Matrix_Poly
y se imprime.Matrix_Poly <- lavCor(Specifications1[[5]], ordered = TRUE, output = "cor")
Matrix_Poly
## bif1 bif2 bif3 bif4 bif5 bif6 bif7 bif8 bif9 bif10
## bif1 1.000
## bif2 -0.413 1.000
## bif3 -0.327 0.562 1.000
## bif4 -0.175 0.402 0.430 1.000
## bif5 -0.239 0.446 0.574 0.366 1.000
## bif6 -0.011 0.115 0.130 0.100 0.165 1.000
## bif7 0.004 0.149 0.164 0.257 0.143 0.482 1.000
## bif8 -0.012 0.218 0.159 0.163 0.154 0.353 0.394 1.000
## bif9 0.124 -0.183 -0.164 -0.204 -0.162 -0.412 -0.438 -0.398 1.000
## bif10 0.035 -0.144 -0.183 -0.283 -0.198 -0.291 -0.332 -0.394 0.535 1.000
## bif11 0.131 -0.268 -0.252 -0.169 -0.273 -0.035 0.018 -0.011 0.116 0.077
## bif12 0.102 -0.285 -0.336 -0.229 -0.380 -0.119 -0.084 -0.095 0.244 0.291
## bif13 -0.065 0.290 0.443 0.234 0.475 0.162 0.190 0.118 -0.112 -0.191
## bif14 -0.087 0.333 0.433 0.375 0.540 0.155 0.141 0.116 -0.146 -0.234
## bif15 -0.024 0.321 0.304 0.186 0.301 0.297 0.298 0.246 -0.282 -0.280
## bif16 0.181 -0.106 -0.096 -0.110 -0.222 -0.076 -0.015 -0.086 0.236 0.224
## bif17 0.154 -0.053 -0.092 -0.154 -0.213 -0.033 0.009 -0.067 0.172 0.263
## bif18 0.100 -0.033 -0.053 -0.069 -0.151 -0.021 0.010 -0.083 0.225 0.256
## bif19 0.055 -0.113 -0.152 -0.185 -0.228 -0.100 -0.032 -0.135 0.310 0.382
## bif20 0.001 0.023 -0.056 -0.002 -0.091 -0.068 0.046 -0.042 0.245 0.215
## bif21 -0.017 0.137 0.179 0.053 0.182 0.224 0.196 0.111 -0.125 -0.107
## bif22 0.068 0.019 0.003 0.053 -0.013 -0.161 -0.074 -0.039 0.237 0.145
## bif23 -0.093 0.175 0.257 0.052 0.260 0.218 0.213 0.062 -0.099 -0.085
## bif24 -0.110 0.081 0.048 -0.073 0.014 0.110 0.054 0.015 0.085 0.165
## bif25 0.127 -0.101 -0.062 0.046 -0.059 -0.176 -0.098 -0.006 0.214 0.058
## bif11 bif12 bif13 bif14 bif15 bif16 bif17 bif18 bif19 bif20
## bif1
## bif2
## bif3
## bif4
## bif5
## bif6
## bif7
## bif8
## bif9
## bif10
## bif11 1.000
## bif12 0.512 1.000
## bif13 -0.358 -0.443 1.000
## bif14 -0.480 -0.583 0.475 1.000
## bif15 -0.338 -0.438 0.452 0.364 1.000
## bif16 0.013 0.184 -0.050 -0.158 0.048 1.000
## bif17 0.005 0.208 -0.056 -0.167 0.058 0.769 1.000
## bif18 0.052 0.204 -0.012 -0.147 -0.060 0.620 0.597 1.000
## bif19 0.255 0.386 -0.163 -0.343 -0.223 0.448 0.426 0.565 1.000
## bif20 0.050 0.285 -0.110 -0.123 -0.165 0.426 0.388 0.476 0.441 1.000
## bif21 -0.122 -0.188 0.379 0.158 0.346 -0.065 -0.048 -0.058 -0.059 -0.176
## bif22 0.066 0.097 -0.100 0.044 -0.115 0.154 0.137 0.121 0.091 0.224
## bif23 -0.235 -0.275 0.456 0.235 0.339 -0.042 -0.021 -0.031 -0.065 -0.110
## bif24 0.095 0.204 0.072 -0.121 -0.013 0.106 0.159 0.198 0.278 0.129
## bif25 0.095 0.091 -0.165 0.046 -0.148 0.115 0.016 0.052 0.028 0.165
## bif21 bif22 bif23 bif24 bif25
## bif1
## bif2
## bif3
## bif4
## bif5
## bif6
## bif7
## bif8
## bif9
## bif10
## bif11
## bif12
## bif13
## bif14
## bif15
## bif16
## bif17
## bif18
## bif19
## bif20
## bif21 1.000
## bif22 -0.284 1.000
## bif23 0.451 -0.353 1.000
## bif24 0.249 -0.116 0.239 1.000
## bif25 -0.319 0.381 -0.388 -0.253 1.000
Standardized_solutions
, utilizando el quinto modelo
exploratorio generado (Specifications1[[5]]
), se especifica
el nombre de los ítems como “bif” y se aplica un umbral
(apply_threshold = T
). Esta matriz se almacena en
result_df1
y se imprime.result_df1 <- Standardized_solutions(Specifications1[[5]], name_items = "bif", apply_threshold = T)
result_df1 %>% print(n = 25)
## # A tibble: 25 × 6
## Items f1 f2 f3 f4 f5
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 bif1 -0.482 0 0 0 0
## 2 bif2 0.685 0 0 0 0
## 3 bif3 0.705 0 0 0 0
## 4 bif4 0.476 0 0 0 0
## 5 bif5 0.566 0 0 0 0
## 6 bif6 0 0.592 0 0 0
## 7 bif7 0 0.693 0 0 0
## 8 bif8 0 0.606 0 0 0
## 9 bif9 0 -0.690 0 0 0
## 10 bif10 0 -0.608 0 0 0
## 11 bif11 0 0 0.594 0 0
## 12 bif12 0 0 0.713 0 0
## 13 bif13 0 0 -0.433 0 0.333
## 14 bif14 0.323 0 -0.628 0 0
## 15 bif15 0 0 -0.436 0 0
## 16 bif16 0 0 0 0.905 0
## 17 bif17 0 0 0 0.847 0
## 18 bif18 0 0 0 0.705 0
## 19 bif19 0 0 0.441 0.471 0
## 20 bif20 0 0 0 0.481 0
## 21 bif21 0 0 0 0 0.571
## 22 bif22 0 0 0 0 -0.522
## 23 bif23 0 0 0 0 0.669
## 24 bif24 0 0 0.366 0 0.447
## 25 bif25 0 0 0 0 -0.604
inner_join
) entre la matriz de
soluciones estandarizadas (result_df1
) y los datos leídos
del archivo Excel (BFI_items
). El resultado se almacena en
Patron1
y se imprime.BFI_items <- readxl::read_excel("BFI_items.xlsx")
Patron1 <- inner_join(result_df1, BFI_items)
## Joining with `by = join_by(Items)`
Patron1 %>% print(n = 25)
## # A tibble: 25 × 8
## Items f1 f2 f3 f4 f5 Fraseo Factores
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
## 1 bif1 -0.482 0 0 0 0 Am indifferent to the feeli… Affabil…
## 2 bif2 0.685 0 0 0 0 Inquire about others' well-… Affabil…
## 3 bif3 0.705 0 0 0 0 Know how to comfort others.… Affabil…
## 4 bif4 0.476 0 0 0 0 Love children. (q_1364) Affabil…
## 5 bif5 0.566 0 0 0 0 Make people feel at ease. (… Affabil…
## 6 bif6 0 0.592 0 0 0 Am exacting in my work. (q_… conscie…
## 7 bif7 0 0.693 0 0 0 Continue until everything i… conscie…
## 8 bif8 0 0.606 0 0 0 Do things according to a pl… conscie…
## 9 bif9 0 -0.690 0 0 0 Do things in a half-way man… conscie…
## 10 bif10 0 -0.608 0 0 0 Waste my time. (q_1949) conscie…
## 11 bif11 0 0 0.594 0 0 Don't talk a lot. (q_712) extrave…
## 12 bif12 0 0 0.713 0 0 Find it difficult to approa… extrave…
## 13 bif13 0 0 -0.433 0 0.333 Know how to captivate peopl… extrave…
## 14 bif14 0.323 0 -0.628 0 0 Make friends easily. (q_141… extrave…
## 15 bif15 0 0 -0.436 0 0 Take charge. (q_1768) extrave…
## 16 bif16 0 0 0 0.905 0 Get angry easily. (q_952) neuroti…
## 17 bif17 0 0 0 0.847 0 Get irritated easily. (q_97… neuroti…
## 18 bif18 0 0 0 0.705 0 Have frequent mood swings. … neuroti…
## 19 bif19 0 0 0.441 0.471 0 Often feel blue. (q_1479) neuroti…
## 20 bif20 0 0 0 0.481 0 Panic easily. (q_1505) neuroti…
## 21 bif21 0 0 0 0 0.571 Am full of ideas. (q_128) openness
## 22 bif22 0 0 0 0 -0.522 Avoid difficult reading mat… openness
## 23 bif23 0 0 0 0 0.669 Carry the conversation to a… openness
## 24 bif24 0 0 0.366 0 0.447 Spend time reflecting on th… openness
## 25 bif25 0 0 0 0 -0.604 Will not probe deeply into … openness
lavaan::inspect
. Se extraen las
correlaciones entre los factores utilizando what = "std"
y
se almacenan en InterFactor1
.InterFactor1 <- lavaan::inspect(Specifications1[[5]], what = "std")$psi
InterFactor1
## f1 f2 f3 f4 f5
## f1 1.000
## f2 0.195 1.000
## f3 -0.297 -0.256 1.000
## f4 -0.026 -0.187 0.211 1.000
## f5 0.187 0.200 -0.143 0.006 1.000
generate_modelos
, donde se crea un
modelo con 5 factores y 25 ítems, utilizando como nombres de los ítems
el prefijo “bif”, y se excluyen los ítems “bif14”, “bif13”, “bif19” y
“bif24”.modelos2 <- generate_modelos(n_factors = 5, n_items = 25, name_items = "bif",
exclude_items = c("bif14", "bif13", "bif19", "bif24"))
specification_models
, utilizando los modelos generados
anteriormente (modelos2
), junto con el conjunto de datos
big5_new
y el estimador “WLSMV”.Specifications2 <- specification_models(modelos2, data = big5_new,
estimator = "WLSMV",
rotation = "oblimin", verbose = FALSE)
extract_fit_measures
, y se almacenan
en el objeto Bondades_Original2
. Luego se imprimen estas
bondades de ajuste.Bondades_Original2 <- extract_fit_measures(Specifications2)
Bondades_Original2
## Modelos chisq.scaled df.scaled srmr wrmr cfi.scaled tli.scaled rmsea.scaled
## 1 f1 11337.826 189 0.143 6.536 0.522 0.469 0.162
## 2 f2 7070.709 169 0.098 4.389 0.704 0.632 0.135
## 3 f3 4677.530 150 0.071 3.112 0.806 0.728 0.116
## 4 f4 2250.923 132 0.043 1.874 0.909 0.855 0.085
## 5 f5 1040.903 115 0.028 1.169 0.960 0.928 0.060
lavCor
, aplicándola al quinto modelo especificado
en Specifications1[[5]]
. Se indica que las variables son
ordenadas (ordered = TRUE
) y se especifica que el tipo de
salida debe ser una matriz de correlaciones
(output = "cor"
). Esta matriz se almacena en
Matrix_Poly
y se imprime.Matrix_Poly <- lavCor(Specifications2[[5]], ordered = TRUE, output = "cor")
Matrix_Poly
## bif1 bif2 bif3 bif4 bif5 bif6 bif7 bif8 bif9 bif10
## bif1 1.000
## bif2 -0.413 1.000
## bif3 -0.327 0.562 1.000
## bif4 -0.175 0.402 0.430 1.000
## bif5 -0.239 0.446 0.574 0.366 1.000
## bif6 -0.011 0.115 0.130 0.100 0.165 1.000
## bif7 0.004 0.149 0.164 0.257 0.143 0.482 1.000
## bif8 -0.012 0.218 0.159 0.163 0.154 0.353 0.394 1.000
## bif9 0.124 -0.183 -0.164 -0.204 -0.162 -0.412 -0.438 -0.398 1.000
## bif10 0.035 -0.144 -0.183 -0.283 -0.198 -0.291 -0.332 -0.394 0.535 1.000
## bif11 0.131 -0.268 -0.252 -0.169 -0.273 -0.035 0.018 -0.011 0.116 0.077
## bif12 0.102 -0.285 -0.336 -0.229 -0.380 -0.119 -0.084 -0.095 0.244 0.291
## bif15 -0.024 0.321 0.304 0.186 0.301 0.297 0.298 0.246 -0.282 -0.280
## bif16 0.181 -0.106 -0.096 -0.110 -0.222 -0.076 -0.015 -0.086 0.236 0.224
## bif17 0.154 -0.053 -0.092 -0.154 -0.213 -0.033 0.009 -0.067 0.172 0.263
## bif18 0.100 -0.033 -0.053 -0.069 -0.151 -0.021 0.010 -0.083 0.225 0.256
## bif20 0.001 0.023 -0.056 -0.002 -0.091 -0.068 0.046 -0.042 0.245 0.215
## bif21 -0.017 0.137 0.179 0.053 0.182 0.224 0.196 0.111 -0.125 -0.107
## bif22 0.068 0.019 0.003 0.053 -0.013 -0.161 -0.074 -0.039 0.237 0.145
## bif23 -0.093 0.175 0.257 0.052 0.260 0.218 0.213 0.062 -0.099 -0.085
## bif25 0.127 -0.101 -0.062 0.046 -0.059 -0.176 -0.098 -0.006 0.214 0.058
## bif11 bif12 bif15 bif16 bif17 bif18 bif20 bif21 bif22 bif23
## bif1
## bif2
## bif3
## bif4
## bif5
## bif6
## bif7
## bif8
## bif9
## bif10
## bif11 1.000
## bif12 0.512 1.000
## bif15 -0.338 -0.438 1.000
## bif16 0.013 0.184 0.048 1.000
## bif17 0.005 0.208 0.058 0.769 1.000
## bif18 0.052 0.204 -0.060 0.620 0.597 1.000
## bif20 0.050 0.285 -0.165 0.426 0.388 0.476 1.000
## bif21 -0.122 -0.188 0.346 -0.065 -0.048 -0.058 -0.176 1.000
## bif22 0.066 0.097 -0.115 0.154 0.137 0.121 0.224 -0.284 1.000
## bif23 -0.235 -0.275 0.339 -0.042 -0.021 -0.031 -0.110 0.451 -0.353 1.000
## bif25 0.095 0.091 -0.148 0.115 0.016 0.052 0.165 -0.319 0.381 -0.388
## bif25
## bif1
## bif2
## bif3
## bif4
## bif5
## bif6
## bif7
## bif8
## bif9
## bif10
## bif11
## bif12
## bif15
## bif16
## bif17
## bif18
## bif20
## bif21
## bif22
## bif23
## bif25 1.000
Standardized_solutions
, utilizando el quinto
modelo reespecificado generado (Specifications2[[5]]
). Se
especifica el nombre de los ítems como “bif” y se aplica un umbral
(apply_threshold = T
). Esta matriz se almacena en
result_df2
y se imprime.result_df2 <- Standardized_solutions(Specifications2[[5]], name_items = "bif", apply_threshold = T)
result_df2 %>% print(n = 25)
## # A tibble: 21 × 6
## Items f1 f2 f3 f4 f5
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 bif1 -0.498 0 0 0 0
## 2 bif2 0.715 0 0 0 0
## 3 bif3 0.745 0 0 0 0
## 4 bif4 0.483 0 0 0 0
## 5 bif5 0.579 0 0 0 0
## 6 bif6 0 0.585 0 0 0
## 7 bif7 0 0.692 0 0 0
## 8 bif8 0 0.604 0 0 0
## 9 bif9 0 -0.662 0 0 0
## 10 bif10 0 -0.604 0 0 0
## 11 bif11 0 0 0.562 0 0
## 12 bif12 0 0 0.768 0 0
## 13 bif15 0 0 -0.434 0 0
## 14 bif16 0 0 0 0.895 0
## 15 bif17 0 0 0 0.851 0
## 16 bif18 0 0 0 0.690 0
## 17 bif20 0 0 0 0.471 0
## 18 bif21 0 0 0 0 0.535
## 19 bif22 0 0 0 0 -0.552
## 20 bif23 0 0 0 0 0.657
## 21 bif25 0 0 0 0 -0.617
inner_join
) entre la
nueva matriz de soluciones estandarizadas (result_df2
) y
los datos adicionales de los ítems del inventario Big Five Inventory
almacenados en BFI_items
. El resultado se almacena en
Patron2
y se imprime.Patron2 <- inner_join(result_df2, BFI_items)
## Joining with `by = join_by(Items)`
Patron2 %>% print(n = 25)
## # A tibble: 21 × 8
## Items f1 f2 f3 f4 f5 Fraseo Factores
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
## 1 bif1 -0.498 0 0 0 0 Am indifferent to the feeli… Affabil…
## 2 bif2 0.715 0 0 0 0 Inquire about others' well-… Affabil…
## 3 bif3 0.745 0 0 0 0 Know how to comfort others.… Affabil…
## 4 bif4 0.483 0 0 0 0 Love children. (q_1364) Affabil…
## 5 bif5 0.579 0 0 0 0 Make people feel at ease. (… Affabil…
## 6 bif6 0 0.585 0 0 0 Am exacting in my work. (q_… conscie…
## 7 bif7 0 0.692 0 0 0 Continue until everything i… conscie…
## 8 bif8 0 0.604 0 0 0 Do things according to a pl… conscie…
## 9 bif9 0 -0.662 0 0 0 Do things in a half-way man… conscie…
## 10 bif10 0 -0.604 0 0 0 Waste my time. (q_1949) conscie…
## 11 bif11 0 0 0.562 0 0 Don't talk a lot. (q_712) extrave…
## 12 bif12 0 0 0.768 0 0 Find it difficult to approa… extrave…
## 13 bif15 0 0 -0.434 0 0 Take charge. (q_1768) extrave…
## 14 bif16 0 0 0 0.895 0 Get angry easily. (q_952) neuroti…
## 15 bif17 0 0 0 0.851 0 Get irritated easily. (q_97… neuroti…
## 16 bif18 0 0 0 0.690 0 Have frequent mood swings. … neuroti…
## 17 bif20 0 0 0 0.471 0 Panic easily. (q_1505) neuroti…
## 18 bif21 0 0 0 0 0.535 Am full of ideas. (q_128) openness
## 19 bif22 0 0 0 0 -0.552 Avoid difficult reading mat… openness
## 20 bif23 0 0 0 0 0.657 Carry the conversation to a… openness
## 21 bif25 0 0 0 0 -0.617 Will not probe deeply into … openness
lavaan::inspect
. Se
extraen las correlaciones entre los factores utilizando
what = "std"
y se almacenan en
InterFactor2
.InterFactor2 <- lavaan::inspect(Specifications2[[5]], what = "std")$psi
InterFactor2
## f1 f2 f3 f4 f5
## f1 1.000
## f2 0.242 1.000
## f3 -0.341 -0.228 1.000
## f4 -0.078 -0.147 0.186 1.000
## f5 0.153 0.237 -0.249 -0.065 1.000
Ventura-León, J. (2024). PsyMetricTools [Software]. GitHub. https://github.com/jventural/PsyMetricTools