Search code examples
rarimaforecast

R ARIMA Average Monthly Forecast geom_forecast


Similar to the questions here, here and here I am trying to plot the ARIMA model forecasting via geom_forecast for average monthly data for 42 years. But, no matter what method I try, I can't seem to get wiggles (expectation) in my forecasting, so maybe I am doing something wrong or maybe one of the following outputs is correct and I am just reading it incorrectly.

The purpose is to forecast for the next 10 years considering each of the 12 months for every year.

How can I do this?

Data (AvgTMeanMYTS):

structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 
6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 
9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 
1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 
2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 1980, 
1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 
1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 
2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 1980, 1981, 1982, 
1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 
1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 
2016, 2017, 2018, 2019, 2020, 2021, 1980, 1981, 1982, 1983, 1984, 
1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 
2018, 2019, 2020, 2021, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 
1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 
2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 
2020, 2021, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 
1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 
2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 
1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 
1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 
2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 1980, 1981, 
1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 
1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 
2015, 2016, 2017, 2018, 2019, 2020, 2021, 1980, 1981, 1982, 1983, 
1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 
2017, 2018, 2019, 2020, 2021, 1980, 1981, 1982, 1983, 1984, 1985, 
1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 
1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 
2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 
2019, 2020, 2021, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 
2021, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 
1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 
2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 19.5234148089655, 
15.0366903831034, 19.5392940460345, 19.0978801331034, 18.9825869596552, 
16.6811386634483, 18.5066560548276, 19.2956733698276, 20.0643974172414, 
22.4810527272414, 22.6210526763793, 22.4206389058621, 19.0881733396552, 
22.3737596315517, 20.4387596065517, 19.19941478, 19.4748974167241, 
20.261535447069, 20.759914727069, 20.7351043962069, 19.6209664506897, 
16.2958110941379, 19.9926732817241, 16.4404491394828, 18.7724318994828, 
19.6738629836207, 19.8275872922414, 21.8777424060345, 20.0689664051724, 
18.9992596196552, 16.59275933, 18.3989836922414, 19.4371904836207, 
22.1457596153448, 19.3794838155172, 20.8792768344828, 19.2305699046552, 
20.8842079222414, 18.744259472931, 19.3601735217241, 20.813638885, 
19.5074598377586, 17.3716212965517, 20.0332077944828, 23.1299493063793, 
19.4617424010345, 20.4595008717241, 20.244794155, 21.0837078758621, 
20.8405180641379, 19.8091216910345, 21.1094838181034, 22.9663631174138, 
20.8937079337931, 20.8812768218966, 19.7623801396552, 22.3103285817241, 
19.3778286634483, 18.8863456658621, 23.06451837, 20.1062595110345, 
20.3945353610345, 20.1511387991379, 22.7304837127586, 20.5541562377586, 
21.6235008894828, 20.9550355386207, 19.4482768815517, 18.9642421794828, 
19.6347766418966, 22.4174319960345, 18.7314837224138, 16.7035868743103, 
21.1463112003448, 21.8351389125862, 21.0177251546552, 22.9037424284483, 
19.1483629487931, 19.2036044022414, 22.3285528051724, 23.6532596712069, 
23.240966632069, 21.8478443867241, 22.7852374441379, 22.4606217015517, 
20.183466517069, 23.5448460084483, 19.975880227931, 21.4716561087931, 
22.7356217806897, 20.6343285787931, 21.9705009465517, 21.5662079184483, 
22.6853114493103, 22.9527422810345, 23.0049492741379, 21.318311297069, 
20.7341733467241, 22.7557079708621, 22.5793113382759, 20.2714319882759, 
24.5957252239655, 20.2146561067241, 20.7979148996552, 23.3620011232759, 
22.4483458748276, 23.0763630375862, 25.6045529267241, 22.2922595777586, 
21.2266559605172, 21.6622423631034, 22.3749666539655, 22.5084320263793, 
21.3816045555172, 18.2155526258621, 22.2718975131034, 23.414139057069, 
18.8383284601724, 22.1790527146552, 24.4159150612069, 23.9225699977586, 
22.2889147463793, 20.8810354106897, 22.4923803393103, 23.7941822177586, 
22.9678650234483, 23.9591218689655, 24.4570700875862, 25.34286328, 
22.4109836441379, 23.2791218593103, 23.5636908431034, 22.6530870893103, 
21.3028286567241, 24.3380528808621, 24.3847425065517, 23.7251389272414, 
25.2739838572414, 22.9420182460345, 22.7761389306897, 25.0779838562069, 
25.1714150324138, 23.4838631406897, 24.0932079513793, 23.8361906515517, 
24.8867597577586, 23.5647425482759, 23.6907597577586, 25.3781391344828, 
23.3686045613793, 22.9672079746552, 22.1086735227586, 24.5475356991379, 
23.1211045693103, 23.80146658, 23.9823114463793, 23.3642423565517, 
26.0613805184483, 23.5376045293103, 24.7732942844828, 24.6526391260345, 
26.4082598517241, 24.5554321548276, 25.0216047348276, 24.6478287931035, 
24.8998942536207, 26.781771857069, 24.4313959913793, 26.0892252432759, 
25.8896390986207, 25.4137426243103, 25.7815529074138, 25.9859667801724, 
26.1187253162069, 25.7864493672414, 25.8446217898276, 25.1878115562069, 
26.1233804967241, 26.1724840360345, 27.0302599546552, 24.4233631263793, 
25.5100700768966, 26.7858632184483, 27.811673722931, 26.3336563439655, 
26.4555184927586, 26.4807426846552, 25.5774667025862, 26.42888056, 
25.0461217943103, 26.7652943705172, 27.1714667951724, 25.9051220665517, 
25.659742552931, 25.7077424936207, 25.2542597677586, 26.5976392155172, 
25.8413286543103, 27.068139175, 26.6647771643103, 25.9372081431034, 
25.5426046103448, 26.3741909224138, 26.4974667118966, 26.4422598544828, 
27.1561564086207, 25.7564839339655, 26.8498959375862, 25.6893097122414, 
26.6419216353448, 27.7962599124138, 28.2913978512069, 27.6681564927586, 
27.409139172931, 26.8181736386207, 28.0509151262069, 27.3267081684483, 
28.3309495851724, 27.3919322574138, 27.5564495613793, 27.7155012262069, 
28.087553122931, 27.3101392618966, 27.6276736091379, 28.4914838856897, 
27.6942944037931, 27.2662254537931, 27.8348633006897, 29.1696393241379, 
26.5736219474138, 27.6102082812069, 27.7674669065517, 26.9373978587931, 
27.818294295, 28.6165531091379, 27.0563459725862, 27.722208155, 
26.7952427703448, 28.0425875760345, 27.8446392186207, 29.3741565574138, 
28.3941737206897, 27.7194496682759, 28.0779667886207, 27.048328892931, 
28.2497426067241, 28.5273116208621, 27.8117771805172, 28.1947944253448, 
28.5293578448276, 28.1200182682759, 27.6098078365517, 28.5288117181034, 
28.9119324191379, 28.5291737846552, 28.8811049296552, 27.9429151274138, 
27.4544839856897, 28.2430703063793, 28.914518552931, 28.2676393248276, 
28.1170702305172, 28.2393116786207, 28.7065358984483, 28.7822254772414, 
28.8033807681034, 28.3555531658621, 28.3212255612069, 28.865639192931, 
28.8368634846552, 29.1408807160345, 28.348277157931, 28.4560876386207, 
27.9212252848276, 28.1722944193103, 28.5972944456897, 28.5663116722414, 
29.2512600343103, 27.8561220501724, 28.389484077069, 27.941052962069, 
28.5000186786207, 29.4781737822414, 28.7937427705172, 28.216915097931, 
27.8123632953448, 28.4043979639655, 29.2174324494828, 29.4048116613793, 
29.1284153051724, 28.8606393748276, 29.0871406098276, 28.6258974077586, 
28.2848734694828, 28.7113806953448, 28.2356220110345, 28.6213980048276, 
28.5743632484483, 28.3699496701724, 28.5225185534483, 28.7040186910345, 
29.468966977931, 28.3327082936207, 28.4458979908621, 28.6057254851724, 
29.0184150893103, 28.407466822069, 28.6567598874138, 27.9688977868966, 
28.589346162069, 28.1792254613793, 28.83467375, 29.291466877069, 
28.4688979841379, 28.6432428032759, 28.6119323598276, 28.6189669575862, 
28.1613117082759, 28.6550702717241, 29.0741393651724, 28.4793460786207, 
29.2086738056897, 28.6869496637931, 29.1081565660345, 29.337329107931, 
29.1090357222414, 28.6691565346552, 28.7326565774138, 29.0297771975862, 
29.2930702998276, 28.8705703798276, 28.8166910037931, 28.6686392491379, 
28.7605423765517, 29.4544560986207, 28.99168544, 28.0121392546552, 
27.5890701234483, 27.9629669198276, 27.7423806355172, 27.1558805662069, 
27.2871219043103, 28.3769668710345, 28.4299840925862, 28.7066737539655, 
28.5235358589655, 28.2323805710345, 28.0190874958621, 27.9419496474138, 
28.0633979003448, 27.6105531822414, 28.5143978841379, 28.305191172069, 
27.5264323337931, 28.4792599186207, 27.556156487069, 28.2293462096552, 
27.5556564656897, 28.3530013639655, 28.122311822931, 28.1180185122414, 
28.287311717931, 27.9968290331034, 28.1326220284483, 28.2644324141379, 
28.1865185705172, 28.3579496837931, 28.3689670234483, 27.6532253401724, 
27.8185013731034, 27.8663461946552, 28.5898808113793, 28.3556564594828, 
28.653570372069, 28.3749496196552, 28.8238527031034, 28.4812406346552, 
27.9539353932759, 26.6943634293103, 26.5870529377586, 25.3577597384483, 
26.4269495336207, 25.6849495127586, 27.2447599541379, 26.942035707931, 
25.2685529772414, 25.8693804903448, 25.7020184744828, 26.7748978387931, 
26.1649150189655, 25.6515356593103, 26.4973459906897, 26.5133288156897, 
27.4164668115517, 25.6728116074138, 25.685363242931, 26.899087412931, 
25.8395357794828, 25.1666390317241, 25.8519839258621, 27.3024839856897, 
26.9371564803448, 25.937380527069, 26.2282599415517, 26.0855183439655, 
27.4245875458621, 25.3618805332759, 27.0875530244828, 25.6910873937931, 
25.2798286303448, 25.8630528936207, 26.4526737482759, 26.1230184293103, 
27.0892427058621, 26.3437081698276, 26.0252599384483, 27.4703633862069, 
27.9582045001724, 27.4609889982759, 26.7818941241379, 23.0714839084483, 
21.62562173, 23.9744665868966, 22.5804838641379, 21.8865699763793, 
24.6331907796552, 26.2893633353448, 24.1835528739655, 24.4934148132759, 
23.8964321856897, 23.5875355293103, 22.137690707931, 24.5104149465517, 
23.8344839356897, 24.7481044574138, 22.4549319822414, 23.345070017069, 
23.252139025, 24.0351389851724, 23.1180354481034, 22.4232422736207, 
22.8676734462069, 22.372587237069, 24.1060355941379, 23.5168286682759, 
23.6845700163793, 21.836242347069, 23.069742367069, 21.0660183018966, 
23.3808630906897, 22.4157940436207, 23.4583113439655, 20.861604492931, 
24.4649321125862, 21.9254837034483, 25.9717081332759, 23.188742407931, 
23.701518222931, 24.3004322048276, 23.3279805351724, 25.0533769541379, 
22.2203546391379, 19.0223803691379, 19.7827769644828, 22.0487423605172, 
21.5309493624138, 21.8489322005172, 19.1200181041379, 22.9332941315517, 
21.0568112998276, 20.972363077069, 17.7882593415517, 22.1202079181034, 
21.7630009493103, 21.1251561067241, 19.8691045168966, 21.9340354331034, 
19.2758110634483, 20.9055527327586, 20.6538975153448, 22.5218802489655, 
20.5432250584483, 20.3242940248276, 22.363328605, 20.292432027931, 
18.741759497069, 19.801621635, 19.683259537069, 22.7950182287931, 
22.7994665937931, 21.1325009437931, 21.4851216610345, 15.1932765212069, 
22.0281043222414, 21.3982596236207, 23.4489493534483, 21.0453975941379, 
24.9554493343103, 24.1170529, 20.6785010305172, 21.3142251315517, 
22.1351838937931, 19.3360494739655, 22.7316958656897), .Dim = c(504L, 
3L), .Dimnames = list(NULL, c("month", "year", "AvgTMean")), .Tsp = c(1, 
504, 1), class = c("mts", "ts", "matrix"))

Method 1 :

# Run auto.arima on a single ts
arima_fit = auto.arima(AvgTMeanMYTS[,3], D = 1) # D = 1 is being used to pickup monthly variations 

#dput(AvgTMeanMYTS)

# Forecast for the next 10 years (2030)
arima_forecast = forecast(arima_fit, h = 12)

# Plot forecasts
autoplot(arima_forecast) + geom_forecast() # Doesn't show years on y-axis

Output:

enter image description here

Method 2:

AvgTMeanMYModel = arima(AvgTMeanMYTS[,3])
fcst  = forecast(AvgTMeanMYModel, h = 12)
autoplot(fcst)

Output:

enter image description here

Method 3:

plot(forecast(arima_fit, frequency = 12, D = 1, h = 12))

Output:

enter image description here


Solution

  • Actually, your line is not completely straight. If we zoom in you can see that:

    library(forecast)
    arima_fit = auto.arima(AvgTMeanMYTS[,3], D = 1) 
    arima_forecast = forecast(arima_fit, h = 12)
    autoplot(arima_forecast) + 
      geom_forecast() +
      coord_cartesian(xlim=c(500, 520))
    

    Output:

    enter image description here

    As you can see the line is at the start not completely straight. This is because the signal is very weak. I would suggest to have a look at this post which describes very good why this happens: https://stats.stackexchange.com/questions/388502/daily-data-r-forecasts-only-yield-straight-line