Introducción


El dataframe

Proceso de normalización

Base de datos

#install.packages("e1071")
library(e1071)
# Leemos el archivo
Data <- read_xlsx("C:/Users/diego/Downloads/Indicador de Seguimiento a la Economía (ISE).xlsx",
                 sheet = "Tabla Final")
Data

Serie de Tiempo Seleccionada

Nota: Definición de la serie de tiempo elegida y descripción a partir de sus componentes.

attach(Data)

# Detectar año y mes de inicio
fecha_inicio <- min(Data$Fecha, na.rm = TRUE)
anio_inicio <- as.numeric(format(fecha_inicio, "%Y"))
mes_inicio <- as.numeric(format(fecha_inicio, "%m"))

# Crear las series temporales con fecha correcta
y <- ts(Data$`Indicador de Seguimiento a la Economía`, frequency = 12, start = c(anio_inicio, mes_inicio))
x <- ts(Data$`Actividades primarias`, frequency = 12, start = c(anio_inicio, mes_inicio))

# Fechas para graficar
fechas <- seq(as.Date(fecha_inicio), length.out = length(y), by = "months")

# Graficar
ts.plot(y, main = "Indicadores de Seguimiento de la Economía (ISE)")

ts.plot(x, main = "Actividades primarias")

En el gráfico se observa que: 1. Tendencia: A la alza 2. Ciclo: SI 3. Estacionalidad: SI 4. Irregularidad: SI nota: aqui revisar la informacion para ver que hacer porque no recuerdo la informacion para rellenar

#Modelos de suavizamiento
#Modelo de promedios móviles
m1<-sma(y, h=3)
f1<-forecast(m1, h=10)
plot(forecast(m1))

#Modelo de suavización exponencial
m2<-ces(y,h=3,seasonality = "none")
f2<-forecast(m2)
plot(forecast(m2))

#Modelo de índices estacionales
m3<-ces(y,h=3,seasonality = "simple")
f3<-forecast(m3)
plot(forecast(m3))

m4<-ces(y,h=3,seasonality = "partial")
f4<-forecast(m4)
plot(forecast(m4))

m5<-ces(y,h=3,seasonality = "full")
f5<-forecast(m5)
plot(forecast(m5))

#Medidas de error de pronostico
p1<-fitted.values(m1)
p2<-fitted.values(m2)
p3<-fitted.values(m3)
p4<-fitted.values(m4)
p5<-fitted.values(m5)

a1<-accuracy(p1,y[1:242])
a2<-accuracy(p2,y[1:242])
a3<-accuracy(p3,y[1:242])
a4<-accuracy(p4,y[1:242])
a5<-accuracy(p5,y[1:242])
Tabla<-matrix(c(a1[c(2,3,5)], a2[c(2,3,5)], a3[c(2,3,5)], a4[c(2,3,5)], a5[c(2,3,5)]), 5, byrow=TRUE)
rownames(Tabla)<-c("Promedios moviles","Suavizacion exponencial","Estacional simple", "Estacional parcial", "Estacional completo") #Define los nombres de fila
colnames(Tabla)<-c("RMSE","MAE","MAPE")
Tabla
##                             RMSE      MAE     MAPE
## Promedios moviles       5.480963 3.794829 3.903229
## Suavizacion exponencial 5.316510 3.713245 3.867300
## Estacional simple       4.404171 2.851181 3.102142
## Estacional parcial      2.302605 1.540220 1.651569
## Estacional completo     2.315468 1.427494 1.478069
#Modelos polinomicos y
T=length(y)
t = seq(1:T) 
t2 = t^2 
t3 = t^3
t4 = t^4
t5 = t^5
t6 = t^6
t7 = t^7
t8 = t^8

mlineal=lm(y~t)
summary(mlineal)
## 
## Call:
## lm(formula = y ~ t)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -27.5120  -2.9232   0.0471   2.6014  16.6846 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 64.907831   0.723257   89.74   <2e-16 ***
## t            0.248383   0.005161   48.13   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.608 on 240 degrees of freedom
## Multiple R-squared:  0.9061, Adjusted R-squared:  0.9057 
## F-statistic:  2317 on 1 and 240 DF,  p-value: < 2.2e-16
g1<-predict.lm(mlineal, h=3)

mcuad=lm(y~t+t2)
summary(mcuad)
## 
## Call:
## lm(formula = y ~ t + t2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -27.7389  -2.6935  -0.0145   2.6567  17.1335 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.260e+01  1.075e+00  58.263  < 2e-16 ***
## t            3.050e-01  2.042e-02  14.938  < 2e-16 ***
## t2          -2.330e-04  8.138e-05  -2.864  0.00456 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.526 on 239 degrees of freedom
## Multiple R-squared:  0.9092, Adjusted R-squared:  0.9085 
## F-statistic:  1197 on 2 and 239 DF,  p-value: < 2.2e-16
g2<-predict.lm(mcuad, h=3)

mcub=lm(y~t+t2+t3)
summary(mcub)
## 
## Call:
## lm(formula = y ~ t + t2 + t3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -27.1193  -2.9297   0.1636   2.5831  17.4652 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.113e+01  1.439e+00  42.477  < 2e-16 ***
## t            3.772e-01  5.118e-02   7.369 2.81e-12 ***
## t2          -9.739e-04  4.889e-04  -1.992   0.0475 *  
## t3           2.033e-06  1.323e-06   1.537   0.1257    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.51 on 238 degrees of freedom
## Multiple R-squared:  0.9101, Adjusted R-squared:  0.909 
## F-statistic: 803.4 on 3 and 238 DF,  p-value: < 2.2e-16
g3<-predict.lm(mcub, h=3)

mcuatro=lm(y~t+t2+t3+t4)
summary(mcuatro)
## 
## Call:
## lm(formula = y ~ t + t2 + t3 + t4)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -26.174  -2.825  -0.161   2.232  18.737 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.426e+01  1.789e+00  35.926  < 2e-16 ***
## t            1.238e-01  1.016e-01   1.219  0.22405    
## t2           3.696e-03  1.695e-03   2.181  0.03017 *  
## t3          -2.782e-05  1.047e-05  -2.658  0.00840 ** 
## t4           6.142e-08  2.137e-08   2.874  0.00442 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.428 on 237 degrees of freedom
## Multiple R-squared:  0.9132, Adjusted R-squared:  0.9117 
## F-statistic:   623 on 4 and 237 DF,  p-value: < 2.2e-16
g4<-predict.lm(mcuatro, h=3)

mcinco=lm(y~t+t2+t3+t4+t5)
summary(mcinco)
## 
## Call:
## lm(formula = y ~ t + t2 + t3 + t4 + t5)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -26.2104  -2.6407  -0.1404   2.1456  18.9706 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.352e+01  2.175e+00  29.212   <2e-16 ***
## t            2.127e-01  1.795e-01   1.185    0.237    
## t2           1.155e-03  4.554e-03   0.254    0.800    
## t3          -2.446e-08  4.741e-05  -0.001    1.000    
## t4          -6.712e-08  2.149e-07  -0.312    0.755    
## t5           2.116e-10  3.520e-10   0.601    0.548    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.435 on 236 degrees of freedom
## Multiple R-squared:  0.9133, Adjusted R-squared:  0.9115 
## F-statistic: 497.2 on 5 and 236 DF,  p-value: < 2.2e-16
g5<-predict.lm(mcinco, h=3)

mseis<-lm(y~t+t2+t3+t4+t5+t6)
summary(mseis)
## 
## Call:
## lm(formula = y ~ t + t2 + t3 + t4 + t5 + t6)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -24.5353  -2.8361  -0.2515   2.1296  18.6141 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.765e+01  2.476e+00  23.284  < 2e-16 ***
## t            1.187e+00  2.794e-01   4.249 3.09e-05 ***
## t2          -3.845e-02  9.941e-03  -3.868 0.000142 ***
## t3           6.485e-04  1.531e-04   4.237 3.25e-05 ***
## t4          -5.060e-06  1.144e-06  -4.424 1.48e-05 ***
## t5           1.828e-08  4.084e-09   4.476 1.19e-05 ***
## t6          -2.478e-11  5.583e-12  -4.439 1.39e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.232 on 235 degrees of freedom
## Multiple R-squared:   0.92,  Adjusted R-squared:  0.918 
## F-statistic: 450.4 on 6 and 235 DF,  p-value: < 2.2e-16
g6<-predict.lm(mseis,h=3)

msiete<-lm(y~t+t2+t3+t4+t5+t6+t7)
summary(msiete)
## 
## Call:
## lm(formula = y ~ t + t2 + t3 + t4 + t5 + t6 + t7)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -24.0784  -2.7850  -0.1327   1.9720  18.9795 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.967e+01  2.870e+00  20.791   <2e-16 ***
## t            7.464e-01  4.234e-01   1.763   0.0792 .  
## t2          -1.438e-02  2.003e-02  -0.718   0.4734    
## t3           1.024e-04  4.232e-04   0.242   0.8090    
## t4           1.097e-06  4.593e-06   0.239   0.8115    
## t5          -1.814e-08  2.663e-08  -0.681   0.4964    
## t6           8.338e-11  7.836e-11   1.064   0.2884    
## t7          -1.272e-13  9.190e-14  -1.384   0.1677    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.222 on 234 degrees of freedom
## Multiple R-squared:  0.9206, Adjusted R-squared:  0.9183 
## F-statistic: 387.8 on 7 and 234 DF,  p-value: < 2.2e-16
g7<-predict.lm(msiete,h=3)

mocho<-lm(y~t+t2+t3+t4+t5+t6+t7+t8)
summary(mocho)
## 
## Call:
## lm(formula = y ~ t + t2 + t3 + t4 + t5 + t6 + t7 + t8)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -24.0640  -2.8098  -0.1397   1.9915  18.8045 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.031e+01  3.295e+00  18.305   <2e-16 ***
## t            5.698e-01  6.144e-01   0.927    0.355    
## t2          -1.950e-03  3.717e-02  -0.052    0.958    
## t3          -2.687e-04  1.026e-03  -0.262    0.794    
## t4           6.793e-06  1.506e-05   0.451    0.652    
## t5          -6.676e-08  1.252e-07  -0.533    0.595    
## t6           3.164e-10  5.918e-10   0.535    0.593    
## t7          -7.140e-13  1.480e-12  -0.482    0.630    
## t8           6.037e-16  1.520e-15   0.397    0.692    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.231 on 233 degrees of freedom
## Multiple R-squared:  0.9207, Adjusted R-squared:  0.918 
## F-statistic: 338.2 on 8 and 233 DF,  p-value: < 2.2e-16
g8<-predict.lm(mocho,h=3)

Polinomio de grado 1: Ecuación de la recta es: y=13.265-0.0105x. Como la pendiente es negativa, la tendencia es a la baja. Significancia individual y global: p-valores<0.05, luego los coeficientes son estadísticamente diferentes de cero. R2=0.1256 indica que la tendencia lineal explica en 12% la variabilidad de la tasa de desempleo. aqui debemos escribir y analizar la infroamcion

#Grafico sencillo
plot(fechas,y,type="l",col="blue")
lines(fechas,g1,col="red")
lines(fechas,g2,col="green")
lines(fechas,g6,col="orange")
lines(fechas,g7,col="black")
lines(fechas,g8,col="purple")

#Medidas de error de pronostico
rmse1<-sqrt(MSE(y,g1))
rmse2<-sqrt(MSE(y,g2))
rmse3<-sqrt(MSE(y,g3))
rmse4<-sqrt(MSE(y,g4))
rmse5<-sqrt(MSE(y,g5))
rmse6<-sqrt(MSE(y,g6))
rmse7<-sqrt(MSE(y,g7))
rmse8<-sqrt(MSE(y,g8))

mae1<-MAE(y,g1)
mae2<-MAE(y,g2)
mae3<-MAE(y,g3)
mae4<-MAE(y,g4)
mae5<-MAE(y,g5)
mae6<-MAE(y,g6)
mae7<-MAE(y,g7)
mae8<-MAE(y,g8)

mape1<-MAPE(y,g1)
mape2<-MAPE(y,g2)
mape3<-MAPE(y,g3)
mape4<-MAPE(y,g4)
mape5<-MAPE(y,g5)
mape6<-MAPE(y,g6)
mape7<-MAPE(y,g7)
mape8<-MAPE(y,g8)
A<-matrix(c(rmse1, rmse2, rmse3, rmse4, rmse5, rmse6, rmse7, rmse8, mae1, mae2, mae3, mae4, mae5, mae6, mae7, mae8, mape1, mape2, mape3, mape4, mape5, mape6, mape7, mape8), 8, byrow=FALSE)
rownames(A)<-c("Lineal","Cuadratico","Grado3", "Grado4", "Grado5", "Grado6", "Grado7", "Grado8") #Define los nombres de fila
colnames(A)<-c("RMSE","MAE","MAPE")
A
##                RMSE      MAE       MAPE
## Lineal     5.584969 3.965102 0.04160197
## Cuadratico 5.491558 3.779402 0.03926358
## Grado3     5.464515 3.803242 0.03951042
## Grado4     5.371699 3.776436 0.03933705
## Grado5     5.367591 3.752436 0.03895441
## Grado6     5.155783 3.577116 0.03688910
## Grado7     5.134814 3.554143 0.03649538
## Grado8     5.133076 3.553698 0.03649298
#Varias medidas de error de pronóstico
accuracy(g1,y[1:237])
##                    ME     RMSE      MAE       MPE     MAPE
## Test set -0.005624226 5.533831 3.918186 -0.360033 4.144751
accuracy(g2,y[1:237])
##                   ME     RMSE      MAE       MPE     MAPE
## Test set -0.05067795 5.427448 3.724046 -0.345572 3.904033
accuracy(g6,y[1:237])
##                   ME     RMSE      MAE        MPE     MAPE
## Test set -0.03296855 5.094266 3.531058 -0.2873145 3.672019
accuracy(g7,y[1:237])
##                   ME     RMSE      MAE        MPE     MAPE
## Test set -0.05277144 5.069622 3.511702 -0.3029798 3.635987
accuracy(g8,y[1:237])
##                   ME     RMSE      MAE        MPE     MAPE
## Test set -0.04790769 5.068352 3.509295 -0.2988531 3.633943
#Pronosticos
forecast(g1)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       125.2648 125.2648 125.2648 125.2648 125.2648
## 244       125.5132 125.5132 125.5132 125.5132 125.5132
## 245       125.7616 125.7616 125.7616 125.7616 125.7616
## 246       126.0100 126.0100 126.0100 126.0100 126.0100
## 247       126.2584 126.2584 126.2584 126.2584 126.2584
## 248       126.5067 126.5067 126.5067 126.5067 126.5067
## 249       126.7551 126.7551 126.7551 126.7551 126.7551
## 250       127.0035 127.0035 127.0035 127.0035 127.0035
## 251       127.2519 127.2519 127.2519 127.2519 127.2519
## 252       127.5003 127.5003 127.5003 127.5003 127.5003
forecast(g2)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       122.9624 122.9618 122.9630 122.9615 122.9634
## 244       123.1549 123.1535 123.1562 123.1528 123.1569
## 245       123.3473 123.3451 123.3496 123.3439 123.3508
## 246       123.5398 123.5365 123.5431 123.5348 123.5448
## 247       123.7323 123.7278 123.7367 123.7254 123.7391
## 248       123.9247 123.9190 123.9304 123.9160 123.9335
## 249       124.1172 124.1101 124.1243 124.1063 124.1280
## 250       124.3096 124.3011 124.3182 124.2965 124.3227
## 251       124.5021 124.4920 124.5122 124.4866 124.5176
## 252       124.6945 124.6828 124.7063 124.6765 124.7126
forecast(g3)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       124.4373 124.4360 124.4385 124.4354 124.4392
## 244       124.6997 124.6969 124.7024 124.6954 124.7039
## 245       124.9621 124.9574 124.9667 124.9550 124.9692
## 246       125.2245 125.2177 125.2313 125.2141 125.2349
## 247       125.4869 125.4777 125.4961 125.4728 125.5010
## 248       125.7493 125.7374 125.7611 125.7312 125.7674
## 249       126.0117 125.9970 126.0264 125.9892 126.0342
## 250       126.2741 126.2564 126.2918 126.2470 126.3012
## 251       126.5365 126.5155 126.5575 126.5044 126.5686
## 252       126.7989 126.7745 126.8233 126.7616 126.8362
forecast(g4)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       127.5637 127.5574 127.5700 127.5540 127.5733
## 244       128.0657 128.0516 128.0798 128.0441 128.0872
## 245       128.5676 128.5440 128.5913 128.5315 128.6038
## 246       129.0696 129.0350 129.1043 129.0167 129.1226
## 247       129.5716 129.5247 129.6185 129.4998 129.6434
## 248       130.0736 130.0131 130.1340 129.9812 130.1660
## 249       130.5756 130.5005 130.6506 130.4608 130.6903
## 250       131.0775 130.9869 131.1682 130.9389 131.2162
## 251       131.5795 131.4723 131.6868 131.4155 131.7436
## 252       132.0815 131.9567 132.2063 131.8907 132.2723
forecast(g5)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       128.2966 128.2893 128.3039 128.2854 128.3078
## 244       128.8768 128.8616 128.8919 128.8536 128.8999
## 245       129.4569 129.4324 129.4815 129.4195 129.4944
## 246       130.0371 130.0019 130.0723 129.9833 130.0910
## 247       130.6173 130.5702 130.6644 130.5452 130.6894
## 248       131.1975 131.1373 131.2576 131.1055 131.2894
## 249       131.7777 131.7035 131.8518 131.6642 131.8911
## 250       132.3578 132.2687 132.4470 132.2215 132.4942
## 251       132.9380 132.8329 133.0431 132.7773 133.0987
## 252       133.5182 133.3963 133.6401 133.3318 133.7046
forecast(g6)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       122.5147 122.4881 122.5413 122.4740 122.5554
## 244       122.2585 122.2000 122.3171 122.1690 122.3481
## 245       122.0120 121.9155 122.1086 121.8643 122.1597
## 246       121.7748 121.6355 121.9141 121.5618 121.9878
## 247       121.5465 121.3606 121.7323 121.2622 121.8307
## 248       121.3268 121.0911 121.5624 120.9664 121.6872
## 249       121.1154 120.8272 121.4035 120.6747 121.5560
## 250       120.9119 120.5690 121.2548 120.3875 121.4364
## 251       120.7162 120.3165 121.1158 120.1050 121.3274
## 252       120.5278 120.0697 120.9858 119.8272 121.2283
forecast(g7)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       120.5295 120.5023 120.5567 120.4879 120.5711
## 244       119.8805 119.8198 119.9413 119.7876 119.9734
## 245       119.2315 119.1300 119.3331 119.0763 119.3868
## 246       118.5826 118.4342 118.7310 118.3556 118.8095
## 247       117.9336 117.7329 118.1343 117.6267 118.2405
## 248       117.2846 117.0269 117.5424 116.8904 117.6789
## 249       116.6357 116.3164 116.9550 116.1473 117.1240
## 250       115.9867 115.6018 116.3716 115.3980 116.5754
## 251       115.3377 114.8834 115.7921 114.6429 116.0326
## 252       114.6888 114.1614 115.2161 113.8822 115.4953
forecast(g8)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       121.1561 121.1319 121.1803 121.1190 121.1931
## 244       120.6690 120.6153 120.7226 120.5869 120.7511
## 245       120.1916 120.1026 120.2806 120.0554 120.3278
## 246       119.7238 119.5946 119.8530 119.5262 119.9214
## 247       119.2653 119.0918 119.4388 119.0000 119.5306
## 248       118.8160 118.5948 119.0373 118.4776 119.1544
## 249       118.3757 118.1036 118.6479 117.9595 118.7920
## 250       117.9442 117.6184 118.2700 117.4460 118.4425
## 251       117.5213 117.1395 117.9032 116.9373 118.1054
## 252       117.1069 116.6668 117.5471 116.4338 117.7801

De aqui falta hacer el analisis para saber cual es el mejor modelo pero dejare el codigo para porseguir

#Pronosticos
p8<-forecast(g8) #El mejor modelo de los polinomios
p8
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 243       121.1561 121.1319 121.1803 121.1190 121.1931
## 244       120.6690 120.6153 120.7226 120.5869 120.7511
## 245       120.1916 120.1026 120.2806 120.0554 120.3278
## 246       119.7238 119.5946 119.8530 119.5262 119.9214
## 247       119.2653 119.0918 119.4388 119.0000 119.5306
## 248       118.8160 118.5948 119.0373 118.4776 119.1544
## 249       118.3757 118.1036 118.6479 117.9595 118.7920
## 250       117.9442 117.6184 118.2700 117.4460 118.4425
## 251       117.5213 117.1395 117.9032 116.9373 118.1054
## 252       117.1069 116.6668 117.5471 116.4338 117.7801
f5 #El mejor modelo de los suavizados
##           Mar      Apr      May      Jun      Jul      Aug      Sep      Oct
## 2025 123.5808 118.9022 121.8284 123.6517 126.3066 126.5314 125.2474 126.3556
##           Nov      Dec
## 2025 131.1916 139.2957
## Pronostico (estacional parcial) - PONGA ACÁ SU MEJOR MODELO
mp<-ces(y,h=3,seasonality = "full")
fy<-forecast(mp)
plot(forecast(mp))

fy
##           Mar      Apr      May      Jun      Jul      Aug      Sep      Oct
## 2025 123.5808 118.9022 121.8284 123.6517 126.3066 126.5314 125.2474 126.3556
##           Nov      Dec
## 2025 131.1916 139.2957

hasta aqui toca saber cual es el mejor modelo

aqui en adelnate ya es corr

#Correlacion
mcorr<-lm(y~x)
summary(mcorr)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.6470  -6.2606  -0.4203   4.4072  23.6240 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -15.87723    3.51566  -4.516 9.88e-06 ***
## x             1.21428    0.03806  31.905  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.995 on 240 degrees of freedom
## Multiple R-squared:  0.8092, Adjusted R-squared:  0.8084 
## F-statistic:  1018 on 1 and 240 DF,  p-value: < 2.2e-16
f14<-predict.lm(mcorr)

uff aqui no tengo ni idea que ocurre

#Pronostico
yp=47.45-0.614*57.93 #Este dato, corresponde a la tasa de ocupación del mes de octubre de 2024
yp
## [1] 11.88098
#Medidas de error de pronostico correlacion
rmse14<-sqrt(MSE(y,f14))
mae14<-MAE(y,f14)
mape14<-MAPE(y,f14)
Comparacion<-matrix(c(a1[c(2,3,5)], a2[c(2,3,5)], a3[c(2,3,5)], a4[c(2,3,5)], a5[c(2,3,5)], rmse1, mae1, mape1*100, rmse2, mae2, mape2*100, rmse3, mae3, mape3*100, rmse4, mae4, mape4*100, rmse5, mae5, mape5*100, rmse6, mae6, mape6*100, rmse7, mae7, mape7*100, rmse8, mae8, mape8*100, rmse14, mae14, mape14*100), 14, byrow=TRUE)
rownames(Comparacion)<-c("Promedios moviles","Suavizacion exponencial","Estacional simple", "Estacional parcial", "Estacional completo", "Polinomio grado 1", "Polinomio grado 2", "Polinomio grado 3", "Polinomio grado 4", "Polinomio grado 5", "Polinomio grado 6", "Polinomio grado 7", "Polinomio grado 8", "Correlacion") #Define los nombres de fila
colnames(Comparacion)<-c("RMSE","MAE","MAPE")
Comparacion
##                             RMSE      MAE     MAPE
## Promedios moviles       5.480963 3.794829 3.903229
## Suavizacion exponencial 5.316510 3.713245 3.867300
## Estacional simple       4.404171 2.851181 3.102142
## Estacional parcial      2.302605 1.540220 1.651569
## Estacional completo     2.315468 1.427494 1.478069
## Polinomio grado 1       5.584969 3.965102 4.160197
## Polinomio grado 2       5.491558 3.779402 3.926358
## Polinomio grado 3       5.464515 3.803242 3.951042
## Polinomio grado 4       5.371699 3.776436 3.933705
## Polinomio grado 5       5.367591 3.752436 3.895441
## Polinomio grado 6       5.155783 3.577116 3.688910
## Polinomio grado 7       5.134814 3.554143 3.649538
## Polinomio grado 8       5.133076 3.553698 3.649298
## Correlacion             7.961986 6.279782 6.429062