Practica de Analisis Factorial

library(haven)
library(ggplot2)
library(MVN)
library(psych)
library(nFactors)
datos = read_sav("Ciencias_Letras.sav")
par(mfrow = c(3, 2))

qqnorm(datos$CNa)
qqline(datos$CNa)

qqnorm(datos$Mat)
qqline(datos$Mat)

qqnorm(datos$Fra)
qqline(datos$Fra)

qqnorm(datos$Lat)
qqline(datos$Lat)

qqnorm(datos$Lit)
qqline(datos$Lit)

shapiro.test(datos$CNa)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$CNa
## W = 0.91452, p-value = 0.07777
shapiro.test(datos$Mat)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$Mat
## W = 0.94253, p-value = 0.2675
shapiro.test(datos$Fra)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$Fra
## W = 0.91746, p-value = 0.08855
shapiro.test(datos$Lat)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$Lat
## W = 0.92895, p-value = 0.1474
shapiro.test(datos$Lit)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$Lit
## W = 0.90352, p-value = 0.04803
fit.ml = fa(datos[, 2:6], nfactors = 2, fm = "ml", rotate = "none", n.obs = 220, scores = "regression")

print(fit.ml)
## Factor Analysis using method =  ml
## Call: fa(r = datos[, 2:6], nfactors = 2, n.obs = 220, rotate = "none", 
##     scores = "regression", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##       ML2  ML1   h2    u2 com
## CNa  0.42 0.67 0.62 0.378 1.7
## Mat -0.03 1.00 1.00 0.005 1.0
## Fra  0.97 0.13 0.96 0.040 1.0
## Lat  0.80 0.25 0.71 0.291 1.2
## Lit  0.82 0.34 0.79 0.205 1.3
## 
##                        ML2  ML1
## SS loadings           2.44 1.64
## Proportion Var        0.49 0.33
## Cumulative Var        0.49 0.82
## Proportion Explained  0.60 0.40
## Cumulative Proportion 0.60 1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  10  and the objective function was  3.66 with Chi Square of  60.31
## The degrees of freedom for the model are 1  and the objective function was  0.08 
## 
## The root mean square of the residuals (RMSR) is  0.03 
## The df corrected root mean square of the residuals is  0.09 
## 
## The harmonic number of observations is  20 with the empirical chi square  0.3  with prob <  0.58 
## The total number of observations was  20  with Likelihood Chi Square =  1.23  with prob <  0.27 
## 
## Tucker Lewis Index of factoring reliability =  0.95
## RMSEA index =  0.093  and the 90 % confidence intervals are  0 0.631
## BIC =  -1.77
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    ML2  ML1
## Correlation of (regression) scores with factors   0.98 1.00
## Multiple R square of scores with factors          0.97 1.00
## Minimum correlation of possible factor scores     0.94 0.99
ev = eigen(cor(datos[, 2:6]))  # Obtencion de los autovalores.
ap = parallel(subject = nrow(datos[, 2:6]), 
              var = ncol(datos[, 2:6]), 
              rep = 100, 
              cent = 0.05)
nS = nScree(x = ev$values, aparallel = ap$eigen$qevpea)
plotnScree(nS, xlab = "Numero de Componentes", ylab = "Autovalores", 
           main = "Solucion por autovalores para determinar \n el numero de factores o componentes")

fit.pa.rot.vari = fa(datos[, 2:6], 
                     nfactors = 2, 
                     fm = "pa", 
                     rotate = "varimax", 
                     n.obs = 220, 
                     scores = "regression")
## maximum iteration exceeded
fit.pa.rot.vari
## Factor Analysis using method =  pa
## Call: fa(r = datos[, 2:6], nfactors = 2, n.obs = 220, rotate = "varimax", 
##     scores = "regression", fm = "pa")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      PA1  PA2   h2    u2 com
## CNa 0.42 0.68 0.64 0.357 1.7
## Mat 0.04 0.93 0.88 0.124 1.0
## Fra 0.98 0.08 0.96 0.038 1.0
## Lat 0.81 0.18 0.69 0.307 1.1
## Lit 0.85 0.31 0.82 0.175 1.3
## 
##                        PA1  PA2
## SS loadings           2.53 1.47
## Proportion Var        0.51 0.29
## Cumulative Var        0.51 0.80
## Proportion Explained  0.63 0.37
## Cumulative Proportion 0.63 1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  10  and the objective function was  3.66 with Chi Square of  60.31
## The degrees of freedom for the model are 1  and the objective function was  0.11 
## 
## The root mean square of the residuals (RMSR) is  0.02 
## The df corrected root mean square of the residuals is  0.07 
## 
## The harmonic number of observations is  20 with the empirical chi square  0.19  with prob <  0.66 
## The total number of observations was  20  with Likelihood Chi Square =  1.62  with prob <  0.2 
## 
## Tucker Lewis Index of factoring reliability =  0.863
## RMSEA index =  0.169  and the 90 % confidence intervals are  0 0.67
## BIC =  -1.37
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    PA1  PA2
## Correlation of (regression) scores with factors   0.98 0.94
## Multiple R square of scores with factors          0.97 0.89
## Minimum correlation of possible factor scores     0.94 0.78
fit.pa.rot.qua = fa(datos[, 2:6], 
                     nfactors = 2, 
                     fm = "pa", 
                     rotate = "quartimax", 
                     n.obs = 220, 
                     scores = "regression")
## maximum iteration exceeded
## Loading required namespace: GPArotation
fit.pa.rot.qua
## Factor Analysis using method =  pa
## Call: fa(r = datos[, 2:6], nfactors = 2, n.obs = 220, rotate = "quartimax", 
##     scores = "regression", fm = "pa")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      PA1   PA2   h2    u2 com
## CNa 0.50  0.63 0.64 0.357 1.9
## Mat 0.15  0.92 0.88 0.124 1.0
## Fra 0.98 -0.03 0.96 0.038 1.0
## Lat 0.83  0.09 0.69 0.307 1.0
## Lit 0.88  0.21 0.82 0.175 1.1
## 
##                        PA1  PA2
## SS loadings           2.69 1.30
## Proportion Var        0.54 0.26
## Cumulative Var        0.54 0.80
## Proportion Explained  0.67 0.33
## Cumulative Proportion 0.67 1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  10  and the objective function was  3.66 with Chi Square of  60.31
## The degrees of freedom for the model are 1  and the objective function was  0.11 
## 
## The root mean square of the residuals (RMSR) is  0.02 
## The df corrected root mean square of the residuals is  0.07 
## 
## The harmonic number of observations is  20 with the empirical chi square  0.19  with prob <  0.66 
## The total number of observations was  20  with Likelihood Chi Square =  1.62  with prob <  0.2 
## 
## Tucker Lewis Index of factoring reliability =  0.863
## RMSEA index =  0.169  and the 90 % confidence intervals are  0 0.67
## BIC =  -1.37
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    PA1  PA2
## Correlation of (regression) scores with factors   0.99 0.94
## Multiple R square of scores with factors          0.97 0.89
## Minimum correlation of possible factor scores     0.95 0.77