{"id":459,"date":"2014-06-23T10:00:58","date_gmt":"2014-06-23T10:00:58","guid":{"rendered":"http:\/\/kourentzes.com\/forecasting\/?p=459"},"modified":"2014-12-18T10:40:54","modified_gmt":"2014-12-18T10:40:54","slug":"intermittent-demand-forecasting-package-for-r","status":"publish","type":"post","link":"https:\/\/kourentzes.com\/forecasting\/2014\/06\/23\/intermittent-demand-forecasting-package-for-r\/","title":{"rendered":"Intermittent demand forecasting package for R"},"content":{"rendered":"<p style=\"text-align: justify;\">A new package for analysing and forecasting intermittent demand time series and slow moving items has been release for R. You can download the latest version from <a href=\"http:\/\/cran.r-project.org\/web\/packages\/tsintermittent\/index.html\">CRAN<\/a>.<\/p>\n<p style=\"text-align: justify;\">The launch version contains the following functions:<\/p>\n<ul style=\"text-align: justify;\">\n<li>crost: Croston&#8217;s method and variants.<\/li>\n<li>crost.ma: Moving average with Croston&#8217;s method decomposition.<\/li>\n<li>idclass: Time series categorisation for intermittent demand.<\/li>\n<li>simID: Simulator for intermittent demand series.<\/li>\n<li>tsb: TSB (Teunter-Syntetos-Babai) method.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Two demo time series are included to try the various functions: data and data2.<\/p>\n<p style=\"text-align: justify;\">To fit Croston&#8217;s to a time series, simply use the following command:<\/p>\n<pre>&gt; crost(data)<\/pre>\n<p style=\"text-align: justify;\">The function comes with a few different options. By default it optimises model parameters and initial values using the <a title=\"On Intermittent Demand Model Optimisation and Selection\" href=\"http:\/\/kourentzes.com\/forecasting\/2014\/06\/11\/on-intermittent-demand-model-optimisation-and-selection\/\">MAR<\/a> cost function. Using the flag <em>cost<\/em> different cost functions are available. By default the smoothing parameter for the non-zero demand and demand intervals are optimised separately, but this can be controlled using the flag <em>nop<\/em>. Similarly the initialisation values for demand and intervals can be optimised or not and set either manually, or to preset initialisation heuristics. These are controlled by the flags <em>init.opt<\/em> and <em>init<\/em>.<\/p>\n<p style=\"text-align: justify;\">Three different variants of the method are implemented:<\/p>\n<ul style=\"text-align: justify;\">\n<li>\u00a0&#8216;croston&#8217;, for the original method.<\/li>\n<li>&#8216;sba&#8217;, for the Syntetos-Boylan approximation.<\/li>\n<li>&#8216;sbj&#8217;, for the Shale-Boylan-Johnston correction.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">For example, to get SBA forecasts with optimal parameters for 12 months ahead and plot the results you can use:<\/p>\n<pre>&gt; crost(data,type='sba',h=12,outplot=TRUE)<\/pre>\n<p>This will provide the following visual output:<br \/>\n<a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig1_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-460 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig1_-300x214.png\" alt=\"tsID.fig1\" width=\"300\" height=\"214\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig1_-300x214.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig1_-150x107.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig1_.png 525w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nFunctions <em>tsb<\/em> and <em>crost.ma<\/em> allow similar level of control.<\/p>\n<p style=\"text-align: justify;\">The next interesting function in the package allows you to create simulated intermittent demand series. The simulator assumes that non-zero demand arrivals follow a bernoulli distribution and the non-zero demands a negative binomial distribution. For example to create 100 simulated time series, 60 observations each, use:<\/p>\n<pre>&gt; dataset &lt;- simID(100,60,idi=1.15,cv2=0.3)<\/pre>\n<p style=\"text-align: justify;\">The two last inputs control the average demand interval and the squared coefficient of variation of the non-zero demand for the series.<\/p>\n<p style=\"text-align: justify;\">To get a better view of the generated series, or a real dataset, we can use the <em>idclass<\/em> function. This categorises the intermittent demand time series according to existing classification schemes. In particular the following are implemented:<\/p>\n<ul style=\"text-align: justify;\">\n<li>&#8216;SBC&#8217;, classification proposed by Syntetos-Boylan-Croston.<\/li>\n<li>&#8216;KH&#8217;, the revised classification by Kostenko-Hyndman using the exact separation.<\/li>\n<li>&#8216;KHa&#8217;, as above but using the approximate separation.<\/li>\n<li>&#8216;PK&#8217;, the further revised classification that deals with temporal aggregation by <a title=\"Forecast Combinations for Intermittent Demand\" href=\"http:\/\/kourentzes.com\/forecasting\/2014\/05\/13\/forecast-combinations-for-intermittent-demand\/\">Petropoulos-Kourentzes<\/a>.<\/li>\n<li>&#8216;PKa&#8217;, as above but using the approximate separation.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Both &#8216;KH&#8217; and &#8216;PK&#8217; require the demand interval smoothing parameter of SBA as input. This can either by calculated automatically by the function, or given as an input using the <em>a.in<\/em> flag.<\/p>\n<p style=\"text-align: justify;\">Finally there are two views for each classification. One summarised that merely provides the number of time series the class\/method or a detailed one that provides a scatterplot of the time series characteristics. Here are some examples:<\/p>\n<pre>&gt; idclass(t(dataset))<\/pre>\n<p>This gives by default the PKa classification.<br \/>\n<a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig2_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-461 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig2_-300x214.png\" alt=\"tsID.fig2\" width=\"300\" height=\"214\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig2_-300x214.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig2_-150x107.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig2_.png 525w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>&gt; idclass(t(dataset),type='SBC')<\/pre>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig3_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-465 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig3_-300x214.png\" alt=\"tsID.fig3\" width=\"300\" height=\"214\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig3_-300x214.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig3_-150x107.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig3_.png 525w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>&gt; idclass(t(dataset),type='KHa')<\/pre>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig4_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-467 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig4_-300x214.png\" alt=\"tsID.fig4\" width=\"300\" height=\"214\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig4_-300x214.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig4_-150x107.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig4_.png 525w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>&gt; idclass(t(dataset),type='PK',outplot='detail')<\/pre>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig5_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-464 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig5_-300x214.png\" alt=\"tsID.fig5\" width=\"300\" height=\"214\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig5_-300x214.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig5_-150x107.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/2014\/06\/tsID.fig5_.png 525w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nNote that the PK and KH exact classifications, unless the smoothing parameters are provided, can be computationally expensive.<\/p>\n<p style=\"text-align: justify;\">More information about the various optimisation cost functions for these intermittent demand methods and the classification schemes can be found <a title=\"On Intermittent Demand Model Optimisation and Selection\" href=\"http:\/\/kourentzes.com\/forecasting\/2014\/06\/11\/on-intermittent-demand-model-optimisation-and-selection\/\">here<\/a> and <a title=\"Forecast Combinations for Intermittent Demand\" href=\"http:\/\/kourentzes.com\/forecasting\/2014\/05\/13\/forecast-combinations-for-intermittent-demand\/\">here<\/a>. An interactive demo of various functions and optimisation options can be found <a title=\"Choosing parameters for Croston\u2019s method and its variants\" href=\"http:\/\/kourentzes.com\/forecasting\/2014\/08\/05\/choosing-parameters-for-crostons-method-and-its-variants\/\">here<\/a>.<\/p>\n<div class=\"SPOSTARBUST-Related-Posts\"><H3>Related Posts<\/H3><ul class=\"entry-meta\"><li class=\"SPOSTARBUST-Related-Post\"><a title=\"Intermittent demand &#038; THieF &#8211; EJOR Editors\u2019 Choice Articles\" href=\"https:\/\/kourentzes.com\/forecasting\/2020\/06\/08\/intermittent-demand-thief-ejor-editors-choice-articles\/\" rel=\"bookmark\">Intermittent demand &#038; THieF &#8211; EJOR Editors\u2019 Choice Articles<\/a><\/li>\n<li class=\"SPOSTARBUST-Related-Post\"><a title=\"Automatic robust estimation for exponential smoothing: perspectives from statistics and machine learning\" href=\"https:\/\/kourentzes.com\/forecasting\/2020\/06\/04\/automatic-robust-estimation-for-exponential-smoothing-perspectives-from-statistics-and-machine-learning\/\" rel=\"bookmark\">Automatic robust estimation for exponential smoothing: perspectives from statistics and machine learning<\/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<\/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>A new package for analysing and forecasting intermittent demand time series and slow moving items has been release for R. You can download the latest version from CRAN. The launch version contains the following functions: crost: Croston&#8217;s method and variants. crost.ma: Moving average with Croston&#8217;s method decomposition. idclass: Time series categorisation for intermittent demand. simID:\u2026 <span class=\"read-more\"><a href=\"https:\/\/kourentzes.com\/forecasting\/2014\/06\/23\/intermittent-demand-forecasting-package-for-r\/\">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,54,22,23,39],"_links":{"self":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/459"}],"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=459"}],"version-history":[{"count":0,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/459\/revisions"}],"wp:attachment":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/media?parent=459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/categories?post=459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/tags?post=459"}],"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. -->