Data <- read.csv("Atencion.csv")
head(Data)
##   S  E DI  C D P1 P2 P3 P4 P5 P6 P7 P8 P9
## 1 h 77 28 NO 1  3  4  3  4  4  5  1  2  2
## 2 h 88 26 NO 2  2  3  2  4  4  5  4  5  5
## 3 h 90 28 NO 3  2  2  2  4  4  5  2  3  2
## 4 h 62 19 SI 3  4  3  4  3  3  3  4  5  5
## 5 h 90 30 SI 1  5  5  5  2  2  3  3  4  5
## 6 h 63 30 NO 3  4  3  4  3  3  3  2  3  2

Data solo numerica:

Data_numeric <- Data[sapply(Data, is.numeric)]
col_means <- colMeans(Data_numeric)

Estadisticas descriptivas:

Data_numeric <- Data[sapply(Data, is.numeric)]
col_means <- colMeans(Data_numeric)

Medias    <- apply(Data_numeric[,],2,mean)
Des_st    <- apply(Data_numeric[,],2,sd)
Coef_Var  <- Des_st/Medias

Descriptivas <-rbind(Medias,Des_st,Coef_Var)
round(Descriptivas,2)
##              E    DI    D   P1   P2   P3   P4   P5   P6   P7   P8   P9
## Medias   68.64 13.31 2.03 3.50 3.29 3.64 3.21 3.32 3.47 2.85 3.76 3.62
## Des_st   17.52 10.03 0.98 1.17 1.09 1.28 1.18 1.06 1.23 1.08 1.05 1.50
## Coef_Var  0.26  0.75 0.48 0.33 0.33 0.35 0.37 0.32 0.35 0.38 0.28 0.42

Los datos descriptivos muestran una población de pacientes con una edad promedio de 68.64 años, lo que sugiere que el hospital atiende principalmente a adultos mayores. Las calificaciones de los servicios (habitaciones, comida,atención del personal, etc.) tienden a ser moderadas, con una mayor satisfacción en áreas como la solución del problema y la atención médica, aunque existe una variabilidad considerable en las percepciones de los pacientes, especialmente en aspectos como la información recibida. Estos resultados preliminares, que reflejan una dispersión significativa en varias variables, sugieren que existen diferentes factores subyacentes que podrían explicar las variaciones en la satisfacción y las características de los pacientes. Este contexto es adecuado para aplicar un Análisis Factorial Exploratorio (EFA), con el fin de identificar patrones y agrupar variables relacionadas que puedan ayudar a entender mejor las dimensiones de la experiencia del paciente en el hospital.

Aplicacion de Analisis Factorial Exploratorio (EFA) con enfoque en las variables (P1, P2, P3, P4, P5, P6, P7, P8, P9)

Data_P <- Data[, c("P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9")]

Paso 1: Verificar que la matiz de datos sea factorizable

Matriz de Correlacion

library(polycor)
## Warning: package 'polycor' was built under R version 4.3.3
R <- hetcor(Data_P)$correlations
R
##             P1        P2          P3          P4          P5          P6
## P1  1.00000000 0.8258960  0.96306274 -0.16449386 -0.20353070  0.04584421
## P2  0.82589602 1.0000000  0.87152496  0.24890683  0.13654799  0.36399056
## P3  0.96306274 0.8715250  1.00000000 -0.03641381 -0.07811802  0.18029621
## P4 -0.16449386 0.2489068 -0.03641381  1.00000000  0.87003977  0.74573277
## P5 -0.20353070 0.1365480 -0.07811802  0.87003977  1.00000000  0.67408460
## P6  0.04584421 0.3639906  0.18029621  0.74573277  0.67408460  1.00000000
## P7  0.11649969 0.3201771  0.22510140  0.06462720  0.06004673  0.09218256
## P8  0.10754311 0.2379589  0.16936007 -0.05682630 -0.05746190 -0.03717801
## P9  0.03453722 0.2273607  0.13344422  0.04533565  0.07060313  0.02663651
##            P7          P8         P9
## P1 0.11649969  0.10754311 0.03453722
## P2 0.32017707  0.23795890 0.22736066
## P3 0.22510140  0.16936007 0.13344422
## P4 0.06462720 -0.05682630 0.04533565
## P5 0.06004673 -0.05746190 0.07060313
## P6 0.09218256 -0.03717801 0.02663651
## P7 1.00000000  0.85600862 0.91966434
## P8 0.85600862  1.00000000 0.80921848
## P9 0.91966434  0.80921848 1.00000000
library(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.3.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.3
ggcorrplot(R,type="lower",hc.order = T)

En la grafica podemos observar una buena Correlacion entre las Variables

Prueba de esfericidad de Bartlett:

library(psych)
## Warning: package 'psych' was built under R version 4.3.3
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
## The following object is masked from 'package:polycor':
## 
##     polyserial
cortest.bartlett(Data_P)$p.value
## R was not square, finding R from data
## [1] 2.844082e-196

Dado que el p-value = 0 , rechazamos la hipotesis nula y concluimos que las variables efectivamente estan correlacionadas entre si.

Prueba de KMO

KMO(R)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = R)
## Overall MSA =  0.71
## MSA for each item = 
##   P1   P2   P3   P4   P5   P6   P7   P8   P9 
## 0.62 0.81 0.67 0.62 0.69 0.82 0.67 0.83 0.73

Un valor global de 0.71 nos afirma que estas variables son aptas para aplicar un EFA, el MSA nos indica que cada una de las variables es importante para el analisis.

Paso 2: Elegir un método y extraer los factores:

Metodos utilizados: ejes principales y minimo cuadrados ponderados

Prueba de dos modelos con cinco factores:

library(psych)
m1     <- fa(R, nfactors = 5, rotate = "none",
             fm="paf") # modelo de ejes principales
## factor method not specified correctly, minimum residual (unweighted least squares  used
m1
## Factor Analysis using method =  minres
## Call: fa(r = R, nfactors = 5, rotate = "none", fm = "paf")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     MR1   MR2   MR3   MR4   MR5   h2    u2 com
## P1 0.69 -0.33 -0.63  0.09  0.01 0.99 0.013 2.5
## P2 0.84  0.05 -0.44 -0.07 -0.15 0.92 0.077 1.6
## P3 0.78 -0.21 -0.56  0.05  0.09 0.98 0.023 2.0
## P4 0.20  0.92 -0.01 -0.06 -0.12 0.91 0.088 1.1
## P5 0.16  0.93  0.04  0.28  0.04 0.98 0.021 1.3
## P6 0.32  0.74 -0.15 -0.22  0.14 0.73 0.266 1.7
## P7 0.74 -0.08  0.66 -0.04  0.05 0.99 0.014 2.0
## P8 0.61 -0.19  0.60 -0.01 -0.02 0.76 0.236 2.2
## P9 0.64 -0.08  0.68  0.05 -0.01 0.88 0.122 2.0
## 
##                        MR1  MR2  MR3  MR4  MR5
## SS loadings           3.26 2.47 2.18 0.15 0.07
## Proportion Var        0.36 0.27 0.24 0.02 0.01
## Cumulative Var        0.36 0.64 0.88 0.90 0.90
## Proportion Explained  0.40 0.30 0.27 0.02 0.01
## Cumulative Proportion 0.40 0.70 0.97 0.99 1.00
## 
## Mean item complexity =  1.8
## Test of the hypothesis that 5 factors are sufficient.
## 
## df null model =  36  with the objective function =  11
## df of  the model are 1  and the objective function was  0.02 
## 
## The root mean square of the residuals (RMSR) is  0 
## The df corrected root mean square of the residuals is  0.01 
## 
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    MR1  MR2  MR3  MR4   MR5
## Correlation of (regression) scores with factors   0.99 0.99 0.99 0.84  0.68
## Multiple R square of scores with factors          0.99 0.97 0.98 0.70  0.47
## Minimum correlation of possible factor scores     0.98 0.95 0.97 0.41 -0.07
m2     <- fa(R, nfactors = 5, rotate = "none",
             fm="mle") # maxima verosimilitud
m2
## Factor Analysis using method =  ml
## Call: fa(r = R, nfactors = 5, rotate = "none", fm = "mle")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     ML2   ML3   ML1   ML4   ML5   h2     u2 com
## P1 0.64 -0.09  0.75 -0.02 -0.02 0.99 0.0062 2.0
## P2 0.80  0.10  0.43  0.24 -0.05 0.90 0.0998 1.8
## P3 0.73  0.01  0.66  0.03  0.10 0.98 0.0240 2.0
## P4 0.56 -0.03 -0.69  0.38 -0.06 0.94 0.0635 2.6
## P5 0.60 -0.04 -0.79 -0.04  0.00 1.00 0.0050 1.9
## P6 0.58 -0.03 -0.42  0.37  0.20 0.70 0.3012 2.9
## P7 0.24  0.96  0.06  0.00  0.01 0.98 0.0199 1.1
## P8 0.13  0.85  0.13 -0.05 -0.12 0.78 0.2224 1.1
## P9 0.18  0.92  0.00 -0.07 -0.04 0.88 0.1239 1.1
## 
##                        ML2  ML3  ML1  ML4  ML5
## SS loadings           2.72 2.51 2.48 0.35 0.07
## Proportion Var        0.30 0.28 0.28 0.04 0.01
## Cumulative Var        0.30 0.58 0.86 0.90 0.90
## Proportion Explained  0.33 0.31 0.30 0.04 0.01
## Cumulative Proportion 0.33 0.64 0.95 0.99 1.00
## 
## Mean item complexity =  1.8
## Test of the hypothesis that 5 factors are sufficient.
## 
## df null model =  36  with the objective function =  11
## df of  the model are 1  and the objective function was  0.01 
## 
## The root mean square of the residuals (RMSR) is  0 
## The df corrected root mean square of the residuals is  0.02 
## 
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    ML2  ML3  ML1  ML4   ML5
## Correlation of (regression) scores with factors   1.00 0.99 1.00 0.89  0.66
## Multiple R square of scores with factors          0.99 0.98 1.00 0.79  0.43
## Minimum correlation of possible factor scores     0.99 0.97 0.99 0.58 -0.14

Comparación de las comunalidades:

c1 <- sort(m1$communality,decreasing = T)
c1
##        P1        P7        P5        P3        P2        P4        P9        P8 
## 0.9871257 0.9857922 0.9789010 0.9774174 0.9232146 0.9119169 0.8783169 0.7635487 
##        P6 
## 0.7341862
c2 <- sort(m2$communality,decreasing = T)
c2
##        P5        P1        P7        P3        P4        P2        P9        P8 
## 0.9950004 0.9937920 0.9800984 0.9759919 0.9365267 0.9002472 0.8760538 0.7775841 
##        P6 
## 0.6988183
head(cbind(c1,c2))
##           c1        c2
## P1 0.9871257 0.9950004
## P7 0.9857922 0.9937920
## P5 0.9789010 0.9800984
## P3 0.9774174 0.9759919
## P2 0.9232146 0.9365267
## P4 0.9119169 0.9002472

Comparación de las unicidades:

u1 <- sort(m1$uniquenesses,decreasing = T)
u2 <- sort(m2$uniquenesses,decreasing = T)
head(cbind(u1,u2))
##            u1         u2
## P6 0.26581375 0.30118168
## P8 0.23645132 0.22241588
## P9 0.12168314 0.12394623
## P4 0.08808306 0.09975283
## P2 0.07678544 0.06347333
## P3 0.02258263 0.02400813

Los factores extraídos capturan de manera efectiva la varianza de la mayoría de las variables (en especial P1, P7, P5, P3 y P2), pero algunas variables (como P6, P8 y P9) no están tan bien representadas, lo que podría sugerir que estas variables tienen un componente único que no se ajusta bien al modelo.

Paso 3: Determinar el número adecuado de factores:

Valores propios:

ei   <- eigen(R)
plot(ei$values,type="b",pch=20,col="blue")
abline(h=1,lty=3,col="red")

ei
## eigen() decomposition
## $values
## [1] 3.34256756 2.57831990 2.26536937 0.31108906 0.19303203 0.15412408 0.06945257
## [8] 0.06570035 0.02034508
## 
## $vectors
##             [,1]        [,2]        [,3]        [,4]        [,5]        [,6]
##  [1,] 0.36046097 -0.17966887 -0.44968349  0.09565100 -0.01991505 -0.21624683
##  [2,] 0.45697165  0.04618517 -0.31497931  0.09833817 -0.07147628  0.50435605
##  [3,] 0.41390074 -0.10674599 -0.40250568  0.04404904  0.08810389 -0.26008092
##  [4,] 0.12204580  0.57822362  0.04319618  0.24362022 -0.17642886  0.49989002
##  [5,] 0.09428371  0.56524618  0.08240502  0.48892552  0.01745393 -0.56810936
##  [6,] 0.19040918  0.50490435 -0.06792449 -0.81245366  0.08257257 -0.15373733
##  [7,] 0.40841694 -0.09076260  0.40413030 -0.05960227  0.22679083  0.06786786
##  [8,] 0.36003505 -0.16787860  0.40276497 -0.08549884 -0.78059732 -0.17156471
##  [9,] 0.36532328 -0.09484745  0.44469182  0.09948754  0.53639162  0.03010405
##              [,7]        [,8]         [,9]
##  [1,] -0.15277832  0.16988860  0.725988966
##  [2,]  0.57879194 -0.27912506 -0.088128848
##  [3,] -0.35112732  0.11865229 -0.663752353
##  [4,] -0.46658752  0.29656006  0.053633787
##  [5,]  0.23751236 -0.21488955  0.011227826
##  [6,]  0.08779280  0.05031091  0.058558487
##  [7,] -0.40942797 -0.64720414  0.124657279
##  [8,]  0.08341043  0.15599187 -0.051034146
##  [9,]  0.24890984  0.54706989  0.005520511

Scree plot:

Screeplot <- scree(R)

Paralelo:

Paralelo <- fa.parallel(R, n.obs = 100, main = "Prueba de Paralelo - EFA", 
            ylab = "Valor Eigen")
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect.  Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected.  Examine the results carefully
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect.  Try a
## different factor score estimation method.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect.  Try a
## different factor score estimation method.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect.  Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected.  Examine the results carefully
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect.  Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected.  Examine the results carefully

## Parallel analysis suggests that the number of factors =  3  and the number of components =  3
Paralelo
## Call: fa.parallel(x = R, n.obs = 100, main = "Prueba de Paralelo - EFA", 
##     ylabel = "Valor Eigen")
## Parallel analysis suggests that the number of factors =  3  and the number of components =  3 
## 
##  Eigen Values of 
## 
##  eigen values of factors
## [1]  2.83  1.67  1.64 -0.20 -0.46 -0.53 -0.59 -0.66 -0.87
## 
##  eigen values of simulated factors
## [1]  0.86  0.37  0.24  0.14  0.04 -0.05 -0.14 -0.26 -0.36
## 
##  eigen values of components 
## [1] 3.34 2.58 2.27 0.31 0.19 0.15 0.07 0.07 0.02
## 
##  eigen values of simulated components
## [1] 1.51 1.33 1.19 1.08 0.98 0.88 0.79 0.66 0.56

Parallel analysis suggests that the number of factors = 3 and the number of components = 3 Las otras variables tienen bajas cargas factoriales por lo que no contribuyen al modelo.

Paso 4: Rotación de los factores

library(psych)
library(GPArotation)
## Warning: package 'GPArotation' was built under R version 4.3.3
## 
## Attaching package: 'GPArotation'
## The following objects are masked from 'package:psych':
## 
##     equamax, varimin
# Definir los tipos de rotación
rot <- c("none", "varimax", "quartimax", "promax")

# Función para generar el biplot con diferentes rotaciones
bi_mod <- function(tipo) {biplot.psych(fa(Data_P, nfactors = 3, fm = "pa", rotate = tipo), main = paste("Biplot con rotación", tipo), col = c("red", "black"),pch = c(5, 19))}

Aplicar la función a cada tipo de rotación

sapply(rot, bi_mod)

## $none
## NULL
## 
## $varimax
## NULL
## 
## $quartimax
## NULL
## 
## $promax
## NULL

Como la rotacion Varimax maximiza la varianza de las cargas factoriales dentro de cada factor, utilizare esta rotacion pues facilita la interpretacion con una estructura clara.

Paso 5: Interpretación de resultados:

modelo_varimax <- fa(R,nfactors = 3,rotate = "varimax",fa="ml")

fa.diagram(modelo_varimax)

Podemos concluir que con base en la rotación Varimax, el Factor 1 (MR1) agrupa a las variables P1, P3, P7 y P8, relacionadas con aspectos de comunicación y ambiente general del hospital. El Factor 2 (MR2) incluye las variables P4, P5 y P6, enfocadas en la calidad y atención del equipo clínico. Finalmente, el Factor 3 (MR3) reúne las variables P2 y P9, que representan la percepción general de la experiencia del paciente. EStos factores son ortogonales (independientes).