{"id":133,"date":"2014-04-19T16:45:54","date_gmt":"2014-04-19T16:45:54","guid":{"rendered":"http:\/\/kourentzes.com\/forecasting\/?p=133"},"modified":"2016-11-17T17:32:10","modified_gmt":"2016-11-17T17:32:10","slug":"multiple-aggregation-prediction-algorithm-mapa","status":"publish","type":"post","link":"https:\/\/kourentzes.com\/forecasting\/2014\/04\/19\/multiple-aggregation-prediction-algorithm-mapa\/","title":{"rendered":"Multiple Aggregation Prediction Algorithm (MAPA)"},"content":{"rendered":"<p>MAPA code for R is available on <a href=\"http:\/\/cran.r-project.org\/web\/packages\/MAPA\/index.html\">CRAN<\/a>.<br \/>\nAn online interactive demo of MAPA can be found <a title=\"MAPA Demo\" href=\"http:\/\/kourentzes.com\/forecasting\/mapa-demo\/\">here<\/a>.<\/p>\n<p>Here is a quick demonstration what you can do with the code. The easiest way to produce a forecast with MAPA is to use the <em>mapasimple<\/em> function.<\/p>\n<pre>&gt; mapasimple(admissions)\r\n     t+1      t+2      t+3      t+4      t+5      t+6      t+7      t+8      t+9     t+10     t+11     t+12 \r\n457438.0 446869.3 450146.7 462231.5 457512.8 467895.1 457606.0 441295.7 471611.2 454282.0 458308.0 453472.5<\/pre>\n<p>This also gives you a simple plot of the series and the forecast:<br \/>\n<a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig1_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-248 size-full aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig1_.png\" alt=\"\" width=\"400\" height=\"220\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig1_.png 620w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig1_-300x164.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><br \/>\nI can ask for a detailed view of the predicted states at each temporal aggregation level:<\/p>\n<pre>&gt; mapasimple(admissions,outplot=2,paral=2)<\/pre>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig5_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-252 size-full aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig5_.png\" alt=\"\" width=\"400\" height=\"295\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig5_.png 620w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig5_-300x221.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><br \/>\nIn this example I also used <em>paral=2<\/em>. This creates a parallel cluster, executes <em>mapasimple<\/em> and then closes the cluster. If you already have a parallel cluster running you can use <em>paral=1<\/em>.<br \/>\nUsing functions <em>mapaest<\/em> and <em>mapafor<\/em> I can have a more detailed control of the estimation and the forecasts across the different levels of temporal aggregation.<\/p>\n<pre>&gt; mapafit &lt;- mapaest(admissions,paral=2)\r\n&gt; mapafor(admissions,mapafit)<\/pre>\n<p>The first function estimates the model fit at each temporal aggregation level and also provides a visualisation of the identified <em>ETS<\/em> components.<br \/>\n<a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig2_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-249 aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig2_.png\" alt=\"mapaR.fig2\" width=\"400\" height=\"220\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig2_.png 620w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig2_-300x164.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><br \/>\nThe second function provides in- and out-of-sample forecasts. By default only one step ahead in-sample forecasts are given.<br \/>\n<a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig3_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-250 aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig3_.png\" alt=\"mapaR.fig3\" width=\"400\" height=\"220\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig3_.png 620w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig3_-300x164.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><br \/>\nThis is easy to change, for instance to 12-steps ahead:<\/p>\n<pre>&gt; mapafor(admissions,mapafit,ifh=12,fh=0)<\/pre>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig4_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-251 aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig4_.png\" alt=\"mapaR.fig4\" width=\"400\" height=\"220\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig4_.png 620w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig4_-300x164.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><br \/>\nI can stop plotting the output by setting <em>outplot=0<\/em> in any of the above functions. The functions have are several more options, allowing you to set the maximum temporal aggregation level, the type of MAPA combination, etc. Finally, the function <em>mapa<\/em> is a wrapper for both <em>mapaest<\/em> and <em>mapafor<\/em>, so these can be run with a single call.<br \/>\nSince version 1.5 of the package there are some new interesting features. The first one is to force a particular exponential smoothing model on all aggregation levels. This can be simply done by using the option <em>model<\/em>:<\/p>\n<pre>&gt; mapa(admissions,model=\"AAdN\",paral=2)<\/pre>\n<p>A nonseasonal damped trend model is fitted to the time series in this case. Since MAPA can no longer change between models and choose a simpler one, it is possible that the preselected model will have too many degrees of freedom for the aggregate version of a given series. In this case no model is fitted.<br \/>\n<a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig6_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-417 aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig6_.png\" alt=\"mapaR.fig6\" width=\"400\" height=\"220\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig6_.png 620w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig6_-150x82.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig6_-300x164.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><br \/>\nFurthermore, if a seasonal model is selected, for any aggregation levels with non=integer seasonality a non-seasonal version of that model will be fitted.<br \/>\nAnother new option is the ability to calculate empirical prediction intervals. As these require simulating forecasts for their calculation, they are computationally expensive and not provided by default. To get the 80%, 90%, 95% and 99% prediction intervals you can use:<\/p>\n<pre>&gt; mapa(admissions,conf.lvl=c(0.8,0.9,0.95,0.99),paral=2)<\/pre>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig7_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-418 size-full aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/04\/mapaR.fig7_.png\" alt=\"mapaR.fig7\" width=\"400\" height=\"220\" \/><\/a><br \/>\nFor more details about the Multiple Aggregation Prediction Algorithm (MAPA) look at the this <a title=\"Improving forecasting by estimating time series structural components across multiple frequencies\" href=\"http:\/\/kourentzes.com\/forecasting\/2014\/04\/19\/improving-forecasting-by-estimating-time-series-structural-components-across-multiple-frequencies\/\">post<\/a>.<\/p>\n<p><strong>Update<\/strong>: The MAPA package now allows modelling <a href=\"http:\/\/kourentzes.com\/forecasting\/2016\/10\/24\/mapa-package-for-r-on-github\/\">high-frequency<\/a> time series and include regressors (<a href=\"http:\/\/kourentzes.com\/forecasting\/2016\/11\/17\/mapax-available-for-r-new-mapa-package-on-cran\/\">MAPAx<\/a>).<\/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=\"Elucidate structure in intermittent demand time series\" href=\"https:\/\/kourentzes.com\/forecasting\/2020\/05\/25\/elucidate-structure-in-intermittent-demand-time-series\/\" rel=\"bookmark\">Elucidate structure in intermittent demand time series<\/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<\/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>MAPA code for R is available on CRAN. An online interactive demo of MAPA can be found here. Here is a quick demonstration what you can do with the code. The easiest way to produce a forecast with MAPA is to use the mapasimple function. &gt; mapasimple(admissions) t+1 t+2 t+3 t+4 t+5 t+6 t+7 t+8\u2026 <span class=\"read-more\"><a href=\"https:\/\/kourentzes.com\/forecasting\/2014\/04\/19\/multiple-aggregation-prediction-algorithm-mapa\/\">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":[10],"tags":[45,38,39,36],"_links":{"self":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/133"}],"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=133"}],"version-history":[{"count":0,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"wp:attachment":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/tags?post=133"}],"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. -->