How to avoid displacement of a forecast using ARIMA?

Asked

Viewed 138 times

3

I created a prediction model on R using ARIMA with a 2-year daily historical basis (2018-2019). In this model I use Multivariate Analysis to create predictions.

    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")

In this my model has 5 Variables: QTD_PED (Order Quantity) which is the main variable, FL_FDS (Days with Weekend), FL_FREE (Days with Holidays and Amendments), FL_DIA_MES (Days of the Month) and FL_DIA_SEMANA (Days of the Week) which are the secondary variables.

I generated my prediction and came up with the real values. But I realized that the predicted values and the real values had a displacement/lag between a series and another.

inserir a descrição da imagem aqui

Regarding Orders (what I want to predict) the actual quantity is lower on the weekend, but my model predicted that this low volume of orders happens on Thursday and Friday.

inserir a descrição da imagem aqui

Analyzing the predicted data I realized that my model despite having a reasonable accuracy, he could not understand which days of the week begins the month and ended up causing this displacement. I added a variable with the days of the month and the day of the week to help my model and despite improving accuracy, the model still can not get the days of the week.

My question is basically conceptual, how can I avoid this kind dislocation/ lag in my prediction? Do I enter another variable so that my algorithm understands the behavior of the variable? Or is there any other method that helps in this sense?

Follows the dput with the data:

   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, 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, 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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, 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, 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, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 
3, 4, 5, 6, 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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")
  • 2

    Sends the dput() of the data used please for we can help

  • Hi @Tomásbarcellos I’m having a hard time doing the dput. R shows me the error message: "Error in dput(dates_base, 50) : 'file' must be a Character string or Connection." I don’t know how to fix this.

  • 1

    Seria dput(head(dados_base, 50)). The dput takes only one argument. The head(x, 50) is to make the base smaller.

  • That’s true. I cheated, now it’s gone.

  • dput data is not the same model data. Example, it does not have QTD_USU and the day of the week is extended and not FL_DS, etc...

  • It’s just that when I went to create the Time Series I renamed it, but I’ll fix it to be clearer.

  • I updated the model with the variables from my database. The problems that I am having that the weekend has low level of orders, ie, with real values Saturday and Sunday have few requests, but in my forecast the days that have few orders are on Thursday and Friday. There’s this shift of days I can’t fix.

  • Error: auto.arima can only handle univariate time series. Uses the reprex to reproduce the error, please.

  • These variables are time series, I added the code to facilitate understanding.

  • Please use reprex to generate example, each time you have a different error. Now I have Error in window.default(x, ...) : 'start' cannot be after 'end' when rotating the line generating QTD_PED_teste

  • I’m trying to research Reprex, but I have no idea how to use it, I need an example.

Show 7 more comments

1 answer

2


This displacement cannot be avoided. It is an inherent feature of the ARIMA(p,d,q) models. In particular, the AR(p) models, which are part of the ARIMA(p,d,q).

ARIMA is the English acronym for Toutoregressive Integrated Moving Toverage. It is the generalization of the ARMA models(p,q) (Toutoregressive Moving Toverage), precisely to deal with the cases in which the non-stationarity of the time series occurs.

The ARMA model, in turn, is the union of two other models: the AR(p) model and the MA(q) model. Model AR(p) (i.e., the AR model of order p) has a specific formula given by

inserir a descrição da imagem aqui

Note that the X_t observation of the AR(p) model is given by the linear combination of the previous observations X_{t-1}, X_{t-2}, ..., X_{t-p}, plus a constant c plus the epsilon_t random variable. Thus, every AR(p) model will display this displacement, since the current observation is due to the linear combination of the previous observations. Wanting this not to happen when using an autoregressive model is like using the equation y = a*x + b and not wanting a straight line to appear.

As a final example, see this search done in Google Images by air model fitted values. This displacement always occurs when there is a comparison between the observed and predicted values.

  • Thank you so much for the reply @Marcos Nunes! You’re saving me once again! I have one more question, if this displacement always occurs, in the validation with the predicted and real value I can manually align?

  • 1

    I’ll answer you with another question, with options A and B. Which is more appropriate? Option A: use the Box-Jenkins method, described in 1970 and which has been standard in time series analysis for 50 years, without human interaction in numerical results or Option B: manually tamper with his results, manipulating what was obtained without deep knowledge of the mathematics behind it?

  • As a mathematician I would choose option A. So Box-Jenkins is the method that makes this fit?

  • I don’t know exactly what "fit" means in this context.

  • Sorry I’m already starting to research on Box-Jenkins. The correct word would be fit. The Box-Jenkins is the method that makes the model fit?

  • Not only the adjustment, but it also helps you decide which is the best model for the data.

  • Got it @Marcos Nunes thanks for the clarifications, I see that I still need to delve into the area of statistics and I see a need to study more about it. In another question you indicated me a book (Brockwell and Davis), but because it is in English makes it difficult for me. Do you know any other book or article that might help me?

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.