library(rio)
cocina=import ("INEI_cocina.xlsx")
cocina=cocina[complete.cases(cocina),]

Porcentaje casos positivos

cocina$si_elec_por=cocina$si_elec/cocina$total_elec
cocina$si_gas_por=cocina$si_gas/cocina$total_gas
cocina$si_carbon_por=cocina$si_carbon/cocina$total_carbon
cocina$si_lena_por=cocina$si_lena/cocina$total_lena

Selección de columnas

names(cocina)
##  [1] "Código"        "DEPARTAMENTO"  "PROVINCIA"     "no_elec"      
##  [5] "si_elec"       "total_elec"    "no_gas"        "si_gas"       
##  [9] "total_gas"     "no_carbon"     "si_carbon"     "total_carbon" 
## [13] "no_lena"       "si_lena"       "total_lena"    "si_elec_por"  
## [17] "si_gas_por"    "si_carbon_por" "si_lena_por"
datos_por=cocina[,c(16,17,18,19)] 
str(datos_por)
## 'data.frame':    196 obs. of  4 variables:
##  $ si_elec_por  : num  0.03743 0.00786 0.01587 0.00142 0.00682 ...
##  $ si_gas_por   : num  0.694 0.484 0.596 0.156 0.48 ...
##  $ si_carbon_por: num  0.01148 0.01412 0.00742 0.00264 0.0025 ...
##  $ si_lena_por  : num  0.528 0.641 0.7 0.893 0.861 ...
corMatrix=polycor::hetcor(datos_por)$correlations
round(corMatrix,2)
##               si_elec_por si_gas_por si_carbon_por si_lena_por
## si_elec_por          1.00       0.47          0.10       -0.46
## si_gas_por           0.47       1.00          0.23       -0.87
## si_carbon_por        0.10       0.23          1.00       -0.31
## si_lena_por         -0.46      -0.87         -0.31        1.00

PRUEBAS

library(psych)
psych::KMO(corMatrix) 
## Kaiser-Meyer-Olkin factor adequacy
## Call: psych::KMO(r = corMatrix)
## Overall MSA =  0.63
## MSA for each item = 
##   si_elec_por    si_gas_por si_carbon_por   si_lena_por 
##          0.91          0.59          0.72          0.59

Adecuación

cortest.bartlett(corMatrix,n=nrow(datos_por))$p.value>0.05 
## [1] FALSE
library(matrixcalc)
is.singular.matrix(corMatrix)
## [1] FALSE

Determinar factores

fa.parallel(datos_por, fa = 'fa',correct = T,plot = F)
## Parallel analysis suggests that the number of factors =  1  and the number of components =  NA

Varimax

library(GPArotation)
## 
## Adjuntando el paquete: 'GPArotation'
## The following objects are masked from 'package:psych':
## 
##     equamax, varimin
fa_result <- fa(datos_por, nfactors = 1, rotate = "varimax", fm = "ml")
print(fa_result)
## Factor Analysis using method =  ml
## Call: fa(r = datos_por, nfactors = 1, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                 ML1   h2    u2 com
## si_elec_por    0.49 0.24 0.757   1
## si_gas_por     0.91 0.83 0.169   1
## si_carbon_por  0.30 0.09 0.910   1
## si_lena_por   -0.95 0.90 0.099   1
## 
##                 ML1
## SS loadings    2.07
## Proportion Var 0.52
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## df null model =  6  with the objective function =  1.76 with Chi Square =  338.91
## df of  the model are 2  and the objective function was  0.03 
## 
## The root mean square of the residuals (RMSR) is  0.03 
## The df corrected root mean square of the residuals is  0.06 
## 
## The harmonic n.obs is  196 with the empirical chi square  2.43  with prob <  0.3 
## The total n.obs was  196  with Likelihood Chi Square =  5.98  with prob <  0.05 
## 
## Tucker Lewis Index of factoring reliability =  0.964
## RMSEA index =  0.101  and the 90 % confidence intervals are  0 0.199
## BIC =  -4.58
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    ML1
## Correlation of (regression) scores with factors   0.97
## Multiple R square of scores with factors          0.94
## Minimum correlation of possible factor scores     0.87

Oblimin

library(GPArotation)
fa_result2 <- fa(datos_por, nfactors = 1, rotate = "oblimin", fm = "ml")
print(fa_result)
## Factor Analysis using method =  ml
## Call: fa(r = datos_por, nfactors = 1, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                 ML1   h2    u2 com
## si_elec_por    0.49 0.24 0.757   1
## si_gas_por     0.91 0.83 0.169   1
## si_carbon_por  0.30 0.09 0.910   1
## si_lena_por   -0.95 0.90 0.099   1
## 
##                 ML1
## SS loadings    2.07
## Proportion Var 0.52
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## df null model =  6  with the objective function =  1.76 with Chi Square =  338.91
## df of  the model are 2  and the objective function was  0.03 
## 
## The root mean square of the residuals (RMSR) is  0.03 
## The df corrected root mean square of the residuals is  0.06 
## 
## The harmonic n.obs is  196 with the empirical chi square  2.43  with prob <  0.3 
## The total n.obs was  196  with Likelihood Chi Square =  5.98  with prob <  0.05 
## 
## Tucker Lewis Index of factoring reliability =  0.964
## RMSEA index =  0.101  and the 90 % confidence intervals are  0 0.199
## BIC =  -4.58
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    ML1
## Correlation of (regression) scores with factors   0.97
## Multiple R square of scores with factors          0.94
## Minimum correlation of possible factor scores     0.87
print(fa_result$loadings,cutoff = 0.5)
## 
## Loadings:
##               ML1   
## si_elec_por         
## si_gas_por     0.912
## si_carbon_por       
## si_lena_por   -0.949
## 
##                  ML1
## SS loadings    2.065
## Proportion Var 0.516
print(fa_result2$loadings,cutoff = 0.5)
## 
## Loadings:
##               ML1   
## si_elec_por         
## si_gas_por     0.912
## si_carbon_por       
## si_lena_por   -0.949
## 
##                  ML1
## SS loadings    2.065
## Proportion Var 0.516