1
Hello, I am starting in the use of the programming in R for the realization of a project in which I am involved. The question is the following: I have data of counting vehicles hour by hour from 2017 until 2019 and I would like to make projections hour by hour in a regression containing explanatory variables such as time, day, holiday, etc. For this, I am using the following code:
library(forecast)
Pedagiados_Pira=data[,4]
Pedagiados_Pira=as.numeric(unlist(Pedagiados_Pira)
Pedagiados_Pira_TS=ts(Pedagiados_Pira,start = c(2017,1),frequency=8760)
#Criando séries temporais
Pedagiados=ts(Pedagiados_Pira_TS,start=c(2017,1),end=c(2019,4380),frequency=8760)
Feriado_Prolongado=as.numeric(unlist(data[,7]))
Feriado_Prolongado_TS=ts(Feriado_Prolongado,start=c(2017,1),end=c(2019,4380),frequency = 8760)
Feriado_Prolongado_TS
Vespera_Feriado=as.numeric(unlist(data[,8]))
Vespera_Feriado_TS=ts(Vespera_Feriado,start=c(2017,1),end=c(2019,4380),frequency=8760)
Vespera_Feriado_TS
Feriado=as.numeric(unlist(data[,9]))
Feriado_TS=ts(Feriado,start=c(2017,1),end=c(2019,4380),frequency=8760)
Feriado_TS
Dia=as.numeric(unlist(data[,18]))
Dia_TS=ts(Dia,start=c(2017,1),end=c(2019,4380),frequency=8760)
Dia_TS
Hora=as.numeric(unlist(data[,19]))
Hora_TS=ts(Hora,start=c(2017,1),end=c(2019,4380),frequency=8760)
Hora_TS
#Base treino e teste
Volume_Treino=window(Pedagiados,start=c(2017,1),end=c(2019,4380),frequency=8760)
Volume_teste=window(Pedagiados,start=c(2019,4380),frequency=8760)
frequency(Pedagiados)
frequency(Feriado_Prolongado_TS)
frequency(Vespera_Feriado_TS)
frequency(Feriado_TS)
frequency(Dia_TS)
frequency(Hora_TS)
frequency(Volume_Treino)
length(Pedagiados)
length(Feriado_Prolongado_TS)
length(Vespera_Feriado_TS)
length(Feriado_TS)
length(Dia_TS)
length(Hora_TS)
length(Volume_Treino)
#Modelo ARIMA
library(forecast)
Pedagiados_Modelo=auto.arima(Volume_Treino,xreg = cbind(Feriado_Prolongado_TS,Vespera_Feriado_TS,Feriado_TS,Dia_TS,Hora_TS),trace = T, stepwise = T, approximation = T, seasonal = T)
Volume_Prev=forecast(Pedagiados_Modelo,xreg=cbind(Feriado_Prolongado_TS,Vespera_Feriado_TS,Feriado_TS,Dia_TS,Hora_TS),h=8760)
Volume_Prev
However, I am getting as an answer for next week (h=168=24*7):
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2019.50000 1639.295 1308.8097 1969.780 1133.86137 2144.728
2019.50011 1613.166 1023.5096 2202.822 711.36437 2514.968
2019.50023 1589.458 773.1267 2405.790 340.98677 2837.930
2019.50034 1572.230 575.6854 2568.774 48.14677 3096.313
2019.50046 1552.210 422.4699 2681.951 -175.57864 3279.999
2019.50057 1526.521 310.4231 2742.619 -333.34010 3386.382
2019.50068 1500.311 236.2215 2764.400 -432.94684 3433.568
2019.50080 1478.352 190.8950 2765.810 -490.64377 3447.349
2019.50091 1462.639 164.8258 2760.452 -522.19483 3447.472
2019.50103 1452.861 150.6538 2755.067 -538.69284 3444.414
2019.50114 1447.625 143.5283 2751.722 -546.81896 3442.069
2019.50126 1445.410 140.4502 2750.371 -550.35400 3441.175
2019.50137 1445.028 139.6426 2750.413 -551.38664 3441.442
2019.50148 1445.715 140.1077 2751.321 -551.03885 3442.468
2019.50160 1447.044 141.3188 2752.769 -549.89028 3443.978
2019.50171 1448.796 143.0085 2754.583 -548.23362 3445.826
2019.50183 1450.856 145.0363 2756.676 -546.22291 3447.935
2019.50194 1453.153 147.3169 2758.989 -543.95092 3450.257
2019.50205 1455.632 149.7883 2761.476 -541.48370 3452.748
2019.50217 1458.249 152.4010 2764.097 -538.87307 3455.371
2019.50228 1460.965 155.1151 2766.815 -536.15997 3458.090
2019.50240 1463.751 157.9000 2769.601 -533.37556 3460.877
2019.50251 1466.585 160.7335 2772.436 -530.54233 3463.712
2019.50263 1469.451 163.6001 2775.303 -527.67584 3466.579
2019.50274 1438.889 133.0372 2744.740 -558.23882 3436.016
2019.50285 1441.794 135.9424 2747.645 -555.33363 3438.922
2019.50297 1444.710 138.8588 2750.562 -552.41724 3441.838
2019.50308 1447.635 141.7832 2753.486 -549.49288 3444.762
2019.50320 1450.565 144.7133 2756.416 -546.56282 3447.693
2019.50331 1453.499 147.6474 2759.351 -543.62870 3450.627
2019.50342 1456.436 150.5844 2762.288 -540.69169 3453.564
2019.50354 1459.375 153.5234 2765.227 -537.75264 3456.503
2019.50365 1462.316 156.4639 2768.167 -534.81216 3459.443
2019.50377 1465.257 159.4054 2771.109 -531.87068 3462.385
2019.50388 1468.199 162.3476 2774.051 -528.92848 3465.327
2019.50400 1471.142 165.2903 2776.993 -525.98578 3468.270
2019.50411 1474.085 168.2333 2779.937 -523.04274 3471.213
2019.50422 1477.028 171.1766 2782.880 -520.09944 3474.156
2019.50434 1479.972 174.1201 2785.823 -517.15597 3477.099
2019.50445 1482.915 177.0637 2788.767 -514.21237 3480.043
2019.50457 1485.859 180.0074 2791.711 -511.26868 3482.987
2019.50468 1488.803 182.9511 2794.654 -508.32494 3485.930
2019.50479 1491.747 185.8949 2797.598 -505.38114 3488.874
2019.50491 1494.690 188.8388 2800.542 -502.43732 3491.818
2019.50502 1497.634 191.7826 2803.486 -499.49348 3494.762
2019.50514 1500.578 194.7265 2806.430 -496.54962 3497.706
2019.50525 1503.522 197.6703 2809.374 -493.60575 3500.650
2019.50537 1506.466 200.6142 2812.317 -490.66187 3503.593
2019.50548 1437.271 131.4193 2743.122 -559.85679 3434.399
2019.50559 1440.215 134.3632 2746.066 -556.91291 3437.342
2019.50571 1443.159 137.3071 2749.010 -553.96901 3440.286
2019.50582 1446.103 140.2510 2751.954 -551.02512 3443.230
2019.50594 1449.046 143.1948 2754.898 -548.08123 3446.174
2019.50605 1451.990 146.1387 2757.842 -545.13733 3449.118
2019.50616 1454.934 149.0826 2760.786 -542.19344 3452.062
2019.50628 1457.878 152.0265 2763.730 -539.24954 3455.006
2019.50639 1460.822 154.9704 2766.674 -536.30565 3457.950
2019.50651 1463.766 157.9143 2769.618 -533.36175 3460.894
2019.50662 1466.710 160.8582 2772.561 -530.41785 3463.837
2019.50674 1469.654 163.8021 2775.505 -527.47396 3466.781
2019.50685 1472.598 166.7460 2778.449 -524.53006 3469.725
2019.50696 1475.542 169.6899 2781.393 -521.58616 3472.669
2019.50708 1478.485 172.6338 2784.337 -518.64226 3475.613
2019.50719 1481.429 175.5777 2787.281 -515.69837 3478.557
2019.50731 1484.373 178.5216 2790.225 -512.75447 3481.501
2019.50742 1487.317 181.4655 2793.169 -509.81057 3484.445
2019.50753 1490.261 184.4094 2796.113 -506.86668 3487.389
2019.50765 1493.205 187.3533 2799.056 -503.92278 3490.333
2019.50776 1496.149 190.2972 2802.000 -500.97888 3493.276
2019.50788 1499.093 193.2411 2804.944 -498.03499 3496.220
2019.50799 1502.037 196.1850 2807.888 -495.09109 3499.164
2019.50811 1504.980 199.1289 2810.832 -492.14719 3502.108
2019.50822 1435.786 129.9340 2741.637 -561.34210 3432.913
2019.50833 1438.729 132.8779 2744.581 -558.39821 3435.857
2019.50845 1441.673 135.8218 2747.525 -555.45431 3438.801
2019.50856 1444.617 138.7657 2750.469 -552.51041 3441.745
2019.50868 1447.561 141.7096 2753.413 -549.56651 3444.689
2019.50879 1450.505 144.6535 2756.357 -546.62262 3447.633
2019.50890 1453.449 147.5974 2759.301 -543.67872 3450.577
2019.50902 1456.393 150.5413 2762.244 -540.73482 3453.521
2019.50913 1459.337 153.4852 2765.188 -537.79093 3456.464
2019.50925 1462.281 156.4290 2768.132 -534.84703 3459.408
2019.50936 1465.225 159.3729 2771.076 -531.90313 3462.352
2019.50947 1468.168 162.3168 2774.020 -528.95924 3465.296
2019.50959 1471.112 165.2607 2776.964 -526.01534 3468.240
2019.50970 1474.056 168.2046 2779.908 -523.07144 3471.184
2019.50982 1477.000 171.1485 2782.852 -520.12754 3474.128
2019.50993 1479.944 174.0924 2785.796 -517.18365 3477.072
2019.51005 1482.888 177.0363 2788.740 -514.23975 3480.016
2019.51016 1485.832 179.9802 2791.683 -511.29585 3482.959
2019.51027 1488.776 182.9241 2794.627 -508.35196 3485.903
2019.51039 1491.720 185.8680 2797.571 -505.40806 3488.847
2019.51050 1494.664 188.8119 2800.515 -502.46416 3491.791
2019.51062 1497.607 191.7558 2803.459 -499.52026 3494.735
2019.51073 1500.551 194.6997 2806.403 -496.57637 3497.679
2019.51084 1503.495 197.6436 2809.347 -493.63247 3500.623
2019.51096 1434.300 128.4487 2740.152 -562.82738 3431.428
2019.51107 1437.244 131.3926 2743.096 -559.88348 3434.372
2019.51119 1440.188 134.3365 2746.040 -556.93959 3437.316
2019.51130 1443.132 137.2804 2748.984 -553.99569 3440.260
2019.51142 1446.076 140.2243 2751.927 -551.05179 3443.204
2019.51153 1449.020 143.1682 2754.871 -548.10790 3446.147
2019.51164 1451.964 146.1121 2757.815 -545.16400 3449.091
2019.51176 1454.908 149.0560 2760.759 -542.22010 3452.035
2019.51187 1457.851 151.9999 2763.703 -539.27620 3454.979
2019.51199 1460.795 154.9438 2766.647 -536.33231 3457.923
2019.51210 1463.739 157.8877 2769.591 -533.38841 3460.867
2019.51221 1466.683 160.8316 2772.535 -530.44451 3463.811
2019.51233 1469.627 163.7755 2775.479 -527.50062 3466.755
2019.51244 1472.571 166.7194 2778.423 -524.55672 3469.699
2019.51256 1475.515 169.6633 2781.366 -521.61282 3472.643
2019.51267 1478.459 172.6072 2784.310 -518.66893 3475.586
2019.51279 1481.403 175.5510 2787.254 -515.72503 3478.530
2019.51290 1484.347 178.4949 2790.198 -512.78113 3481.474
2019.51301 1487.290 181.4388 2793.142 -509.83723 3484.418
2019.51313 1490.234 184.3827 2796.086 -506.89334 3487.362
2019.51324 1493.178 187.3266 2799.030 -503.94944 3490.306
2019.51336 1496.122 190.2705 2801.974 -501.00554 3493.250
2019.51347 1499.066 193.2144 2804.918 -498.06165 3496.194
2019.51358 1502.010 196.1583 2807.862 -495.11775 3499.138
2019.51370 1432.815 126.9634 2738.667 -564.31266 3429.943
2019.51381 1435.759 129.9073 2741.611 -561.36876 3432.887
2019.51393 1438.703 132.8512 2744.554 -558.42487 3435.830
2019.51404 1441.647 135.7951 2747.498 -555.48097 3438.774
2019.51416 1444.591 138.7390 2750.442 -552.53707 3441.718
2019.51427 1447.534 141.6829 2753.386 -549.59317 3444.662
2019.51438 1450.478 144.6268 2756.330 -546.64928 3447.606
2019.51450 1453.422 147.5707 2759.274 -543.70538 3450.550
2019.51461 1456.366 150.5146 2762.218 -540.76148 3453.494
2019.51473 1459.310 153.4585 2765.162 -537.81759 3456.438
2019.51484 1462.254 156.4024 2768.106 -534.87369 3459.382
2019.51495 1465.198 159.3463 2771.049 -531.92979 3462.326
2019.51507 1468.142 162.2902 2773.993 -528.98590 3465.269
2019.51518 1471.086 165.2341 2776.937 -526.04200 3468.213
2019.51530 1474.030 168.1780 2779.881 -523.09810 3471.157
2019.51541 1476.973 171.1219 2782.825 -520.15420 3474.101
2019.51553 1479.917 174.0658 2785.769 -517.21031 3477.045
2019.51564 1482.861 177.0097 2788.713 -514.26641 3479.989
2019.51575 1485.805 179.9536 2791.657 -511.32251 3482.933
2019.51587 1488.749 182.8975 2794.601 -508.37862 3485.877
2019.51598 1491.693 185.8414 2797.545 -505.43472 3488.821
2019.51610 1494.637 188.7853 2800.488 -502.49082 3491.765
2019.51621 1497.581 191.7292 2803.432 -499.54692 3494.708
2019.51632 1500.525 194.6731 2806.376 -496.60303 3497.652
2019.51644 1431.330 125.4781 2737.181 -565.79794 3428.457
2019.51655 1434.274 128.4220 2740.125 -562.85404 3431.401
2019.51667 1437.218 131.3659 2743.069 -559.91014 3434.345
2019.51678 1440.161 134.3098 2746.013 -556.96625 3437.289
2019.51689 1443.105 137.2537 2748.957 -554.02235 3440.233
2019.51701 1446.049 140.1976 2751.901 -551.07845 3443.177
2019.51712 1448.993 143.1415 2754.845 -548.13456 3446.121
2019.51724 1451.937 146.0854 2757.789 -545.19066 3449.065
2019.51735 1454.881 149.0293 2760.733 -542.24676 3452.009
2019.51747 1457.825 151.9732 2763.676 -539.30287 3454.952
2019.51758 1460.769 154.9171 2766.620 -536.35897 3457.896
2019.51769 1463.713 157.8610 2769.564 -533.41507 3460.840
2019.51781 1466.656 160.8049 2772.508 -530.47117 3463.784
2019.51792 1469.600 163.7488 2775.452 -527.52728 3466.728
2019.51804 1472.544 166.6927 2778.396 -524.58338 3469.672
2019.51815 1475.488 169.6366 2781.340 -521.63948 3472.616
2019.51826 1478.432 172.5805 2784.284 -518.69559 3475.560
2019.51838 1481.376 175.5244 2787.228 -515.75169 3478.504
2019.51849 1484.320 178.4683 2790.171 -512.80779 3481.448
2019.51861 1487.264 181.4122 2793.115 -509.86389 3484.391
2019.51872 1490.208 184.3561 2796.059 -506.92000 3487.335
2019.51884 1493.152 187.3000 2799.003 -503.97610 3490.279
2019.51895 1496.095 190.2439 2801.947 -501.03220 3493.223
2019.51906 1499.039 193.1878 2804.891 -498.08831 3496.167
2019.51918 1429.844 123.9929 2735.696 -567.28322 3426.972
2019.51929 1432.788 126.9368 2738.640 -564.33932 3429.916
2019.51941 1435.732 129.8807 2741.584 -561.39542 3432.860
2019.51952 1438.676 132.8246 2744.528 -558.45153 3435.804
2019.51963 1441.620 135.7684 2747.472 -555.50763 3438.748
2019.51975 1444.564 138.7123 2750.416 -552.56373 3441.692
2019.51986 1447.508 141.6562 2753.359 -549.61983 3444.636
2019.51998 1450.452 144.6001 2756.303 -546.67594 3447.579
2019.52009 1453.396 147.5440 2759.247 -543.73204 3450.523
2019.52021 1456.340 150.4879 2762.191 -540.78814 3453.467
2019.52032 1459.283 153.4318 2765.135 -537.84425 3456.411
2019.52043 1462.227 156.3757 2768.079 -534.90035 3459.355
2019.52055 1465.171 159.3196 2771.023 -531.95645 3462.299
2019.52066 1468.115 162.2635 2773.967 -529.01256 3465.243
2019.52078 1471.059 165.2074 2776.911 -526.06866 3468.187
2019.52089 1474.003 168.1513 2779.855 -523.12476 3471.131
2019.52100 1476.947 171.0952 2782.798 -520.18086 3474.074
2019.52112 1479.891 174.0391 2785.742 -517.23697 3477.018
2019.52123 1482.835 176.9830 2788.686 -514.29307 3479.962
2019.52135 1485.779 179.9269 2791.630 -511.34917 3482.906
2019.52146 1488.722 182.8708 2794.574 -508.40528 3485.850
2019.52158 1491.666 185.8147 2797.518 -505.46138 3488.794
2019.52169 1494.610 188.7586 2800.462 -502.51748 3491.738
2019.52180 1497.554 191.7025 2803.406 -499.57358 3494.682
2019.52192 1428.359 122.5076 2734.211 -568.76850 3425.487
2019.52203 1431.303 125.4515 2737.155 -565.82460 3428.431
2019.52215 1434.247 128.3954 2740.099 -562.88070 3431.375
2019.52226 1437.191 131.3393 2743.042 -559.93680 3434.319
2019.52237 1440.135 134.2832 2745.986 -556.99291 3437.262
2019.52249 1443.079 137.2271 2748.930 -554.04901 3440.206
2019.52260 1446.023 140.1710 2751.874 -551.10511 3443.150
2019.52272 1448.966 143.1149 2754.818 -548.16122 3446.094
Therefore, I would like to understand if I am declaring some variable incorrectly because I verified that the forecast is not returning me values consistent with the historical volume hour by hour (it is noticed that the values obtained rotate around 1420, with no great characteristic variation along the hours of the same day and variation between the days of the week). The vector I got as answer > Volume_prev is returning me the vehicle counts hour by hour over 7 days? If so, there is some error in my code, as my volume forecast has remained "constant" throughout the 168 steps. I thank you in advance!
EDIT:
Summary of Pedagiados_modelo
Series: Volume_Treino
Regression with ARIMA(3,0,5) errors
Coefficients:
ar1 ar2 ar3 ma1 ma2 ma3 ma4 ma5 intercept
1.6672 -1.0226 0.2429 -0.1895 0.2674 0.1498 0.1148 0.0310 1441.7267
s.e. 0.0864 0.1121 0.0501 0.0866 0.0557 0.0412 0.0302 0.0251 29.5701
Feriado_Prolongado_TS Vespera_Feriado_TS Feriado_TS Dia_TS Hora_TS
136.7165 -11.7244 -38.6865 -1.4853 2.9439
s.e. 46.6111 35.8038 40.9769 1.2445 0.3418
sigma^2 estimated as 66502: log likelihood=-152668.9
AIC=305367.8 AICc=305367.9 BIC=305487.8
Training set error measures:
ME RMSE MAE MPE MAPE MASE ACF1
Training set 0.03133539 257.7965 170.8875 -7.276662 18.21747 0.3270411 0.001809384
>
Please edit your question with the output of
summary(Pedagiados_Modelo)
.– Marcus Nunes
Hello, Marcos! Including the Summary!
– Crhistian Ribeiro