<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/smooth-package-for-r-es-function-part-iii-multiplicative-models/"></div></div><div><a data-url="https://www.r-bloggers.com/smooth-package-for-r-es-function-part-iii-multiplicative-models/" data-counturl="https://www.r-bloggers.com/smooth-package-for-r-es-function-part-iii-multiplicative-models/" data-count="horizontal" data-text="“smooth” package for R. es() function. Part III. Multiplicative models" 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://forecasting.svetunkov.ru/en/2016/11/18/smooth-package-for-r-es-function-part-iii-multiplicative-models/"> R – Modern Forecasting</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h3>Theoretical stuff</h3>
<p>Last time we talked about pure additive models, today I want to discuss multiplicative ones.</p>
<p>There is a general scepticism about pure multiplicative exponential smoothing models in the forecasters society, because it is not clear why level, trend, seasonality and error term should be multiplied. Well, when it comes to seasonality, then there is no doubt – multiplicative one is more often met than additive and thus is more often used in practice. However, multiplicative trend and multiplicative error are not as straight forward, because it is not easy to understand why we need them in the first place. In addition, models with these multiplicative components are harder to implement, harder to work with and their forecast accuracy is not necessarily better than accuracy of other models.</p>
<p>So why bother at all? There is at least one reason. Pure multiplicative models are constructed with the assumption that the data we work with is positive only. And this is a plausible assumption when we work with demand on products, because selling -50 boots in March 2017 or something like that does not make much sense. However, when we work with high scale data (for example, hundreds or even thousands of units), then this advantage becomes negligible, so pure additive or mixed models can be used instead. This, in fact, is the reason why pure multiplicative models are neglected.</p>
<p>So, what’s the catch with these models? Let’s have a look.</p>
<p>The general pure multiplicative model can be written in the following compact form, if we use natural logarithms:<br>
\begin{equation} \label{eq:ssGeneralMultiplicative}<br>
\begin{matrix}<br>
y_t = \exp \left(w’ \log(v_{t-l}) + \log(1+\epsilon_t) \right) \\<br>
\log(v_t) = F \log(v_{t-l}) + \log (1 + g \epsilon_t)<br>
\end{matrix} ,<br>
\end{equation}<br>
where all the notations have already been introduced in <a target="_blank" rel="nofollow" href="http://forecasting.svetunkov.ru/en/2016/11/02/smooth-package-for-r-es-function-part-ii-pure-additive-models/">the previous post</a>. The only thing to note is that both \(\exp\) and \(\log\) are applied element wise to vectors. This means that \(\log(v_t)\) will result in vector consisting of components in logarithms. The important thing to note here is that all the components of this models must be positive, otherwise it won’t work.</p>
<p>An example of multiplicative model written in this form is ETS(M,M,N) – model with multiplicative error and multiplicative trend – can be written as:<br>
\begin{equation} \label{eq:ssETS(M,M,N)}<br>
\begin{matrix}<br>
y_t = \exp \left(\log(l_{t-l}) + \log(b_{t-l}) + \log(1 + \epsilon_t) \right) \\<br>
\log(l_t) = \log(l_{t-l}) + \log(b_{t-l}) + \log (1 + \alpha \epsilon_t) \\<br>
\log(b_t) = \log(b_{t-l}) + \log (1 + \beta \epsilon_t)<br>
\end{matrix} .<br>
\end{equation}<br>
Taking exponent of second and third equations and simplifying the first one in \eqref{eq:ssETS(M,M,N)} leads to the conventional model, that underlies Pegel’s method:<br>
\begin{equation} \label{eq:ssETS(M,M,N)_Pegels}<br>
\begin{matrix}<br>
y_t = l_{t-l} b_{t-l} (1 + \epsilon_t) \\<br>
l_t = l_{t-l} b_{t-l} (1 + \alpha \epsilon_t) \\<br>
b_t = b_{t-l} (1 + \beta \epsilon_t)<br>
\end{matrix} .<br>
\end{equation}<br>
Multiplication of level, trend and error term restricts actuals with positive values, but this will only be true if we impose correct assumptions on error term. While <a target="_blank" rel="nofollow" href="http://www.springer.com/gp/book/9783540719168">Hyndman et al. 2008</a> assume that it is distributed normally (they have actually discussed other assumption in Chapter 15), we assume in
<pre>es()</pre>
<p> that it is distributed log-normally:<br>
\begin{equation} \label{eq:ssErrorlogN}<br>
(1 + \epsilon_t) \sim \text{log}\mathcal{N}(0,\sigma^2),<br>
\end{equation}<br>
where \(\sigma^2\) is variance of logarithm of \(1 + \epsilon_t\). Why log-normal distribution? Let me explain. When the variance \(\sigma^2\) is small, the differences between
<pre>es()</pre>
<p> and
<pre>ets()</pre>
<p> models with multiplicative error are almost non-existent, because in this case both normal and log-normal distributions look very similar. However with larger variance the differences become more substantial (and by larger I mean something greater than 0.1), because log-normal distribution becomes positive skewed with a longer tail. In addition, with a higher variance and normality assumption chances of having \(1 + \epsilon_t \leq 0\) increase, which contradicts the original model. So the assumption of normality is not always unrealistic and may lead to problems in model construction. That is why we need the assumption \eqref{eq:ssErrorlogN}.</p>
<p>Now \eqref{eq:ssErrorlogN} influences several aspects of how the model work: point forecasts, prediction intervals and estimation of the model \eqref{eq:ssGeneralMultiplicative} will be slightly different.</p>
<p>First of all, with low actual values point forecasts correspond to median rather than mean. This is because of relations between mean in normal and log-normal distributions and the fact that variance of error term in these cases may become sufficiently large for them to differ substantially. Arguably, median is what we need in cases of skewed distributions and that’s what
<pre>es()</pre>
<p> produces. Knowing that is especially important in cases with intermittent demand models, which will be discussed in this blog at some distant point in future.</p>
<p>Secondly, due to asymmetry of log-normal distribution prediction intervals become asymmetric. This will especially be evident, when scale of data is low and variance is high. In the other situations the intervals will be very close to intervals produced by additive error models with normally distributed errors.</p>
<p>Finally, the estimation of models with multiplicative errors should be based on the following concentrated log-likelihood function (for log-normal distribution):<br>
\begin{equation} \label{eq:ssConcentratedLogLikelihoodLnorm}<br>
\ell(\theta | Y) = -\frac{T}{2} \left( \log \left( 2 \pi e \right) +\log \left( \hat{\sigma}^2 \right) \right) -\sum_{t=1}^T \log y_t ,<br>
\end{equation}<br>
where \(\hat{\sigma}^2 = \frac{1}{T} \sum_{t=1}^T \log^2(1 + \epsilon_{t})\). The likelihood function \eqref{eq:ssConcentratedLogLikelihoodLnorm} looks very similar to <a target="_blank" rel="nofollow" href="http://forecasting.svetunkov.ru/en/2016/11/02/smooth-package-for-r-es-function-part-ii-pure-additive-models/">the one used in additive models</a>, but leads to a slightly different cost function (that we need to minimise):<br>
\begin{equation} \label{eq:ssCostFunction}<br>
\text{CF} = \log \left( \hat{\sigma}^2 \right) + \frac{2}{T} \sum_{t=1}^T \log y_t .<br>
\end{equation}<br>
Giving interpretation to the cost function \eqref{eq:ssCostFunction}, variance of error term here is weighed with actual values. So roughly saying higher actuals will be predicted with higher precision.</p>
<h3>R stuff</h3>
<p>A good example of data, where pure multiplicative model can be used is time series N2457 from M3. Although the scale of data is high (the average is around 5000), the variability of data is high as well, which indicates that multiplicative model could be efficiently used here. So, let’s construct the ETS(M,N,N) model with parametric prediction intervals:</p>
<pre>es(M3$N2457$x, &quot;MNN&quot;, h=18, holdout=TRUE, intervals=&quot;p&quot;)</pre>
<p><p>This results in the following output:</p>
<pre>Time elapsed: 0.1 seconds
Model estimated: ETS(MNN)
Persistence vector g:
alpha 
0.145 
Initial values were optimised.
3 parameters were estimated in the process
Residuals standard deviation: 0.413
Cost function type: MSE; Cost function value: 1288657

Information criteria:
     AIC     AICc      BIC 
1645.978 1646.236 1653.702 
95% parametric prediction intervals were constructed
72% of values are in the prediction interval
Forecast errors:
MPE: 26.3%; Bias: 87%; MAPE: 39.8%; SMAPE: 49.4%
MASE: 2.944; sMAE: 120.1%; RelMAE: 1.258; sMSE: 242.7%</pre>
<p><p>We have already discussed what each of the lines of this output means in the <a target="_blank" rel="nofollow" href="http://forecasting.svetunkov.ru/en/2016/11/02/smooth-package-for-r-es-function-part-ii-pure-additive-models/">previous post</a>, so we will not stop on that here. The thing to note, however, is the line with residuals standard deviation, which is equal to 0.413 (meaning that variance is approximately equal to 0.17). With this standard deviation the distribution will be noticeably skewed. This can be evidently seen on the produced graph:</p>
<div class="wp-caption"><a target="_blank" rel="nofollow" href="https://i2.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2457-MNN-PI-parametric.png"><img sizes="(max-width: 300px) 100vw, 300px" alt="Series N2457 from M3 and es(&quot;MNN&quot;) forecast with prediction intervals" class="wp-image-1014" src="https://i0.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2457-MNN-PI-parametric-300x175.png?resize=300%2C175" data-recalc-dims="1"></a>
<p class="wp-caption-text">Series N2457 from M3 and es(&quot;MNN&quot;) forecast with prediction intervals</p>
</div>
<p>For the same time series ETS(A,N,N) model will produce the following forecast:</p>
<div class="wp-caption"><a target="_blank" rel="nofollow" href="https://i0.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2457-ANN-PI-parametric.png"><img sizes="(max-width: 300px) 100vw, 300px" alt="Series N2457 from M3 and es(&quot;ANN&quot;) forecast with prediction intervals" class="wp-image-1016" src="https://i2.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2457-ANN-PI-parametric-300x175.png?resize=300%2C175" data-recalc-dims="1"></a>
<p class="wp-caption-text">Series N2457 from M3 and es(“ANN”) forecast with prediction intervals</p>
</div>
<p>Comparing the two graphs, we can notice that prediction intervals on the first one are more adequate for this data, because they take into account skewness in errors distribution. As a result they cover more observations in the holdout than the intervals of the second model.</p>
<p>A counter example is time series N2348 – it does not have as high variability as N2457, so ETS(M,N,N) and ETS(A,N,N) produce very similar point forecasts and prediction intervals. This is because variance in multiplicative model applied to this data is equal to 0.000625 and as a result the log-normal distribution becomes very close to the normal. See for yourselves:</p>
<div class="wp-caption"><a target="_blank" rel="nofollow" href="https://i0.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2348-MNN-PI-parametric.png"><img sizes="(max-width: 300px) 100vw, 300px" alt="Series N2348 from M3 and es(&quot;MNN&quot;) forecast with prediction intervals" class="wp-image-1018" src="https://i2.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2348-MNN-PI-parametric-300x175.png?resize=300%2C175" data-recalc-dims="1"></a>
<p class="wp-caption-text">Series N2348 from M3 and es(“MNN”) forecast with prediction intervals</p>
</div>
<div class="wp-caption"><a target="_blank" rel="nofollow" href="https://i1.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2348-ANN-PI-parametric.png"><img sizes="(max-width: 300px) 100vw, 300px" alt="Series N2348 from M3 and es(&quot;ANN&quot;) forecast with prediction intervals" class="wp-image-1019" src="https://i2.wp.com/forecasting.svetunkov.ru/wp-content/uploads/2016/11/N2348-ANN-PI-parametric-300x175.png?resize=300%2C175" data-recalc-dims="1"></a>
<p class="wp-caption-text">Series N2348 from M3 and es(“ANN”) forecast with prediction intervals</p>
</div>
<p>So in cases of time series similar to N2348 both multiplicative and additive error models can be used equally efficiently. But in general pure multiplicative models should not be neglected as they have useful properties. In one of the next posts we will see that these properties become especially useful for intermittent demand.</p>
<p>That’s all, folks!</p>
<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/smooth-package-for-r-es-function-part-iii-multiplicative-models/"></div></div><div><a data-url="https://www.r-bloggers.com/smooth-package-for-r-es-function-part-iii-multiplicative-models/" data-counturl="https://www.r-bloggers.com/smooth-package-for-r-es-function-part-iii-multiplicative-models/" data-count="vertical" data-text="“smooth” package for R. es() function. Part III. Multiplicative models" 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://forecasting.svetunkov.ru/en/2016/11/18/smooth-package-for-r-es-function-part-iii-multiplicative-models/"> R – Modern Forecasting</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/V2I6J1N6CsM"></a></div>