Parte II: Series Temporales y técnicas no supervisadas
El documento ha sido convertido a PDF con la librería pdfkit de Python de la web pública responsive que se puede visitar en la siguiente URL: https://rpubs.com/rtovcan/877300
Series Temporales
Introducción: Presentación de la serie a analizar.
La serie ha sido obtenida desde el INE y son datos reales de la tasa de varuiación mensual del Índice de Precios de Consumo (IPC) de España. Tiene 200 meses y el último mes con datos ha sido Febrero de 2022.
El IPC tiene como objetivo proporcionar una medida estadística de la evolución del conjunto de precios de los bienes y servicios que consume la población residente en viviendas familiares en España.
Representación grafica y descomposición estacional (si tuviera comportamiento estacional).
Se Convierte a serie temporal
Análisis y descripción de las componenetes de la serie
Descomposición de las series
Representacion de la descomposición
Coeficientes debidos a la estacionalidad
## [1] 6.746313e-15 -1.292364e-14 2.635436e-14 -7.448438e-15 -2.266360e-14
## [6] 2.538843e+01 -7.093364e-15 -1.338843e+01 1.258286e-14 -6.658688e-15
## [11] -7.635873e-14 2.450847e-14
Análisis gráfico de la estacionalidad. Representación por año
Representacion de residuos
## [1] -3.02742e+14
## [1] 1.590911e+15
Contraste de normalidad de los residuos
##
## One-sample Kolmogorov-Smirnov test
##
## data: v_ipc_desc$random
## D = 0.42308, p-value < 2.2e-16
## alternative hypothesis: two-sided
##
## Shapiro-Wilk normality test
##
## data: v_ipc_desc$random
## W = 0.54181, p-value < 2.2e-16
Construcción del periodograma
Tratamiento de la serie.
Eliminar la heterocedasticidad. Estabilización de la varianza
Una función para pintar…hay más..
Eliminar tendencia
Representación
Eliminar estacionalidad
Contraste de normalidad de los residuos
##
## One-sample Kolmogorov-Smirnov test
##
## data: ipcLog.diff_1_12
## D = 0.20635, p-value = 0.009354
## alternative hypothesis: two-sided
##
## Shapiro-Wilk normality test
##
## data: ipcLog.diff_1_12
## W = NaN, p-value = NA
Ventanas de ajuste y evaluación
Suavizado exponencial
Distribución de residuos
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Mar 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## Apr 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## May 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## Jun 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## Jul 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## Aug 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## Sep 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## Oct 2022 0.1433328 -0.6443021 0.9309676 -1.061251 1.347916
## Simple exponential smoothing
##
## Call:
## ses(y = ipc_tr, h = 8)
##
## Smoothing parameters:
## alpha = 1e-04
##
## Initial states:
## l = 0.1433
##
## sigma: 0.6146
##
## AIC AICc BIC
## 837.0787 837.2050 846.8823
#Representamos los valores observados y los suavizados con la predicción
Suavizado Exponencial doble de Holt
Inspección del objeto creado y Distribución de residuos
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Mar 2022 0.2107487 -0.5847585 1.0062560 -1.005875 1.427372
## Apr 2022 0.2088434 -0.5866708 1.0043575 -1.007791 1.425477
## May 2022 0.2069380 -0.5885916 1.0024676 -1.009720 1.423596
## Jun 2022 0.2050327 -0.5905244 1.0005897 -1.011667 1.421732
## Jul 2022 0.2031273 -0.5924727 0.9987273 -1.013638 1.419892
## Aug 2022 0.2012219 -0.5944399 0.9968837 -1.015638 1.418082
## Sep 2022 0.1993166 -0.5964293 0.9950625 -1.017672 1.416305
## Oct 2022 0.1974112 -0.5984445 0.9932670 -1.019745 1.414568
## Holt's method
##
## Call:
## holt(y = ipc_tr, h = 8)
##
## Smoothing parameters:
## alpha = 0.0021
## beta = 0.0021
##
## Initial states:
## l = 0.2765
## b = -0.013
##
## sigma: 0.6207
##
## AIC AICc BIC
## 842.9061 843.2253 859.2454
Representamos los valores observados y los suavizados con la predicción
Holt-Winters
Ajuste de modelo
##Visualización
Predicciones utilizando el paquete forecast (ETS)
Se comprueba la precisión de las distintas predicciones.
Parece que los distintos metodos se adaptan bastantes bien tras comprobar los resultados con datos reales, excepto HOLT-WINTERS multiplicativo ya que no es compatible con los valores negativos de la tasa de variación. Parece que se producirá una caida de la tasa de variación del IPC este mes, aunque es un poco improbable con la coyuntura actual económica.
Tecnicas no supervisadas
## Name CodigoProvincia CCAA Population
## Length:8119 Min. : 1.00 Length:8119 Min. : 5
## Class :character 1st Qu.:13.00 Class :character 1st Qu.: 166
## Mode :character Median :26.00 Mode :character Median : 549
## Mean :26.67 Mean : 5742
## 3rd Qu.:41.00 3rd Qu.: 2428
## Max. :52.00 Max. :3141991
##
## TotalCensus AbstentionPtge AbstencionAlta Izda_Pct
## Min. : 5 Min. : 0.00 Min. :0.0000 Min. : 0.00
## 1st Qu.: 140 1st Qu.:21.68 1st Qu.:0.0000 1st Qu.:21.89
## Median : 447 Median :26.43 Median :0.0000 Median :35.16
## Mean : 4261 Mean :26.51 Mean :0.3114 Mean :34.40
## 3rd Qu.: 1846 3rd Qu.:31.48 3rd Qu.:1.0000 3rd Qu.:46.03
## Max. :2363829 Max. :57.58 Max. :1.0000 Max. :94.12
##
## Dcha_Pct Otros_Pct Izquierda Derecha
## Min. : 0.00 Min. : 0.0000 Min. :0.0000 Min. :0.0000
## 1st Qu.: 38.69 1st Qu.: 0.7595 1st Qu.:0.0000 1st Qu.:0.0000
## Median : 51.58 Median : 1.8830 Median :0.0000 Median :1.0000
## Mean : 48.92 Mean : 14.6662 Mean :0.2228 Mean :0.6211
## 3rd Qu.: 62.20 3rd Qu.: 16.4970 3rd Qu.:0.0000 3rd Qu.:1.0000
## Max. :100.00 Max. :100.0000 Max. :1.0000 Max. :1.0000
##
## Age_0-4_Ptge Age_under19_Ptge Age_19_65_pct Age_over65_pct
## Min. : 0.000 Min. : 0.000 Min. : 23.46 Min. : 0.00
## 1st Qu.: 1.389 1st Qu.: 8.334 1st Qu.: 53.84 1st Qu.:19.82
## Median : 2.978 Median :13.889 Median : 58.66 Median :27.56
## Mean : 3.019 Mean :13.568 Mean : 57.37 Mean :29.07
## 3rd Qu.: 4.533 3rd Qu.:19.058 3rd Qu.: 61.82 3rd Qu.:36.91
## Max. :13.245 Max. :33.696 Max. :100.00 Max. :76.47
##
## WomanPopulationPtge ForeignersPtge SameComAutonPtge SameComAutonDiffProvPtge
## Min. :11.77 Min. :-8.96 Min. : 0.00 Min. : 0.000
## 1st Qu.:45.73 1st Qu.: 1.06 1st Qu.: 75.81 1st Qu.: 0.676
## Median :48.48 Median : 3.59 Median : 84.49 Median : 2.190
## Mean :47.30 Mean : 5.62 Mean : 81.63 Mean : 4.337
## 3rd Qu.:50.00 3rd Qu.: 8.18 3rd Qu.: 90.46 3rd Qu.: 5.277
## Max. :72.68 Max. :71.47 Max. :127.16 Max. :67.308
##
## DifComAutonPtge UnemployLess25_Ptge Unemploy25_40_Ptge UnemployMore40_Ptge
## Min. : 0.000 Min. : 0.000 Min. : 0.00 Min. : 0.00
## 1st Qu.: 4.933 1st Qu.: 0.000 1st Qu.: 28.57 1st Qu.: 41.67
## Median : 8.271 Median : 5.882 Median : 39.94 Median : 50.00
## Mean : 10.729 Mean : 7.322 Mean : 37.00 Mean : 50.18
## 3rd Qu.: 13.898 3rd Qu.: 10.470 3rd Qu.: 46.67 3rd Qu.: 60.04
## Max. :100.000 Max. :100.000 Max. :100.00 Max. :100.00
##
## AgricultureUnemploymentPtge IndustryUnemploymentPtge
## Min. : 0.000 Min. : 0.000
## 1st Qu.: 0.000 1st Qu.: 0.000
## Median : 3.493 Median : 7.143
## Mean : 8.401 Mean : 10.008
## 3rd Qu.: 11.732 3rd Qu.: 14.286
## Max. :100.000 Max. :100.000
##
## ConstructionUnemploymentPtge ServicesUnemploymentPtge totalEmpresas
## Min. : 0.000 Min. : 0.00 Min. : 0.0
## 1st Qu.: 0.000 1st Qu.: 50.00 1st Qu.: 7.0
## Median : 8.333 Median : 62.02 Median : 30.0
## Mean : 10.838 Mean : 58.65 Mean : 398.6
## 3rd Qu.: 14.286 3rd Qu.: 72.12 3rd Qu.: 147.0
## Max. :100.000 Max. :100.00 Max. :299397.0
## NA's :5
## Industria Construccion ComercTTEHosteleria Servicios
## Min. : 0.00 Min. : 0.00 Min. : 0.0 Min. : 0.0
## 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.0 1st Qu.: 0.0
## Median : 0.00 Median : 0.00 Median : 0.0 Median : 0.0
## Mean : 23.42 Mean : 48.88 Mean : 146.7 Mean : 172.2
## 3rd Qu.: 14.00 3rd Qu.: 25.00 3rd Qu.: 65.0 3rd Qu.: 40.0
## Max. :10521.00 Max. :30343.00 Max. :80856.0 Max. :177677.0
## NA's :188 NA's :139 NA's :9 NA's :62
## ActividadPpal inmuebles Pob2010 SUPERFICIE
## Length:8119 Min. : 6 Min. : 5 Min. : 2.58
## Class :character 1st Qu.: 180 1st Qu.: 178 1st Qu.: 1839.19
## Mode :character Median : 486 Median : 582 Median : 3487.74
## Mean : 3246 Mean : 5796 Mean : 6214.70
## 3rd Qu.: 1589 3rd Qu.: 2483 3rd Qu.: 6893.88
## Max. :1615548 Max. :3273049 Max. :175022.91
## NA's :138 NA's :7 NA's :9
## Densidad PobChange_pct PersonasInmueble Explotaciones
## Length:8119 Min. :-52.2700 Min. :0.110 Min. : 1
## Class :character 1st Qu.:-10.4000 1st Qu.:0.850 1st Qu.: 22
## Mode :character Median : -4.9600 Median :1.250 Median : 52
## Mean : -4.8974 Mean :1.296 Mean : 2447
## 3rd Qu.: 0.0925 3rd Qu.:1.730 3rd Qu.: 137
## Max. :138.4600 Max. :3.330 Max. :99999
## NA's :7 NA's :138
## [1] "Name" "CodigoProvincia"
## [3] "CCAA" "Population"
## [5] "TotalCensus" "AbstentionPtge"
## [7] "AbstencionAlta" "Izda_Pct"
## [9] "Dcha_Pct" "Otros_Pct"
## [11] "Izquierda" "Derecha"
## [13] "Age_0-4_Ptge" "Age_under19_Ptge"
## [15] "Age_19_65_pct" "Age_over65_pct"
## [17] "WomanPopulationPtge" "ForeignersPtge"
## [19] "SameComAutonPtge" "SameComAutonDiffProvPtge"
## [21] "DifComAutonPtge" "UnemployLess25_Ptge"
## [23] "Unemploy25_40_Ptge" "UnemployMore40_Ptge"
## [25] "AgricultureUnemploymentPtge" "IndustryUnemploymentPtge"
## [27] "ConstructionUnemploymentPtge" "ServicesUnemploymentPtge"
## [29] "totalEmpresas" "Industria"
## [31] "Construccion" "ComercTTEHosteleria"
## [33] "Servicios" "ActividadPpal"
## [35] "inmuebles" "Pob2010"
## [37] "SUPERFICIE" "Densidad"
## [39] "PobChange_pct" "PersonasInmueble"
## [41] "Explotaciones"
Ciudades con más de 100000 hab
Selecciono las numéricas
## [1] "AbstentionPtge" "AbstencionAlta"
## [3] "Izda_Pct" "Dcha_Pct"
## [5] "Otros_Pct" "Izquierda"
## [7] "Derecha" "Age_0-4_Ptge"
## [9] "Age_under19_Ptge" "Age_19_65_pct"
## [11] "Age_over65_pct" "WomanPopulationPtge"
## [13] "ForeignersPtge" "SameComAutonPtge"
## [15] "SameComAutonDiffProvPtge" "DifComAutonPtge"
## [17] "UnemployLess25_Ptge" "Unemploy25_40_Ptge"
## [19] "UnemployMore40_Ptge" "AgricultureUnemploymentPtge"
## [21] "IndustryUnemploymentPtge" "ConstructionUnemploymentPtge"
## [23] "ServicesUnemploymentPtge" "totalEmpresas"
## [25] "Industria" "Construccion"
## [27] "ComercTTEHosteleria" "Servicios"
## [29] "inmuebles" "SUPERFICIE"
## [31] "PobChange_pct" "PersonasInmueble"
## [33] "Explotaciones"
Gráfico de correlación y comunidades
Comprobar matriz de correlaciones
Calular determinante de la matriz
## [1] 1.140791e-31
Gráfico de correlaciones
Test de esferidad de Bartlett
## $chisq
## [1] 5692.248
##
## $p.value
## [1] 0
##
## $df
## [1] 630
Indice de Adecuacion Muestral KMO
## Error in solve.default(r) :
## sistema es computacionalmente singular: número de condición recíproco = 3.96215e-18
## Kaiser-Meyer-Olkin factor adequacy
## Call: psych::KMO(r = elec_r)
## Overall MSA = 0.5
## MSA for each item =
## Pop Cens Abs AbsA Izda Dcha Otr
## 0.5 0.5 0.5 0.5 0.5 0.5 0.5
## IzqA DechA Age4 Age19 Age19_65 Age65 WomP
## 0.5 0.5 0.5 0.5 0.5 0.5 0.5
## Forei SameCom SCDifProv DifCom UnL25 Un25_40 UnM40
## 0.5 0.5 0.5 0.5 0.5 0.5 0.5
## AgrU IndU ConsU ServU Empr Indus Const
## 0.5 0.5 0.5 0.5 0.5 0.5 0.5
## ComHost Servi inmuebles Pob2010 SUPERFICIE PobChange PersInm
## 0.5 0.5 0.5 0.5 0.5 0.5 0.5
## Explot
## 0.5
Selecciono un subconjunto de variables
## [1] "Pop" "Cens" "Abs" "AbsA" "Izda"
## [6] "Dcha" "Otr" "IzqA" "DechA" "Age4"
## [11] "Age19" "Age19_65" "Age65" "WomP" "Forei"
## [16] "SameCom" "SCDifProv" "DifCom" "UnL25" "Un25_40"
## [21] "UnM40" "AgrU" "IndU" "ConsU" "ServU"
## [26] "Empr" "Indus" "Const" "ComHost" "Servi"
## [31] "inmuebles" "Pob2010" "SUPERFICIE" "PobChange" "PersInm"
## [36] "Explot"
Indice de Adecuacion Muestral KMO
## Kaiser-Meyer-Olkin factor adequacy
## Call: psych::KMO(r = elec_red)
## Overall MSA = 0.49
## MSA for each item =
## Izda Dcha Otr IzqA DechA Age4 Age19 Age19_65
## 0.41 0.43 0.48 0.58 0.61 0.48 0.50 0.35
## UnM40 AgrU IndU ConsU ServU Empr Indus Const
## 0.57 0.28 0.36 0.21 0.28 0.65 0.68 0.66
## ComHost
## 0.67
Gráfico de correlaciones
Indice de Adecuacion Muestral KMO
## Kaiser-Meyer-Olkin factor adequacy
## Call: psych::KMO(r = elec_red[, -c(3, 14)])
## Overall MSA = 0.44
## MSA for each item =
## Izda Dcha IzqA DechA Age4 Age19 Age19_65 AgrU
## 0.50 0.56 0.42 0.43 0.55 0.51 0.30 0.22
## IndU ConsU ServU Empr Const ComHost
## 0.23 0.20 0.28 0.59 0.63 0.67
PCA
## Call:
## princomp(x = elec_red, cor = T)
##
## Standard deviations:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
## 1.8627167 1.5621482 1.5162700 1.3785199 1.1224419 0.9592571 0.8044901 0.7142493
## Comp.9 Comp.10 Comp.11 Comp.12 Comp.13 Comp.14
## 0.4615783 0.3861494 0.2865314 0.2413469 0.2003032 0.1026930
##
## 14 variables and 54 observations.
Información del modelo
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 1.8627167 1.5621482 1.5162700 1.3785199 1.12244190
## Proportion of Variance 0.2478367 0.1743076 0.1642196 0.1357369 0.08999113
## Cumulative Proportion 0.2478367 0.4221443 0.5863639 0.7221009 0.81209199
## Comp.6 Comp.7 Comp.8 Comp.9 Comp.10
## Standard deviation 0.95925714 0.80449005 0.71424929 0.46157831 0.38614938
## Proportion of Variance 0.06572673 0.04622887 0.03643943 0.01521818 0.01065081
## Cumulative Proportion 0.87781872 0.92404760 0.96048703 0.97570521 0.98635602
## Comp.11 Comp.12 Comp.13 Comp.14
## Standard deviation 0.286531360 0.241346866 0.200303151 0.1026929802
## Proportion of Variance 0.005864301 0.004160594 0.002865811 0.0007532749
## Cumulative Proportion 0.992220321 0.996380914 0.999246725 1.0000000000
Sedimentación
Cargas
##
## Loadings:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9 Comp.10
## Izda 0.109 0.261 0.404 0.109 0.395 0.289 0.404 0.444
## Dcha -0.122 -0.375 0.426 0.109 0.172 0.259 -0.685
## IzqA 0.168 0.499 0.425 -0.416
## DechA -0.239 -0.431 0.317 -0.110 0.139 0.190 0.141 0.308
## Age4 0.303 -0.236 -0.138 0.378 0.183 0.159 -0.368 0.227 0.151 -0.449
## Age19 0.267 -0.356 0.376 0.182 -0.315 0.542
## Age19_65 0.109 0.237 0.494 0.156 0.426 -0.654
## AgrU -0.296 -0.263 0.500 -0.498 -0.330 -0.342
## IndU -0.470 0.639 0.285 -0.187
## ConsU 0.131 -0.149 0.429 -0.377 -0.455 0.392 0.324 -0.190 -0.149
## ServU -0.137 0.277 0.417 0.173 -0.256 0.122 -0.468 -0.210 -0.295
## Empr -0.494 -0.103 0.184 0.196
## Const -0.443 -0.177 0.295 0.160 -0.380
## ComHost -0.477 -0.134 0.196 0.215 0.287
## Comp.11 Comp.12 Comp.13 Comp.14
## Izda 0.304 0.190
## Dcha 0.183 0.191
## IzqA -0.277 -0.395 -0.350
## DechA -0.259 -0.440 -0.449
## Age4 -0.420 0.202
## Age19 0.395 -0.247 -0.103
## Age19_65 -0.173 0.141
## AgrU 0.210 -0.240
## IndU 0.351 0.112 -0.299
## ConsU 0.153 -0.285
## ServU 0.335 0.101 -0.381
## Empr 0.803
## Const 0.244 -0.453 0.397 -0.297
## ComHost -0.190 0.487 -0.253 -0.496
##
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9
## SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
## Proportion Var 0.071 0.071 0.071 0.071 0.071 0.071 0.071 0.071 0.071
## Cumulative Var 0.071 0.143 0.214 0.286 0.357 0.429 0.500 0.571 0.643
## Comp.10 Comp.11 Comp.12 Comp.13 Comp.14
## SS loadings 1.000 1.000 1.000 1.000 1.000
## Proportion Var 0.071 0.071 0.071 0.071 0.071
## Cumulative Var 0.714 0.786 0.857 0.929 1.000
Con la función PCA()
Información del modelo
##
## Call:
## FactoMineR::PCA(X = elec_red, scale.unit = T)
##
##
## Eigenvalues
## Dim.1 Dim.2 Dim.3 Dim.4 Dim.5 Dim.6 Dim.7
## Variance 3.470 2.440 2.299 1.900 1.260 0.920 0.647
## % of var. 24.784 17.431 16.422 13.574 8.999 6.573 4.623
## Cumulative % of var. 24.784 42.214 58.636 72.210 81.209 87.782 92.405
## Dim.8 Dim.9 Dim.10 Dim.11 Dim.12 Dim.13 Dim.14
## Variance 0.510 0.213 0.149 0.082 0.058 0.040 0.011
## % of var. 3.644 1.522 1.065 0.586 0.416 0.287 0.075
## Cumulative % of var. 96.049 97.571 98.636 99.222 99.638 99.925 100.000
##
## Individuals (the 10 first)
## Dist Dim.1 ctr cos2
## Algeciras | 3.250 | -2.092 2.336 0.414 |
## Cádiz | 4.053 | -1.290 0.888 0.101 |
## Jerez de la Frontera | 2.512 | -1.046 0.584 0.174 |
## Castellón de la Plana / Castelló de la Plana | 2.507 | -0.016 0.000 0.000 |
## Córdoba | 2.639 | 1.719 1.576 0.424 |
## A Coruña | 3.540 | 3.051 4.970 0.743 |
## Granada | 2.352 | 1.538 1.263 0.428 |
## Donostia / San Sebastián | 4.220 | 0.845 0.381 0.040 |
## Huelva | 5.430 | -2.738 4.001 0.254 |
## Jaén | 3.847 | -1.226 0.802 0.102 |
## Dim.2 ctr cos2 Dim.3
## Algeciras 1.597 1.936 0.242 | 1.018
## Cádiz -2.793 5.919 0.475 | 1.161
## Jerez de la Frontera 1.440 1.574 0.329 | 0.591
## Castellón de la Plana / Castelló de la Plana 1.685 2.154 0.452 | -1.103
## Córdoba 1.140 0.987 0.187 | 0.148
## A Coruña -0.275 0.058 0.006 | -0.105
## Granada 0.569 0.246 0.059 | 1.073
## Donostia / San Sebastián -3.447 9.014 0.667 | -0.562
## Huelva 0.424 0.136 0.006 | 0.113
## Jaén 1.979 2.972 0.265 | 1.455
## ctr cos2
## Algeciras 0.834 0.098 |
## Cádiz 1.086 0.082 |
## Jerez de la Frontera 0.282 0.055 |
## Castellón de la Plana / Castelló de la Plana 0.979 0.193 |
## Córdoba 0.018 0.003 |
## A Coruña 0.009 0.001 |
## Granada 0.927 0.208 |
## Donostia / San Sebastián 0.254 0.018 |
## Huelva 0.010 0.000 |
## Jaén 1.704 0.143 |
##
## Variables (the 10 first)
## Dim.1 ctr cos2 Dim.2
## Izda | -0.204 1.196 0.041 | -0.408
## Dcha | 0.227 1.484 0.052 | 0.585
## IzqA | -0.313 2.831 0.098 | -0.779
## DechA | 0.444 5.692 0.198 | 0.673
## Age4 | -0.564 9.159 0.318 | 0.369
## Age19 | -0.498 7.149 0.248 | 0.556
## Age19_65 | -0.203 1.186 0.041 | 0.051
## AgrU | -0.179 0.918 0.032 | 0.462
## IndU | -0.022 0.014 0.000 | 0.139
## ConsU | -0.245 1.724 0.060 | 0.013
## ctr cos2 Dim.3 ctr
## Izda 6.823 0.167 | 0.612 16.302
## Dcha 14.043 0.343 | 0.645 18.114
## IzqA 24.875 0.607 | 0.004 0.001
## DechA 18.551 0.453 | 0.481 10.050
## Age4 5.582 0.136 | -0.209 1.904
## Age19 12.683 0.310 | -0.081 0.285
## Age19_65 0.107 0.003 | 0.360 5.632
## AgrU 8.734 0.213 | 0.031 0.043
## IndU 0.793 0.019 | -0.712 22.043
## ConsU 0.007 0.000 | -0.226 2.216
## cos2
## Izda 0.375 |
## Dcha 0.416 |
## IzqA 0.000 |
## DechA 0.231 |
## Age4 0.044 |
## Age19 0.007 |
## Age19_65 0.129 |
## AgrU 0.001 |
## IndU 0.507 |
## ConsU 0.051 |
AF
##
## Call:
## factanal(x = elec_red, factors = 3, scores = "regression", rotation = "none")
##
## Uniquenesses:
## Izda Dcha IzqA DechA Age4 Age19 Age19_65 AgrU
## 0.216 0.296 0.091 0.005 0.877 0.894 0.917 0.958
## IndU ConsU ServU Empr Const ComHost
## 0.846 0.890 0.849 0.005 0.110 0.039
##
## Loadings:
## Factor1 Factor2 Factor3
## Izda -0.149 0.871
## Dcha 0.486 -0.631 0.264
## IzqA -0.510 0.520 0.615
## DechA 0.722 -0.688
## Age4 -0.309 -0.139
## Age19 -0.178 -0.203 -0.181
## Age19_65 -0.131 0.256
## AgrU -0.201
## IndU 0.144 -0.359
## ConsU -0.181 -0.262
## ServU 0.135 0.364
## Empr 0.855 0.514
## Const 0.751 0.568
## ComHost 0.817 0.542
##
## Factor1 Factor2 Factor3
## SS loadings 3.186 2.166 1.657
## Proportion Var 0.228 0.155 0.118
## Cumulative Var 0.228 0.382 0.501
##
## Test of the hypothesis that 3 factors are sufficient.
## The chi square statistic is 219.55 on 52 degrees of freedom.
## The p-value is 1.81e-22
## Factor Analysis using method = wls
## Call: psych::fa(r = elec_red, nfactors = 3, rotate = "promax", fm = "wls")
## Standardized loadings (pattern matrix) based upon correlation matrix
## WLS1 WLS2 WLS3 h2 u2 com
## Izda 0.66 0.472 0.53 1.4
## Dcha 0.78 0.35 0.702 0.30 1.4
## IzqA -0.68 0.563 0.44 1.4
## DechA 0.84 0.740 0.26 1.2
## Age4 -0.53 0.418 0.58 1.6
## Age19 -0.54 0.487 0.51 1.9
## Age19_65 0.108 0.89 2.3
## AgrU 0.136 0.86 2.4
## IndU -0.59 0.358 0.64 1.1
## ConsU 0.064 0.94 2.8
## ServU 0.66 0.511 0.49 1.2
## Empr 0.85 0.728 0.27 1.2
## Const 0.77 0.598 0.40 1.2
## ComHost 0.83 0.687 0.31 1.2
##
## WLS1 WLS2 WLS3
## SS loadings 2.80 2.01 1.76
## Proportion Var 0.20 0.14 0.13
## Cumulative Var 0.20 0.34 0.47
## Proportion Explained 0.43 0.31 0.27
## Cumulative Proportion 0.43 0.73 1.00
##
## With factor correlations of
## WLS1 WLS2 WLS3
## WLS1 1.00 -0.07 0.15
## WLS2 -0.07 1.00 -0.06
## WLS3 0.15 -0.06 1.00
##
## Mean item complexity = 1.6
## Test of the hypothesis that 3 factors are sufficient.
##
## The degrees of freedom for the null model are 91 and the objective function was 13.91 with Chi Square of 660.71
## The degrees of freedom for the model are 52 and the objective function was 8.31
##
## The root mean square of the residuals (RMSR) is 0.13
## The df corrected root mean square of the residuals is 0.17
##
## The harmonic number of observations is 54 with the empirical chi square 168.78 with prob < 2.9e-14
## The total number of observations was 54 with Likelihood Chi Square = 377.94 with prob < 5.1e-51
##
## Tucker Lewis Index of factoring reliability = -0.053
## RMSEA index = 0.34 and the 90 % confidence intervals are 0.312 0.377
## BIC = 170.52
## Fit based upon off diagonal values = 0.81
## Measures of factor score adequacy
## WLS1 WLS2 WLS3
## Correlation of (regression) scores with factors 0.92 0.90 0.89
## Multiple R square of scores with factors 0.84 0.81 0.80
## Minimum correlation of possible factor scores 0.68 0.63 0.59
Biplot para AF con la función biplot()
CLustering jerárquico
Lista de métodos de Linkage a comparar
Genero un bucle para recorrerla, ajustar modelos y pedir información
## Indice VI single = 0.9798834
## Indice Rand single = 0.2974756
## Silueta media single = 0.2788331
## Within SS single = 697.67
## Indice VI complete = 0.4255589
## Indice Rand complete = 0.8267175
## Silueta media complete = 0.5815634
## Within SS complete = 154.2363
## Indice VI average = 0.4232592
## Indice Rand average = 0.7900927
## Silueta media average = 0.5576904
## Within SS average = 169.7858
## Indice VI mcquitty = 0.4779669
## Indice Rand mcquitty = 0.8075494
## Silueta media mcquitty = 0.5591647
## Within SS mcquitty = 164.5828
## Indice VI ward.D2 = 0.4594814
## Indice Rand ward.D2 = 0.75846
## Silueta media ward.D2 = 0.5360699
## Within SS ward.D2 = 184.4635
Validación Interna
Validación externa
Genero las clasificaciones para 4 clusters
Aplico la función macthing para poder sacar el valor correcto de accuracy
#Parece que funciona mejor el completo o ward en este caso
Comparación con K-means
Validacion con Accuracy
## Accuracy K-means = 0.94
## Indice VI K-means = 0.3383608
## Indice Rand K-means = 0.8572115
## Silueta media K-means = 0.5851126
## Within SS K-means = 151.9651
Una tabla resumen total de validación interna/externa
## vi rand silhouette wss Acc
## single 0.9798834 0.2974756 0.2788331 697.6700 0.51
## complete 0.4255589 0.8267175 0.5815634 154.2363 0.93
## average 0.4232592 0.7900927 0.5576904 169.7858 0.91
## mcquitty 0.4779669 0.8075494 0.5591647 164.5828 0.92
## ward.D2 0.4594814 0.7584600 0.5360699 184.4635 0.89
## med.km 0.3383608 0.8572115 0.5851126 151.9651 0.94