{"id":1155,"date":"2016-10-24T08:10:01","date_gmt":"2016-10-24T08:10:01","guid":{"rendered":"http:\/\/kourentzes.com\/forecasting\/?p=1155"},"modified":"2016-10-24T08:10:01","modified_gmt":"2016-10-24T08:10:01","slug":"mapa-package-for-r-on-github","status":"publish","type":"post","link":"https:\/\/kourentzes.com\/forecasting\/2016\/10\/24\/mapa-package-for-r-on-github\/","title":{"rendered":"MAPA package for R on GitHub"},"content":{"rendered":"<p style=\"text-align: justify;\">Here is the link: <a href=\"https:\/\/github.com\/trnnick\/mapa\" target=\"_blank\">https:\/\/github.com\/trnnick\/mapa<\/a><\/p>\n<p style=\"text-align: justify;\">It has been a long time I wanted to rework the MAPA package for R, but I could not find the time. Finally I got around starting it. There are three objectives in this:<\/p>\n<ol style=\"text-align: justify;\">\n<li>Clean up code and introduce S3methods. MAPA was the first package that I wrote!<\/li>\n<li>Incorporate the <code>es<\/code> exponential smoothing implementation from the <code>smooth<\/code> package. This is an alternative to <code>ets<\/code> that will remain as the default. It allows longer seasonal cycles and some additional customisation in the specification of the exponential smoothing models.<\/li>\n<li>Implement <a href=\"http:\/\/kourentzes.com\/forecasting\/2015\/09\/08\/forecasting-with-multivariate-temporal-aggregation-the-case-of-promotional-modelling\/\">MAPAx<\/a> that permits introducting exogenous variables to MAPA.<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Tidying up the code is an ever-ongoing process, so (1) will never finish! I have already sorted (2) out and the next task is to work on (3). You can grab the development version on <a href=\"https:\/\/github.com\/trnnick\/mapa\" target=\"_blank\">GitHub<\/a>. At the time of writing you will need the development version of <a href=\"https:\/\/github.com\/trnnick\/smooth\" target=\"_blank\"><code>smooth<\/code><\/a> for this to work, on which <a href=\"http:\/\/forecasting.svetunkov.ru\/en\/author\/config\/\" target=\"_blank\">Ivan<\/a> has been ironing out a few peculiar bugs that MAPA brought to surface. You will be amazed how much temporal aggregation can mess up otherwise stable code!<\/p>\n<p style=\"text-align: justify;\">Here is a sneak peak of things you could not do with MAPA before:<\/p>\n<pre>mapafit &lt;- mapaest(taylor,ppy=336,type=\"es\")\r\nplot(mapafit)\r\n<\/pre>\n<div id=\"attachment_1156\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1.png\"><img aria-describedby=\"caption-attachment-1156\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-1156\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1.png\" alt=\"mgit_fig1\" width=\"800\" height=\"222\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1.png 1800w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1-150x42.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1-300x83.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1-768x213.png 768w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1-1024x284.png 1024w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig1-660x183.png 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-1156\" class=\"wp-caption-text\">Fig. 1: Look at all these aggregation levels!<\/p><\/div>\n<p style=\"text-align: justify;\">The new argument is <code>type=\"es\"<\/code> that lets MAPA know what exponential smoothing implementation to use. Once the estimation is done we can use this to forecast as usual.<\/p>\n<pre>mapacalc(taylor,mapafit,comb=\"wght\",outplot=2)<\/pre>\n<div id=\"attachment_1157\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2.png\"><img aria-describedby=\"caption-attachment-1157\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-1157\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2.png\" alt=\"mgit_fig2\" width=\"500\" height=\"250\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2.png 1200w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2-150x75.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2-300x150.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2-768x384.png 768w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2-1024x512.png 1024w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2016\/10\/mgit_fig2-660x330.png 660w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><p id=\"caption-attachment-1157\" class=\"wp-caption-text\">Fig. 2: MAPA for high frequency data!<\/p><\/div>\n<p style=\"text-align: justify;\">So finally we can now easily use MAPA for series with seasonality more than 24 periods! You may have observed that I am using a different combination of the temporal aggregation states: <code>wght<\/code>. This is still experimental, so use it at your own risk! I would still recommend using either <code>median<\/code> or <code>mean<\/code>.<\/p>\n<p style=\"text-align: justify;\">Another nice feature that the <code>es<\/code> implementation offers is more flexibility in specifying models. Before we could use the <code>model=\"ZZZ\"<\/code> to let <code>ets<\/code> select the best model for each aggregation level. Now we can use the letters <code>X<\/code> and <code>Y<\/code> to restrict the search to only additive or\u00a0 multiplicative options (including <code>N<\/code>) respectively. So for example we could set <code>model=\"ZXA\"<\/code> to have MAPA look for exponential smoothing models with any type of error, trend that can be none, additive or damped additive and additive seasonality.<\/p>\n<p style=\"text-align: justify;\">Which of <code>ets<\/code> or <code>es<\/code> is most accurate to use with MAPA? This is a difficult question to answer. In different examples I tried, I got different results, but there are a few things I can point out. <code>ets<\/code> from the <code>forecast<\/code> package by default does not allow multiplicative trends. This was done as using only additive trends seems to work better for <code>ets<\/code>. This is not the case for <code>es<\/code> that considers all possible trends. In the current MAPA implementation you can use the argument <code>allow.multiplicative.trend=TRUE<\/code> to make <code>ets<\/code> consider all trends. Similarly, with <code>es<\/code> you can use <code>model=\"ZXZ\"<\/code> to restrict it to additive trends. On the M3 dataset, once the specification is identical (only additive trends) <code>es<\/code> based MAPA performs about 5% worse than <code>ets<\/code> based MAPA, which is fairly small difference, with no evidence of statistically significant differences. So my recommendation is as follows: MAPA with <code>ets<\/code> works fine and is the default core, but if the additional flexibility of <code>es<\/code> is needed, feel confident in using it!<\/p>\n<div class=\"SPOSTARBUST-Related-Posts\"><H3>Related Posts<\/H3><ul class=\"entry-meta\"><li class=\"SPOSTARBUST-Related-Post\"><a title=\"Special issue on innovations in hierarchical forecasting\" href=\"https:\/\/kourentzes.com\/forecasting\/2020\/10\/25\/special-issue-on-innovations-in-hierarchical-forecasting\/\" rel=\"bookmark\">Special issue on innovations in hierarchical forecasting<\/a><\/li>\n<li class=\"SPOSTARBUST-Related-Post\"><a title=\"Cross-temporal aggregation: Improving the forecast accuracy of hierarchical electricity consumption\" href=\"https:\/\/kourentzes.com\/forecasting\/2020\/05\/25\/cross-temporal-aggregation-improving-the-forecast-accuracy-of-hierarchical-electricity-consumption\/\" rel=\"bookmark\">Cross-temporal aggregation: Improving the forecast accuracy of hierarchical electricity consumption<\/a><\/li>\n<li class=\"SPOSTARBUST-Related-Post\"><a title=\"Tutorial for the nnfor R package\" href=\"https:\/\/kourentzes.com\/forecasting\/2019\/01\/16\/tutorial-for-the-nnfor-r-package\/\" rel=\"bookmark\">Tutorial for the nnfor R package<\/a><\/li>\n<\/ul><\/div><!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Here is the link: https:\/\/github.com\/trnnick\/mapa It has been a long time I wanted to rework the MAPA package for R, but I could not find the time. Finally I got around starting it. There are three objectives in this: Clean up code and introduce S3methods. MAPA was the first package that I wrote! Incorporate the\u2026 <span class=\"read-more\"><a href=\"https:\/\/kourentzes.com\/forecasting\/2016\/10\/24\/mapa-package-for-r-on-github\/\">Read More &raquo;<\/a><\/span><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[41],"tags":[45,15,38,39],"_links":{"self":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/1155"}],"collection":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/comments?post=1155"}],"version-history":[{"count":0,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/1155\/revisions"}],"wp:attachment":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/media?parent=1155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/categories?post=1155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/tags?post=1155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->