3

Criei um modelo de previsão no R usando o ARIMA com uma base histórica diária de 2 anos (2018 a 2019). Neste modelo eu uso a Análise Multivariada para criar previsões.

    dados = dados_dput

    QTD_PED_TS = as.numeric(dados[,c("QTD_PEDIDOS_PG")])
    QTD_PED_TS = ts(QTD_PED_TS, start = c(2018,1), frequency = 365)

        #Criando Série Temporais

    QTD_PED = as.numeric(dados[,c("QTD_PEDIDOS_PG")])
    QTD_PED = ts(QTD_PED, start = c(2018,1), end = c(2019,334), frequency = 365)

    FL_FDS = as.numeric(dados[,c("FL_FDS")])
    FL_FDS = ts(FL_FDS, start = c(2018,1), end = c(2019,334), frequency = 365)

    FL_DIA_SEMANA = as.numeric(dados[,c("FL_DIA_SEMANA")])
    FL_DIA_SEMANA = ts(FL_DIA_SEMANA, start = c(2018,1), end = c(2019,334), frequency = 365)

    FL_FREE = as.numeric(dados[,c("FL_FREE")])
    FL_FREE = ts(FL_FREE, start = c(2018,1), end = c(2019,334), frequency = 365)

    FL_DIA_MES = as.numeric(dados[,c("FL_DIA_MES")])
    FL_DIA_MES = ts(FL_DIA_MES, start = c(2018,1), end = c(2019,334), frequency = 365)

    #BASE TREINO E TESTE

    QTD_PED_treino = window(QTD_PED, start=c(2018,1), end=c(2019,334))
    QTD_PED_teste = window(QTD_PED, start=c(2019,334))

    #MODELO ARIMA

library(forecast)

QTD_PED_modelo = auto.arima(QTD_PED_treino, xreg = cbind(FL_FDS,FL_FREE,FL_DIA_MES,FL_DIA_SEMANA), trace = T, stepwise = T, approximation = T, seasonal = T)
QTD_PED_Prev = forecast(QTD_PED_modelo, xreg = cbind(FL_FDS,FL_FREE,FL_DIA_MES,FL_DIA_SEMANA), h = 365)

#VISUALIZAÇÃO

plot(QTD_PED_TS)
lines(QTD_PED_Prev$mean, col="red")

Nesse meu modelo possui 5 Variáveis: QTD_PED (Quantidade de Pedidos) que é a variável principal, FL_FDS (Dias com Fim de Semana), FL_FREE (Dias com Feriados e Emendas), FL_DIA_MES (Dias do Mês) e FL_DIA_SEMANA (Dias da Semana) que são as variáveis secundárias.

Eu gerei minha previsão e validei com os valores reais. Mas percebi que os valores previstos e os valores reais possuíam um deslocamento/defasagem entre uma série e outra.

inserir a descrição da imagem aqui

Em relação aos Pedidos (o que eu quero prever) a quantidade real é mais baixa no final de semana, porém o meu modelo previu que esse baixo volume de pedidos acontece na quinta e na sexta.

inserir a descrição da imagem aqui

Analisando os dados previstos percebi que o meu modelo apesar de ter uma acurácia razoável, ele não conseguiu entender quais dias da semana começa o mês e acabou causando este deslocamento. Eu acrescentei uma variável com os dias do mês e o dia da semana para ajudar meu modelo e apesar de melhorar acurácia, o modelo ainda não consegue acertar os dias da semana.

Minha dúvida é basicamente conceitual, como posso evitar esse tipo deslocamento/ defasagem na minha previsão? Insiro mais alguma variável para que meu algoritmo entenda o comportamento da variável? Ou existe algum outro método que ajuda nesse sentido?

Segue o dput com os dados:

   dados_dput = structure(list(DT_PAGTO = structure(c(1514764800, 1514851200, 
1514937600, 1515024000, 1515110400, 1515196800, 1515283200, 1515369600, 
1515456000, 1515542400, 1515628800, 1515715200, 1515801600, 1515888000, 
1515974400, 1516060800, 1516147200, 1516233600, 1516320000, 1516406400, 
1516492800, 1516579200, 1516665600, 1516752000, 1516838400, 1516924800, 
1517011200, 1517097600, 1517184000, 1517270400, 1517356800, 1517443200, 
1517529600, 1517616000, 1517702400, 1517788800, 1517875200, 1517961600, 
1518048000, 1518134400, 1518220800, 1518307200, 1518393600, 1518480000, 
1518566400, 1518652800, 1518739200, 1518825600, 1518912000, 1518998400, 
1519084800, 1519171200, 1519257600, 1519344000, 1519430400, 1519516800, 
1519603200, 1519689600, 1519776000, 1519862400, 1519948800, 1520035200, 
1520121600, 1520208000, 1520294400, 1520380800, 1520467200, 1520553600, 
1520640000, 1520726400, 1520812800, 1520899200, 1520985600, 1521072000, 
1521158400, 1521244800, 1521331200, 1521417600, 1521504000, 1521590400, 
1521676800, 1521763200, 1521849600, 1521936000, 1522022400, 1522108800, 
1522195200, 1522281600, 1522368000, 1522454400, 1522540800, 1522627200, 
1522713600, 1522800000, 1522886400, 1522972800, 1523059200, 1523145600, 
1523232000, 1523318400, 1523404800, 1523491200, 1523577600, 1523664000, 
1523750400, 1523836800, 1523923200, 1524009600, 1524096000, 1524182400, 
1524268800, 1524355200, 1524441600, 1524528000, 1524614400, 1524700800, 
1524787200, 1524873600, 1524960000, 1525046400, 1525132800, 1525219200, 
1525305600, 1525392000, 1525478400, 1525564800, 1525651200, 1525737600, 
1525824000, 1525910400, 1525996800, 1526083200, 1526169600, 1526256000, 
1526342400, 1526428800, 1526515200, 1526601600, 1526688000, 1526774400, 
1526860800, 1526947200, 1527033600, 1527120000, 1527206400, 1527292800, 
1527379200, 1527465600, 1527552000, 1527638400, 1527724800, 1527811200, 
1527897600, 1527984000, 1528070400, 1528156800, 1528243200, 1528329600, 
1528416000, 1528502400, 1528588800, 1528675200, 1528761600, 1528848000, 
1528934400, 1529020800, 1529107200, 1529193600, 1529280000, 1529366400, 
1529452800, 1529539200, 1529712000, 1529798400, 1529884800, 1529971200, 
1530057600, 1530144000, 1530230400, 1530316800, 1530403200, 1530489600, 
1530576000, 1530662400, 1530748800, 1530835200, 1530921600, 1531008000, 
1531094400, 1531180800, 1531267200, 1531353600, 1531440000, 1531526400, 
1531612800, 1531699200, 1531785600, 1531872000, 1531958400, 1532044800, 
1532131200, 1532217600, 1532304000, 1532390400, 1532476800, 1532563200, 
1532649600, 1532736000, 1532822400, 1532908800, 1532995200, 1533081600, 
1533168000, 1533254400, 1533340800, 1533427200, 1533513600, 1533600000, 
1533686400, 1533772800, 1533859200, 1533945600, 1534032000, 1534118400, 
1534204800, 1534291200, 1534377600, 1534464000, 1534550400, 1534636800, 
1534723200, 1534809600, 1534896000, 1534982400, 1535068800, 1535155200, 
1535241600, 1535328000, 1535414400, 1535500800, 1535587200, 1535673600, 
1535760000, 1535846400, 1535932800, 1536019200, 1536105600, 1536192000, 
1536278400, 1536364800, 1536451200, 1536537600, 1536624000, 1536710400, 
1536796800, 1536883200, 1536969600, 1537056000, 1537142400, 1537228800, 
1537315200, 1537401600, 1537488000, 1537574400, 1537660800, 1537747200, 
1537833600, 1537920000, 1538006400, 1538092800, 1538179200, 1538265600, 
1538352000, 1538438400, 1538524800, 1538611200, 1538697600, 1538784000, 
1538870400, 1538956800, 1539043200, 1539129600, 1539216000, 1539302400, 
1539388800, 1539475200, 1539561600, 1539648000, 1539734400, 1539820800, 
1539907200, 1539993600, 1540080000, 1540166400, 1540252800, 1540339200, 
1540425600, 1540512000, 1540598400, 1540684800, 1540771200, 1540857600, 
1540944000, 1541030400, 1541116800, 1541203200, 1541289600, 1541376000, 
1541462400, 1541548800, 1541635200, 1541721600, 1541808000, 1541894400, 
1541980800, 1542067200, 1542153600, 1542240000, 1542326400, 1542412800, 
1542499200, 1542585600, 1542672000, 1542758400, 1542844800, 1542931200, 
1543017600, 1543104000, 1543190400, 1543276800, 1543363200, 1543449600, 
1543536000, 1543622400, 1543708800, 1543795200, 1543881600, 1543968000, 
1544054400, 1544140800, 1544227200, 1544313600, 1544400000, 1544486400, 
1544572800, 1544659200, 1544745600, 1544832000, 1544918400, 1545004800, 
1545091200, 1545177600, 1545264000, 1545350400, 1545436800, 1545523200, 
1545609600, 1545696000, 1545782400, 1545868800, 1545955200, 1546041600, 
1546128000, 1546214400, 1546300800, 1546387200, 1546473600, 1546560000, 
1546646400, 1546732800, 1546819200, 1546905600, 1546992000, 1547078400, 
1547164800, 1547251200, 1547337600, 1547424000, 1547510400, 1547596800, 
1547683200, 1547769600, 1547856000, 1547942400, 1548028800, 1548115200, 
1548201600, 1548288000, 1548374400, 1548460800, 1548547200, 1548633600, 
1548720000, 1548806400, 1548892800, 1548979200, 1549065600, 1549152000, 
1549238400, 1549324800, 1549411200, 1549497600, 1549584000, 1549670400, 
1549756800, 1549843200, 1549929600, 1550016000, 1550102400, 1550188800, 
1550275200, 1550361600, 1550448000, 1550534400, 1550620800, 1550707200, 
1550793600, 1550880000, 1550966400, 1551052800, 1551139200, 1551225600, 
1551312000, 1551398400, 1551484800, 1551571200, 1551657600, 1551744000, 
1551830400, 1551916800, 1552003200, 1552089600, 1552176000, 1552262400, 
1552348800, 1552435200, 1552521600, 1552608000, 1552694400, 1552780800, 
1552867200, 1552953600, 1553040000, 1553126400, 1553212800, 1553299200, 
1553385600, 1553472000, 1553558400, 1553644800, 1553731200, 1553817600, 
1553904000, 1553990400, 1554076800, 1554163200, 1554249600, 1554336000, 
1554422400, 1554508800, 1554595200, 1554681600, 1554768000, 1554854400, 
1554940800, 1555027200, 1555113600, 1555200000, 1555286400, 1555372800, 
1555459200, 1555545600, 1555632000, 1555718400, 1555804800, 1555891200, 
1555977600, 1556064000, 1556150400, 1556236800, 1556323200, 1556409600, 
1556496000, 1556582400, 1556668800, 1556755200, 1556841600, 1556928000, 
1557014400, 1557100800, 1557187200, 1557273600, 1557360000, 1557446400, 
1557532800, 1557619200, 1557705600, 1557792000, 1557878400, 1557964800, 
1558051200, 1558137600, 1558224000, 1558310400, 1558396800, 1558483200, 
1558569600, 1558656000, 1558742400, 1558828800, 1558915200, 1559001600, 
1559088000, 1559174400, 1559260800, 1559347200, 1559433600, 1559520000, 
1559606400, 1559692800, 1559779200, 1559865600, 1559952000, 1560038400, 
1560124800, 1560211200, 1560297600, 1560384000, 1560470400, 1560556800, 
1560643200, 1560729600, 1560816000, 1560902400, 1560988800, 1561075200, 
1561161600, 1561248000, 1561334400, 1561420800, 1561507200, 1561593600, 
1561680000, 1561766400, 1561852800, 1561939200, 1562025600, 1562112000, 
1562198400, 1562284800, 1562371200, 1562457600, 1562544000, 1562630400, 
1562716800, 1562803200, 1562889600, 1562976000, 1563062400, 1563148800, 
1563235200, 1563321600, 1563408000, 1563494400, 1563580800, 1563667200, 
1563753600, 1563840000, 1563926400, 1564012800, 1564099200, 1564185600, 
1564272000, 1564358400, 1564444800, 1564531200, 1564617600, 1564704000, 
1564790400, 1564876800, 1564963200, 1565049600, 1565136000, 1565222400, 
1565308800, 1565395200, 1565481600, 1565568000, 1565654400, 1565740800, 
1565827200, 1565913600, 1.566e+09, 1566086400, 1566172800, 1566259200, 
1566345600, 1566432000, 1566518400, 1566604800, 1566691200, 1566777600, 
1566864000, 1566950400, 1567036800, 1567123200, 1567209600, 1567296000, 
1567382400, 1567468800, 1567555200, 1567641600, 1567728000, 1567814400, 
1567900800, 1567987200, 1568073600, 1568160000, 1568246400, 1568332800, 
1568419200, 1568505600, 1568592000, 1568678400, 1568764800, 1568851200, 
1568937600, 1569024000, 1569110400, 1569196800, 1569283200, 1569369600, 
1569456000, 1569542400, 1569628800, 1569715200, 1569801600, 1569888000, 
1569974400, 1570060800, 1570147200, 1570233600, 1570320000, 1570406400, 
1570492800, 1570579200, 1570665600, 1570752000, 1570838400, 1570924800, 
1571011200, 1571097600, 1571184000, 1571270400, 1571356800, 1571443200, 
1571529600, 1571616000, 1571702400, 1571788800, 1571875200, 1571961600, 
1572048000, 1572134400, 1572220800, 1572307200, 1572393600, 1572480000, 
1572566400, 1572652800, 1572739200, 1572825600, 1572912000, 1572998400, 
1573084800, 1573171200, 1573257600, 1573344000, 1573430400, 1573516800, 
1573603200, 1573689600, 1573776000, 1573862400, 1573948800, 1574035200, 
1574121600, 1574208000, 1574294400, 1574380800, 1574467200, 1574553600, 
1574640000, 1574726400, 1574812800, 1574899200, 1574985600, 1575072000, 
1575158400, 1575244800, 1575331200, 1575417600, 1575504000, 1575590400, 
1575676800, 1575763200, 1575849600, 1575936000, 1576022400, 1576108800, 
1576195200, 1576281600, 1576368000, 1576454400, 1576540800, 1576627200, 
1576713600, 1576800000, 1576886400, 1576972800, 1577059200, 1577145600, 
1577232000, 1577318400, 1577404800, 1577491200, 1577577600, 1577664000, 
1577750400, 1577836800, 1577923200, 1578009600, 1578096000, 1578182400, 
1578268800, 1578355200, 1578441600, 1578528000, 1578614400, 1578700800, 
1578787200, 1578873600, 1578960000, 1579046400, 1579132800, 1579219200, 
1579305600, 1579392000, 1579478400, 1579564800, 1579651200), class = c("POSIXct", 
"POSIXt"), tzone = "UTC"), QTD_PEDIDOS_PG = c(429, 1472, 1473, 
1404, 1432, 1326, 486, 1492, 1369, 1361, 1364, 1310, 697, 667, 
1947, 1878, 1702, 1396, 1511, 834, 737, 2059, 1934, 1739, 972, 
1465, 970, 865, 2339, 2084, 1789, 1885, 1683, 1102, 839, 2085, 
1968, 1766, 1689, 1442, 829, 638, 736, 722, 1543, 1853, 1593, 
1098, 847, 2376, 2081, 2055, 1943, 1542, 1022, 862, 2063, 2207, 
1917, 1874, 1541, 766, 634, 2029, 1731, 1660, 1591, 1439, 767, 
613, 1910, 1730, 1656, 1472, 1760, 865, 753, 2205, 1870, 1977, 
1949, 1792, 1011, 857, 2463, 2188, 1946, 1729, 495, 714, 702, 
2249, 1926, 1729, 1667, 1409, 754, 587, 1919, 1793, 1696, 1739, 
1490, 843, 741, 2080, 1880, 1994, 1885, 1570, 813, 837, 2303, 
2166, 2144, 2157, 1809, 890, 653, 1237, 828, 2169, 1763, 1371, 
795, 728, 1914, 1663, 1657, 1652, 1480, 811, 720, 2055, 1800, 
1759, 1674, 1623, 727, 124, 2435, 2087, 1974, 1778, 1713, 1095, 
1151, 2607, 2333, 1695, 786, 1158, 767, 755, 1988, 1754, 1603, 
1424, 1403, 795, 654, 1916, 1674, 1707, 1586, 1429, 764, 586, 
1995, 1751, 1760, 1635, 890, 845, 2222, 1946, 1610, 1901, 1641, 
889, 602, 1711, 1731, 1579, 1420, 1154, 736, 536, 777, 1780, 
1694, 1621, 1405, 860, 673, 1890, 1730, 1655, 1733, 1538, 942, 
840, 2101, 2044, 1902, 1942, 1723, 994, 908, 2320, 1906, 1903, 
1676, 1272, 800, 722, 1973, 1677, 1718, 1527, 1421, 825, 700, 
2024, 1866, 1681, 1688, 1494, 815, 701, 2174, 1738, 2054, 1968, 
1764, 968, 864, 2526, 2352, 2323, 2128, 1839, 974, 970, 2325, 
1838, 1774, 1557, 625, 773, 665, 2011, 1837, 1810, 1768, 1536, 
794, 882, 2174, 1976, 1965, 1821, 1765, 1058, 936, 2494, 2296, 
2183, 2077, 1759, 932, 817, 2314, 1833, 1839, 1595, 1438, 741, 
739, 1865, 1753, 1639, 1450, 656, 707, 658, 1886, 1864, 1804, 
1760, 1559, 895, 769, 2010, 2074, 1882, 1860, 1876, 893, 912, 
2424, 2137, 1777, 1483, 569, 704, 553, 1910, 1708, 1491, 1514, 
1309, 725, 649, 1794, 1664, 1479, 583, 1007, 686, 614, 1033, 
863, 2064, 1865, 1576, 857, 860, 2080, 1959, 1904, 1804, 1458, 
711, 630, 1683, 1576, 1293, 1361, 1186, 640, 636, 1687, 1466, 
1451, 1404, 1334, 808, 618, 1709, 1543, 1538, 1293, 1194, 655, 
432, 401, 365, 1135, 987, 791, 522, 365, 444, 334, 1084, 1186, 
1092, 995, 1739, 1288, 1064, 1061, 1113, 1118, 773, 640, 1443, 
1327, 1399, 1363, 1219, 702, 657, 1855, 1588, 1608, 1411, 736, 
796, 827, 2194, 2037, 1721, 1616, 1480, 786, 786, 1928, 1732, 
1638, 1589, 1362, 722, 714, 2041, 1852, 1811, 1721, 1506, 694, 
902, 2370, 2287, 1953, 2029, 1916, 1129, 1160, 2657, 2270, 1814, 
1878, 1418, 726, 573, 660, 653, 1413, 1756, 1457, 706, 731, 1871, 
1837, 1715, 1696, 1444, 768, 747, 2086, 1853, 1796, 1698, 1532, 
857, 845, 2252, 2060, 1973, 1896, 1541, 808, 777, 2150, 1761, 
1590, 1482, 1286, 646, 631, 1739, 1655, 1633, 1570, 1416, 716, 
655, 1906, 1795, 1730, 1365, 511, 642, 668, 2200, 1969, 1997, 
2007, 1771, 390, 882, 2269, 1729, 767, 1897, 1360, 665, 599, 
1749, 1488, 1419, 1444, 1223, 675, 623, 1929, 1661, 1647, 1519, 
1380, 721, 736, 2043, 1685, 1927, 1780, 1646, 845, 884, 2437, 
2217, 2024, 2041, 1803, 883, 707, 2094, 1689, 1475, 1433, 1302, 
645, 608, 1747, 1580, 1617, 1529, 1011, 800, 711, 1943, 1672, 
1488, 655, 1136, 718, 747, 2185, 1914, 1803, 1734, 1474, 781, 
684, 1864, 1554, 1488, 1198, 1153, 589, 413, 950, 616, 1552, 
1396, 1278, 764, 614, 1791, 1518, 1526, 1451, 1357, 762, 674, 
1936, 1855, 1730, 1788, 1616, 894, 821, 2188, 1954, 1856, 1653, 
1278, 652, 592, 1887, 1582, 1544, 1517, 1293, 753, 590, 1911, 
1788, 1620, 1611, 1494, 798, 706, 2001, 1746, 1695, 1807, 1582, 
865, 826, 2312, 2162, 1718, 2058, 1647, 894, 740, 2051, 1799, 
1671, 1372, 1061, 596, 578, 1886, 1634, 1536, 1557, 1430, 762, 
690, 2047, 1952, 1853, 1822, 1568, 911, 767, 2138, 2111, 2046, 
1990, 1737, 875, 700, 2156, 2055, 1712, 1587, 1379, 728, 599, 
1794, 1749, 1619, 1526, 1408, 618, 611, 1781, 1554, 1666, 1589, 
1505, 827, 613, 1935, 1817, 1897, 1936, 1794, 934, 777, 2338, 
2096, 1950, 1875, 1622, 645, 610, 2007, 1646, 1547, 1428, 1329, 
733, 586, 1748, 1660, 1634, 1443, 538, 693, 658, 1932, 1555, 
824, 1788, 1607, 835, 740, 2075, 1944, 1948, 1746, 1544, 847, 
597, 1790, 1544, 1441, 1277, 1166, 719, 529, 1592, 1392, 1467, 
1511, 1313, 778, 638, 1756, 1581, 1559, 1419, 1285, 678, 507, 
1021, 482, 370, 1005, 923, 506, 401, 735, 498, 291, 1008, 857, 
497, 555, 1554, 1315, 1318, 1329, 1183, 689, 555, 1684, 1501, 
1505, 1505, 1350, 800, 667, 1827, 1428, 1832), FL_FDS = c(0, 
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), FL_DIA_MES = c(1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 
23, 24, 25, 26, 27, 28, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 
24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 
28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 
31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 
23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 
27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 
30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 
23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 
26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 
30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 
23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 
26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 
30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
), FL_DIA_SEMANA = c(2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 
2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 
2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 
2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 
2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 
2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 
2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 
2, 3, 4, 5, 6, 7, 1, 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3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4)), row.names = c(NA, -751L), class = "data.frame")
12
  • 2
    Manda o dput() dos dados usados por favor para podemos ajudar Commented 21/01/2020 às 12:22
  • Olá @TomásBarcellos estou com dificuldades em fazer o dput. O R me mostra a mensagem de erro: "Error in dput(dados_base, 50) : 'file' must be a character string or connection." Não sei como corrigir isso. Commented 21/01/2020 às 20:20
  • 1
    Seria dput(head(dados_base, 50)). O dput recebe só um argumento. O head(x, 50) é para deixar a base menor. Commented 21/01/2020 às 20:48
  • Puts verdade. Me enrolei, agora foi. Commented 21/01/2020 às 21:02
  • Os dados do dput não são os mesmos dados do modelo. Exemplo, não tem QTD_USU e o dia da semana está por extenso e não FL_DS, etc.. Commented 22/01/2020 às 14:15

1 Resposta 1

2
+50

Não é possível evitar este deslocamento. Ele é uma característica inerente dos modelos ARIMA(p,d,q). Em particular, dos modelos AR(p), que fazem parte dos modelos ARIMA(p,d,q).

ARIMA é a sigla, em inglês, para Autoregressive Integrated Moving Average. Ele é a generalização dos modelos ARMA(p,q) (Autoregressive Moving Average), justamente para lidar com os casos em que ocorre não-estacionariedade da série temporal.

O modelo ARMA, por sua vez, é a união de outros dois modelos: o modelo AR(p) e o modelo MA(q). O modelo AR(p) (ou seja, o modelo AR de ordem p) tem uma fórmula específica, dada por

inserir a descrição da imagem aqui

Note que a observação X_t do modelo AR(p) é dada pela combinação linear das p observações anteriores X_{t-1}, X_{t-2}, ..., X_{t-p}, mais uma constante c e mais a variável aleatória epsilon_t. Dessa forma, todo modelo AR(p) vai exibir esse deslocamento, pois a observação atual é decorrente da combinação linear das p observações anteriores. Querer que isso não ocorra ao usar um modelo autorregressivo é como usar a equação y = a*x + b e não querer que apareça uma reta.

Como exemplo final, veja essa pesquisa feita no Google Imagens por ar model fitted values. Sempre ocorre este deslocamento quando há uma comparação entre os valores observados e os previstos.

8
  • Muito obrigado pela resposta @Marcos Nunes! Tu ta me salvando mais uma vez! Eu tenho mais uma pergunta, se esse deslocamento sempre ocorre, na validação com o valor previsto e real eu posso alinhar manualmente? Commented 24/01/2020 às 13:35
  • 1
    Vou te responder com outra pergunta, com opções A e B. O que é mais indicado? Opção A: usar o método Box-Jenkins, descrito em 1970 e que é padrão na análise de séries temporais há 50 anos, sem interação humana nos resultados numéricos ou Opção B: mexer manualmente nos resultados dele, manipulando o que foi obtido sem conhecimento profundo sobre a matemática que está por trás disso? Commented 24/01/2020 às 13:57
  • Como matemático escolheria a opção A. Então o Box-Jenkins é o método que faz esse encaixe? Commented 24/01/2020 às 14:00
  • Eu não sei exatamente o que significa "encaixe" neste contexto. Commented 24/01/2020 às 14:04
  • Desculpa já estou começando a pesquisar sobre Box-Jenkins. A palavra correta seria ajuste. O Box-Jenkins é o método que faz o ajuste do modelo? Commented 24/01/2020 às 14:12

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .