<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/error-trend-seasonality-ets-and-its-forecast-model-friends/"></div></div><div><a data-url="https://www.r-bloggers.com/error-trend-seasonality-ets-and-its-forecast-model-friends/" data-counturl="https://www.r-bloggers.com/error-trend-seasonality-ets-and-its-forecast-model-friends/" data-count="horizontal" data-text="Error, trend, seasonality –  ets and its forecast model friends" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://ellisp.github.io/blog/2016/11/27/ets-friends"> Peter's stats stuff - R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>A broad family of fast and effective forecast methods</h2>
<p><a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Exponential_smoothing">Exponential smoothing state space</a> methods constitute a broad family of approaches to univariate time series forecasting that have been around for many decades and only in the twenty-first century placed into a systematic framework. The definitive book on the subject is Hyndman, Koehler, Ord and Snyder’s <a target="_blank" rel="nofollow" href="http://www.exponentialsmoothing.net/">Forecasting with Exponential Smoothing: The State Space Approach</a>. Well known models such as <a target="_blank" rel="nofollow" href="https://www.otexts.org/fpp/7/1">simple or single exponential smoothing</a>, Holt’s linear trend method (ingeniously implemented here <a target="_blank" rel="nofollow" href="http://www.real-statistics.com/time-series-analysis/basic-time-series-forecasting/holt-linear-trend/">in Excel</a> – these methods are popular in the business world where better tools are often not used) and <a target="_blank" rel="nofollow" href="https://www.otexts.org/fpp/7/5">the Holt-Winters seasonal method</a> can be shown to be special cases of a single family.</p>
<p>A simple must-read in this space is the <a target="_blank" rel="nofollow" href="https://www.otexts.org/fpp/7/6">taxonomy of exponential smoothing methods</a> in Hyndman and Athanasopolous’ <em>Forecasting Principles and Practice</em>. Their taxonomy is based on characterising each model against three dimensions: error, trend and seasonality (hence the function that implements these models is <code>ets</code> in the <code>forecast</code> package). Each of those three can be characteristised as “additive”, “multiplicative”, or “none”. From the ets helpfile:</p>
<blockquote>
<p><code>model</code>: Usually a three-character string identifying method using the framework terminology of Hyndman et al. (2002) and Hyndman et al. (2008). The first letter denotes the error type (“A”, “M” or “Z”); the second letter denotes the trend type (“N”,”A”,”M” or “Z”); and the third letter denotes the season type (“N”,”A”,”M” or “Z”). In all cases, “N”=none, “A”=additive, “M”=multiplicative and “Z”=automatically selected. So, for example, “ANN” is simple exponential smoothing with additive errors, “MAM” is multiplicative Holt-Winters’ method with multiplicative errors, and so on.</p>
</blockquote>
<p>By taking a fully general approach, <code>ets</code> is able to make the most of all of the members of its family and automatically choose the most effective method for a given dataset.</p>
<h2>Three relatives</h2>
<p>I wanted to get my head around the performance with seasonal data of two close relatives of <code>ets</code>: <code>stlm</code> and <code>thetaf</code>, Hyndman’s implementation of the successful <a target="_blank" rel="nofollow" href="https://www.google.co.nz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&cad=rja&uact=8&ved=0ahUKEwi2i-3NxsnQAhWDF5QKHdw7A-YQFgg5MAQ&url=https%3A%2F%2Fwww.researchgate.net%2Fpublication%2F223049702_The_theta_model_A_decomposition_approach_to_forecasting&usg=AFQjCNGN1PCpPDu5KSMWzHvNbhDFYLQofw&sig2=cdBAHctXx8kd2eVsDPXgLQ">Theta decomposition method of forecasting</a>.</p>
<p>After the Theta method made a name for itself in the forecasting competition world as a complex new algorithm, Hyndman and Billah <a target="_blank" rel="nofollow" href="http://www.robjhyndman.com/papers/Theta.pdf">successfully showed</a> that it could be seen as yet another special case of an exponential smoothing model with drift. Both the <code>thetaf</code> and <code>stlm</code> methods, in Hyndman’s <code>forecast</code> package, work by first seasonally adjusting a series, then applying a type of exponential smoothing model to it. The original Theta method <a target="_blank" rel="nofollow" href="http://stats.stackexchange.com/questions/67036/does-thetaf-in-the-forecast-package-in-r-detect-seasonality">did not detect seasonality</a>, but Hyndman’s more recent implementations of it do.</p>
<p>Because Hyndman’s <code>forecast</code> package is open source, we can inspect the <a target="_blank" rel="nofollow" href="https://github.com/robjhyndman/forecast/tree/master/R">source code</a> to be sure the functions are doing what we think they are. Here are the three functions I’m looking at:</p>
<ul>
<li><code>ets</code> The most general and flexible version. Models error, trend and seasonal elements together.</li>
<li><code>stlm</code> Seasonal adjustment via <code>stl</code> (Cleveland-style loess); then a non-seasonal <code>ets</code> model (ie just error and trend terms); then re-seasonalise.</li>
<li><code>thetaf</code> Seasonal adjustment via <code>decomp</code> (classical multiplicative seasonal decomposition); <code>ets</code> with just an additive model (no trend or seasonality); estimate trend/drift by an adjusted form of linear regression of the seasonally adjusted variable against time.</li>
</ul>
<p>One way of looking at this is that <code>ets</code> uses exponential smoothing for all three of error, trend and seasonal; <code>stlm</code> for just error and trend; and <code>thetaf</code> for just error. <code>stlm</code> and <code>thetaf</code> bring in other methods for dealing with the seasonal and trend elements.</p>
<p>Here are those three methods in action against one of the example monthly data sets from the <a target="_blank" rel="nofollow" href="http://ellisp.github.io/blog/2016/10/19/Tcomp">2010 Tourism Forecasting Competition</a>.</p>
<p><img alt="eg1" src="http://ellisp.github.io/img/0070-eg1.svg"></p>
<p>We see from the plot titles in this example that the <code>ets</code> approach detects additive error and seasonal structures; whereas the <code>stlm</code> approach first removes the seasonality, so what is left is simply additive error. None of the methods is good at picking up the subtle upwards trend and they all slightly underestimate the forward values of the series, albeit with good prediction interval coverage.</p>
<p>Here’s a second example, this time a quarterly series:</p>
<p><img alt="eg2" src="http://ellisp.github.io/img/0070-eg2.svg"></p>
<p>In this case, multiplicative error and seasonal components are detected in the original data.</p>
<h2>A systematic comparison</h2>
<p>To get a more systematic view on which of these variants of methods is most effective with seasonal data of the sort I mostly deal with, I ran an experiment. I used all three methods against each of the quarterly and monthly series in the 2010 tourism forecasting competition and the 1982 “M1” forecasting competition from Makridakis et al. This constitutes well over a thousand time series in total. I calculated the mean absolute scaled error (MASE) of the forecasts against the actual future data. Here’s the distribution of those values of MASE:</p>
<p><img alt="density" src="http://ellisp.github.io/img/0070-density.svg"></p>
<p>Easier to take in than all those individual values of MASE is a summary statistic. Here’s the trimmed mean:<br>
<img alt="trmean" src="http://ellisp.github.io/img/0070-trmean.svg"></p>
<p>The Theta method stands out as not as consistently accurate as either <code>ets</code> or <code>stlm</code> and there is little to tell the two apart. But here is the mean:</p>
<p><img alt="mean" src="http://ellisp.github.io/img/0070-mean.svg"></p>
<p>All three methods obviously generated a few poor values of MASE that drag their untrimmed mean scores up. Those pesky, hard to predict real datasets… Mostly but not always <code>stlm</code> appears a bit better than <code>ets</code>, which might suggest that it is a good idea to seasonally adjust the data before fitting an exponential smoothing model to it – but there isn’t much in it. <code>thetaf</code> does seem to be systematically outperformed by its more general and flexible cousins with this seasonal data. We can’t tell from this whether it is the simple seasonal adjustment method used in <code>thetaf</code> that is responsible or the Theta method itself; my suspicion is with the seasonal adjustment. Classical decomposition is a less flexible method than the rolling window smoothing approach used by <code>stl</code>, which is able to pick up changes in seasonality over time.</p>
<p>Here’s the code that produces all the above examples and runs the tests against the competition data:</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>ggplot2</span><span>)</span><span>
</span><span>library</span><span>(</span><span>forecast</span><span>)</span><span>
</span><span>library</span><span>(</span><span>Tcomp</span><span>)</span><span>
</span><span>library</span><span>(</span><span>doParallel</span><span>)</span><span>
</span><span>library</span><span>(</span><span>dplyr</span><span>)</span><span>
</span><span>library</span><span>(</span><span>tidyr</span><span>)</span><span>
</span><span>library</span><span>(</span><span>Mcomp</span><span>)</span><span>
</span><span>#======example datasets=============
</span><span>
</span><span># Example 1
</span><span>x</span><span> </span><span>&lt;-</span><span> </span><span>tourism</span><span>[[</span><span>150</span><span>]]</span><span>$</span><span>x</span><span>
</span><span>h</span><span> </span><span>&lt;-</span><span> </span><span>tourism</span><span>[[</span><span>150</span><span>]]</span><span>$</span><span>h</span><span>
</span><span>par</span><span>(</span><span>mfrow</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>4</span><span>,</span><span> </span><span>1</span><span>),</span><span> </span><span>bty</span><span> </span><span>=</span><span> </span><span>&quot;l&quot;</span><span>,</span><span> </span><span>font.main</span><span> </span><span>=</span><span> </span><span>1</span><span>)</span><span>
</span><span>plot</span><span>(</span><span>forecast</span><span>(</span><span>ets</span><span>(</span><span>x</span><span>),</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>h</span><span>));</span><span> </span><span>grid</span><span>()</span><span>
</span><span>plot</span><span>(</span><span>forecast</span><span>(</span><span>stlm</span><span>(</span><span>x</span><span>),</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>h</span><span>));</span><span> </span><span>grid</span><span>()</span><span>
</span><span>plot</span><span>(</span><span>thetaf</span><span>(</span><span>x</span><span>,</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>h</span><span>));</span><span> </span><span>grid</span><span>()</span><span>
</span><span>plot</span><span>(</span><span>tourism</span><span>[[</span><span>150</span><span>]],</span><span> </span><span>main</span><span> </span><span>=</span><span> </span><span>&quot;Actual results - `tourism` data series 150&quot;</span><span>);</span><span> </span><span>grid</span><span>()</span><span>
</span><span># Example 2
</span><span>x</span><span> </span><span>&lt;-</span><span> </span><span>tourism</span><span>[[</span><span>600</span><span>]]</span><span>$</span><span>x</span><span>
</span><span>h</span><span> </span><span>&lt;-</span><span> </span><span>tourism</span><span>[[</span><span>600</span><span>]]</span><span>$</span><span>h</span><span>
</span><span>par</span><span>(</span><span>mfrow</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>4</span><span>,</span><span> </span><span>1</span><span>),</span><span> </span><span>bty</span><span> </span><span>=</span><span> </span><span>&quot;l&quot;</span><span>,</span><span> </span><span>font.main</span><span> </span><span>=</span><span> </span><span>1</span><span>)</span><span>
</span><span>plot</span><span>(</span><span>forecast</span><span>(</span><span>ets</span><span>(</span><span>x</span><span>),</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>h</span><span>));</span><span> </span><span>grid</span><span>()</span><span>
</span><span>plot</span><span>(</span><span>forecast</span><span>(</span><span>stlm</span><span>(</span><span>x</span><span>),</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>h</span><span>));</span><span> </span><span>grid</span><span>()</span><span>
</span><span>plot</span><span>(</span><span>thetaf</span><span>(</span><span>x</span><span>,</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>h</span><span>));</span><span> </span><span>grid</span><span>()</span><span>
</span><span>plot</span><span>(</span><span>tourism</span><span>[[</span><span>600</span><span>]],</span><span> </span><span>main</span><span> </span><span>=</span><span> </span><span>&quot;Actual results - `tourism` data series 600&quot;</span><span>);</span><span> </span><span>grid</span><span>()</span><span>
</span><span>#============set up cluster for parallel computing===========
</span><span>cluster</span><span> </span><span>&lt;-</span><span> </span><span>makeCluster</span><span>(</span><span>7</span><span>)</span><span> </span><span># only any good if you have at least 7 processors :)
</span><span>registerDoParallel</span><span>(</span><span>cluster</span><span>)</span><span>
</span><span>clusterEvalQ</span><span>(</span><span>cluster</span><span>,</span><span> </span><span>{</span><span>
</span><span>library</span><span>(</span><span>Tcomp</span><span>)</span><span>
</span><span>library</span><span>(</span><span>Mcomp</span><span>)</span><span>
</span><span>library</span><span>(</span><span>forecast</span><span>)</span><span>
</span><span>})</span><span>
</span><span>#==========the actual analytical function==============
</span><span>competition</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>collection</span><span>,</span><span> </span><span>maxfors</span><span> </span><span>=</span><span> </span><span>length</span><span>(</span><span>collection</span><span>)){</span><span>
</span><span>if</span><span>(</span><span>class</span><span>(</span><span>collection</span><span>)</span><span> </span><span>!=</span><span> </span><span>&quot;Mcomp&quot;</span><span>){</span><span>
</span><span>stop</span><span>(</span><span>&quot;This function only works on objects of class Mcomp, eg from the Mcomp or Tcomp packages.&quot;</span><span>)</span><span>
</span><span>}</span><span>
</span><span>nseries</span><span> </span><span>&lt;-</span><span> </span><span>length</span><span>(</span><span>collection</span><span>)</span><span>
</span><span>mases</span><span> </span><span>&lt;-</span><span> </span><span>foreach</span><span>(</span><span>i</span><span> </span><span>=</span><span> </span><span>1</span><span>:</span><span>maxfors</span><span>,</span><span> </span><span>.combine</span><span> </span><span>=</span><span> </span><span>&quot;rbind&quot;</span><span>)</span><span> </span><span>%dopar%</span><span> </span><span>{</span><span>
</span><span>thedata</span><span> </span><span>&lt;-</span><span> </span><span>collection</span><span>[[</span><span>i</span><span>]]</span><span> </span><span>fc1</span><span> </span><span>&lt;-</span><span> </span><span>forecast</span><span>(</span><span>ets</span><span>(</span><span>thedata</span><span>$</span><span>x</span><span>),</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>thedata</span><span>$</span><span>h</span><span>)</span><span>
</span><span>fc2</span><span> </span><span>&lt;-</span><span> </span><span>forecast</span><span>(</span><span>stlm</span><span>(</span><span>thedata</span><span>$</span><span>x</span><span>),</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>thedata</span><span>$</span><span>h</span><span>)</span><span>
</span><span>fc3</span><span> </span><span>&lt;-</span><span> </span><span>thetaf</span><span>(</span><span>thedata</span><span>$</span><span>x</span><span>,</span><span> </span><span>h</span><span> </span><span>=</span><span> </span><span>thedata</span><span>$</span><span>h</span><span>)</span><span>
</span><span>mase</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>accuracy</span><span>(</span><span>fc1</span><span>,</span><span> </span><span>thedata</span><span>$</span><span>xx</span><span>)[</span><span>2</span><span>,</span><span> </span><span>&quot;MASE&quot;</span><span>],</span><span>
</span><span>accuracy</span><span>(</span><span>fc2</span><span>,</span><span> </span><span>thedata</span><span>$</span><span>xx</span><span>)[</span><span>2</span><span>,</span><span> </span><span>&quot;MASE&quot;</span><span>],</span><span>
</span><span>accuracy</span><span>(</span><span>fc3</span><span>,</span><span> </span><span>thedata</span><span>$</span><span>xx</span><span>)[</span><span>2</span><span>,</span><span> </span><span>&quot;MASE&quot;</span><span>])</span><span>
</span><span>return</span><span>(</span><span>mase</span><span>)</span><span>
</span><span>}</span><span>
</span><span>colnames</span><span>(</span><span>mases</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;ets&quot;</span><span>,</span><span> </span><span>&quot;stlm&quot;</span><span>,</span><span> </span><span>&quot;thetaf&quot;</span><span>)</span><span>
</span><span>return</span><span>(</span><span>mases</span><span>)</span><span>
</span><span>}</span><span>
</span><span>## Test on a small set of data, useful during dev
</span><span>small_collection</span><span> </span><span>&lt;-</span><span> </span><span>list</span><span>(</span><span>tourism</span><span>[[</span><span>100</span><span>]],</span><span> </span><span>tourism</span><span>[[</span><span>200</span><span>]],</span><span> </span><span>tourism</span><span>[[</span><span>300</span><span>]],</span><span> </span><span>tourism</span><span>[[</span><span>400</span><span>]],</span><span> </span><span>tourism</span><span>[[</span><span>500</span><span>]],</span><span> </span><span>tourism</span><span>[[</span><span>600</span><span>]])</span><span>
</span><span>class</span><span>(</span><span>small_collection</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>&quot;Mcomp&quot;</span><span>
</span><span>test1</span><span> </span><span>&lt;-</span><span> </span><span>competition</span><span>(</span><span>small_collection</span><span>)</span><span>
</span><span>round</span><span>(</span><span>test1</span><span>,</span><span> </span><span>1</span><span>)</span><span>
</span><span>#===========application=================
# takes a few minutes to run
</span><span>t</span><span>4</span><span> </span><span>&lt;-</span><span> </span><span>competition</span><span>(</span><span>subset</span><span>(</span><span>tourism</span><span>,</span><span> </span><span>&quot;quarterly&quot;</span><span>))</span><span>
</span><span>t</span><span>12</span><span> </span><span>&lt;-</span><span> </span><span>competition</span><span>(</span><span>subset</span><span>(</span><span>tourism</span><span>,</span><span> </span><span>&quot;monthly&quot;</span><span>))</span><span>
</span><span>m</span><span>4</span><span> </span><span>&lt;-</span><span> </span><span>competition</span><span>(</span><span>subset</span><span>(</span><span>M</span><span>1</span><span>,</span><span> </span><span>&quot;quarterly&quot;</span><span>))</span><span>
</span><span>m</span><span>12</span><span> </span><span>&lt;-</span><span> </span><span>competition</span><span>(</span><span>subset</span><span>(</span><span>M</span><span>1</span><span>,</span><span> </span><span>&quot;monthly&quot;</span><span>))</span><span>
</span><span># shut down cluster
</span><span>stopCluster</span><span>(</span><span>cluster</span><span>)</span><span>
</span><span>#===========results=============
</span><span>
</span><span>results</span><span> </span><span>&lt;-</span><span> </span><span>as.data.frame</span><span>(</span><span>rbind</span><span>(</span><span>t</span><span>4</span><span>,</span><span> </span><span>t</span><span>12</span><span>,</span><span> </span><span>m</span><span>4</span><span>,</span><span> </span><span>m</span><span>12</span><span>)</span><span> </span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>dataset</span><span> </span><span>=</span><span> </span><span>rep</span><span>(</span><span>c</span><span>(</span><span>&quot;Tourism&quot;</span><span>,</span><span> </span><span>&quot;M1&quot;</span><span>),</span><span> </span><span>times</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>nrow</span><span>(</span><span>t</span><span>4</span><span>)</span><span> </span><span>+</span><span> </span><span>nrow</span><span>(</span><span>t</span><span>12</span><span>),</span><span> </span><span>nrow</span><span>(</span><span>m</span><span>4</span><span>)</span><span> </span><span>+</span><span> </span><span>nrow</span><span>(</span><span>m</span><span>12</span><span>))))</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>period</span><span> </span><span>=</span><span> </span><span>rep</span><span>(</span><span>c</span><span>(</span><span>&quot;Quarterly&quot;</span><span>,</span><span> </span><span>&quot;Monthly&quot;</span><span>,</span><span> </span><span>&quot;Quarterly&quot;</span><span>,</span><span> </span><span>&quot;Monthly&quot;</span><span>),</span><span>
</span><span>times</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>nrow</span><span>(</span><span>t</span><span>4</span><span>),</span><span> </span><span>nrow</span><span>(</span><span>t</span><span>12</span><span>),</span><span> </span><span>nrow</span><span>(</span><span>m</span><span>4</span><span>),</span><span> </span><span>nrow</span><span>(</span><span>m</span><span>12</span><span>))))</span><span> </span><span>%>%</span><span>
</span><span>gather</span><span>(</span><span>method</span><span>,</span><span> </span><span>MASE</span><span>,</span><span> </span><span>-</span><span>period</span><span>,</span><span> </span><span>-</span><span>dataset</span><span>)</span><span>
</span><span>results</span><span> </span><span>%>%</span><span>
</span><span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>MASE</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>method</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>method</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_density</span><span>(</span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.1</span><span>)</span><span> </span><span>+</span><span> </span><span>geom_rug</span><span>()</span><span> </span><span>+</span><span>
</span><span>scale_colour_brewer</span><span>(</span><span>&quot;&quot;</span><span>,</span><span> </span><span>palette</span><span> </span><span>=</span><span> </span><span>&quot;Set1&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_fill_brewer</span><span>(</span><span>&quot;&quot;</span><span>,</span><span> </span><span>palette</span><span> </span><span>=</span><span> </span><span>&quot;Set1&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>facet_grid</span><span>(</span><span>period</span><span> </span><span>~</span><span> </span><span>dataset</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_x_sqrt</span><span>()</span><span>
</span><span>results</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>period</span><span>,</span><span> </span><span>dataset</span><span>,</span><span> </span><span>method</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>MASE</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>MASE</span><span>,</span><span> </span><span>tr</span><span> </span><span>=</span><span> </span><span>0.1</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>period</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>MASE</span><span>,</span><span> </span><span>label</span><span> </span><span>=</span><span> </span><span>method</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>method</span><span>))</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>dataset</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_text</span><span>()</span><span> </span><span>+</span><span>
</span><span>scale_colour_brewer</span><span>(</span><span>palette</span><span> </span><span>=</span><span> </span><span>&quot;Set1&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>legend.position</span><span> </span><span>=</span><span> </span><span>&quot;none&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Trimmed mean of Mean Absolute Scaled Error&quot;</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Comparison of three related forecasting methods&quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;'Tourism' and 'M1' competition datasets&quot;</span><span>)</span><span>
</span><span>results</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>period</span><span>,</span><span> </span><span>dataset</span><span>,</span><span> </span><span>method</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>MASE</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>MASE</span><span>,</span><span> </span><span>tr</span><span> </span><span>=</span><span> </span><span>0</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>period</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>MASE</span><span>,</span><span> </span><span>label</span><span> </span><span>=</span><span> </span><span>method</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>method</span><span>))</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>dataset</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_text</span><span>()</span><span> </span><span>+</span><span>
</span><span>scale_colour_brewer</span><span>(</span><span>palette</span><span> </span><span>=</span><span> </span><span>&quot;Set1&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>legend.position</span><span> </span><span>=</span><span> </span><span>&quot;none&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Mean of Mean Absolute Scaled Error&quot;</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Comparison of three related forecasting methods&quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;'Tourism' and 'M1' competition datasets&quot;</span><span>)</span></code></pre>
</figure>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/error-trend-seasonality-ets-and-its-forecast-model-friends/"></div></div><div><a data-url="https://www.r-bloggers.com/error-trend-seasonality-ets-and-its-forecast-model-friends/" data-counturl="https://www.r-bloggers.com/error-trend-seasonality-ets-and-its-forecast-model-friends/" data-count="vertical" data-text="Error, trend, seasonality –  ets and its forecast model friends" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://ellisp.github.io/blog/2016/11/27/ets-friends"> Peter's stats stuff - R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/uPyrZYXn70M"></a></div>