Cargamos los datos y la librería
library(haven)
EH_6_variables_simple <- read_sav("EH_6_variables_simple.sav")
data <- EH_6_variables_simple
library(psych)
## Warning: package 'psych' was built under R version 4.2.3
Aplicamos la función policórica y creamos un objeto “Matriz” con los coeficientes
r <- polychoric(data)
Matriz <- r$rho
Matriz
## P1 P2 P3 P4 P5 P6
## P1 1.0000000 0.7549263 0.7258645 0.6722924 0.6619933 0.5607432
## P2 0.7549263 1.0000000 0.7851290 0.7235942 0.7015590 0.5789710
## P3 0.7258645 0.7851290 1.0000000 0.7406075 0.7192314 0.6010792
## P4 0.6722924 0.7235942 0.7406075 1.0000000 0.6880473 0.6109166
## P5 0.6619933 0.7015590 0.7192314 0.6880473 1.0000000 0.6651198
## P6 0.5607432 0.5789710 0.6010792 0.6109166 0.6651198 1.0000000
Calculamos KMO y test de esfericidad de Barlett
KMO(Matriz)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = Matriz)
## Overall MSA = 0.92
## MSA for each item =
## P1 P2 P3 P4 P5 P6
## 0.93 0.90 0.91 0.93 0.92 0.93
cortest.bartlett(Matriz)
## Warning in cortest.bartlett(Matriz): n not specified, 100 used
## $chisq
## [1] 430.2472
##
## $p.value
## [1] 2.996447e-82
##
## $df
## [1] 15
Calculamos autovalores
autovalores <- eigen(Matriz)
round(autovalores$values,2)
## [1] 4.41 0.51 0.32 0.30 0.25 0.21
Modelamos nuestro ACP exploratorio diciéndole que extraiga un factor con método de rotación varimax
Modelo <- pca(Matriz, nfactors = 1, rotate = "varimax")
Observamos las cargas factoriales
print(Modelo$loadings, digits = 2)
##
## Loadings:
## PC1
## P1 0.85
## P2 0.89
## P3 0.89
## P4 0.86
## P5 0.86
## P6 0.77
##
## PC1
## SS loadings 4.41
## Proportion Var 0.73
Observamos las comunalidades:
print(Modelo$communality, digits = 2)
## P1 P2 P3 P4 P5 P6
## 0.73 0.79 0.80 0.75 0.75 0.60
Calculamos las puntuaciones factoriales, le decimos la BDD sobre la que calcula las puntuaciones para cada caso y el modelo factorial entrenado.
Puntuaciones <- factor.scores(data, Modelo)
Por último, hacemos el merge de las puntuaciones factoriales calculadas con la BDD orignal
Puntuaciones.factoriales <- Puntuaciones$scores
EH_6_variables_Con_Puntuaciones <- cbind(data,Puntuaciones.factoriales)
EH_6_variables_Con_Puntuaciones$Puntuaciones_Policoricas <- EH_6_variables_Con_Puntuaciones$PC1
head(EH_6_variables_Con_Puntuaciones)
## P1 P2 P3 P4 P5 P6 PC1 Puntuaciones_Policoricas
## 1 3 4 4 4 3 3 0.5207624 0.5207624
## 2 3 4 5 5 3 3 0.8820585 0.8820585
## 3 3 4 4 4 3 5 0.8698348 0.8698348
## 4 2 2 4 1 3 3 -0.5629253 -0.5629253
## 5 2 1 1 1 3 4 -1.1122924 -1.1122924
## 6 2 2 2 2 3 3 -0.7471734 -0.7471734
Le pedimos un summary de checkeo final
summary(EH_6_variables_Con_Puntuaciones)
## P1 P2 P3 P4
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:2.000
## Median :3.000 Median :3.000 Median :3.000 Median :3.000
## Mean :2.757 Mean :2.972 Mean :3.034 Mean :3.022
## 3rd Qu.:3.000 3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:4.000
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
## P5 P6 PC1 Puntuaciones_Policoricas
## Min. :1.000 Min. :1.000 Min. :-2.20426 Min. :-2.20426
## 1st Qu.:2.000 1st Qu.:3.000 1st Qu.:-0.57574 1st Qu.:-0.57574
## Median :3.000 Median :3.000 Median :-0.01889 Median :-0.01889
## Mean :3.135 Mean :3.194 Mean : 0.00000 Mean : 0.00000
## 3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.: 0.53965 3rd Qu.: 0.53965
## Max. :5.000 Max. :5.000 Max. : 2.16647 Max. : 2.16647
Y ya estaría.