<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Archives programming - Open Forecasting</title>
	<atom:link href="https://openforecast.org/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://openforecast.org/tag/programming/</link>
	<description>How to look into the future</description>
	<lastBuildDate>Thu, 01 Aug 2019 20:36:45 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2015/08/cropped-usd-05-32x32.png&amp;nocache=1</url>
	<title>Archives programming - Open Forecasting</title>
	<link>https://openforecast.org/tag/programming/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>greybox package for R</title>
		<link>https://openforecast.org/2018/05/04/greybox-package-for-r/</link>
					<comments>https://openforecast.org/2018/05/04/greybox-package-for-r/#respond</comments>
		
		<dc:creator><![CDATA[Ivan Svetunkov]]></dc:creator>
		<pubDate>Fri, 04 May 2018 12:22:35 +0000</pubDate>
				<category><![CDATA[Applied forecasting]]></category>
		<category><![CDATA[Package greybox for R]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[greybox]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[statistics]]></category>
		<guid isPermaLink="false">https://openforecast.org/?p=1718</guid>

					<description><![CDATA[<p>I am delighted to announce a new package on CRAN. It is called &#8220;greybox&#8221;. I know, what my American friends will say, as soon as they see the name &#8211; they will claim that there is a typo, and that it should be &#8220;a&#8221; instead of &#8220;e&#8221;. But in fact no mistake was made &#8211; [&#8230;]</p>
<p>Message <a href="https://openforecast.org/2018/05/04/greybox-package-for-r/">greybox package for R</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2018/05/greybox2.png&amp;nocache=1"><img fetchpriority="high" decoding="async" src="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2018/05/greybox2-260x300.png&amp;nocache=1" alt="Hexagon for greybox" width="260" height="300" class="size-medium wp-image-1719" srcset="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2018/05/greybox2-260x300.png&amp;nocache=1 260w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2018/05/greybox2-768x888.png&amp;nocache=1 768w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2018/05/greybox2-886x1024.png&amp;nocache=1 886w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2018/05/greybox2.png&amp;nocache=1 1206w" sizes="(max-width: 260px) 100vw, 260px" /></a></p>
<p>I am delighted to announce a new package on CRAN. It is called &#8220;greybox&#8221;. I know, what my American friends will say, as soon as they see the name &#8211; they will claim that there is a typo, and that it should be &#8220;a&#8221; instead of &#8220;e&#8221;. But in fact no mistake was made &#8211; I used British spelling for the name, and I totally understand that at some point I might regret this&#8230;</p>
<p>So, what is &#8220;greybox&#8221;? Wikipedia <a href="https://en.wikipedia.org/wiki/Grey_box_model" rel="noopener noreferrer" target="_blank">tells us that grey box</a> is a model that &#8220;combines a partial theoretical structure with data to complete the model&#8221;. This means that almost any statistical model can be considered as a grey box, thus making the package potentially quite flexible and versatile.</p>
<p>But why do we need a new package on CRAN?</p>
<p>First, there were several functions in <a href="/en/tag/smooth/">smooth</a> package that did not belong there, and there are several functions in <a href="https://github.com/trnnick/TStools" rel="noopener noreferrer" target="_blank">TStools</a> package that can be united with a topic of model building. They focus on the multivariate regression analysis rather than on state-space models, time series smoothing or anything else. It would make more sense to find them their own <del>home</del> package. An example of such a function is <span class="lang:r decode:true crayon-inline">ro()</span> &#8211; <a href="https://cran.r-project.org/web/packages/greybox/vignettes/ro.html" rel="noopener noreferrer" target="_blank">Rolling Origin</a> &#8211; function that Yves and I wrote in 2016 on our way to the International Symposium on Forecasting. Arguably this function can be used not only for assessing the accuracy of forecasting models, but also for the variables / model selection.</p>
<p>Second, in one of my side projects, I needed to work more on the multivariate regressions, and I had several ideas I wanted to test. One of those is creating a combined multivariate regression from several models using information criteria weights. The existing implementations did not satisfy me, so I ended up writing a function <span class="lang:r decode:true crayon-inline">lmCombine()</span> that does that. In addition, our research together with Yves Sagaert indicates that there is a nice solution for a fat regression problem (when the number of parameters is higher than the number of observations) using information criteria. Uploading those function in <span class="lang:r decode:true crayon-inline">smooth</span> did not sound right, but having a <span class="lang:r decode:true crayon-inline">greybox</span> helps a lot. There are other ideas that I have in mind, and they don&#8217;t fit in the other packages.</p>
<p>Finally, I could not find satisfactory (from my point of view) packages on CRAN that would focus on multivariate model building and forecasting &#8211; the usual focus is on analysis instead (including time series analysis). The other thing is the obsession of many packages with p-values and hypotheses testing, which was yet another motivator for me to develop a package that would be completely hypotheses-free (at 95% level). As a result, if you work with the functions from <span class="lang:r decode:true crayon-inline">greybox</span>, you might notice that they produce confidence intervals instead of p-values (because I find them more informative and useful). Finally, I needed good instruments for the promotional modelling for several projects, and it was easier to implement them myself than to compile them from different functions from different packages.</p>
<p>Keeping that in mind, it makes sense to briefly discuss what is already available there. I&#8217;ve already discussed how <span class="lang:r decode:true crayon-inline">xregExpander()</span> and <span class="lang:r decode:true crayon-inline">stepwise()</span> functions work <a href="/en/2018/02/10/smooth-package-for-r-common-ground-part-iv-exogenous-variables-advanced-stuff/">in one of the previous posts</a>, and these functions are now available in <span class="lang:r decode:true crayon-inline">greybox</span> instead of <span class="lang:r decode:true crayon-inline">smooth</span>. However, I have not covered either <span class="lang:r decode:true crayon-inline">lmCombine()</span> or <span class="lang:r decode:true crayon-inline">ro()</span> functions yet. While <span class="lang:r decode:true crayon-inline">lmCombine()</span> is still under construction and works only for normal cases (fat regression can be solved, but not 100% efficiently), <span class="lang:r decode:true crayon-inline">ro()</span> has worked efficiently for several years already. So I created a detailed <a href="https://cran.r-project.org/web/packages/greybox/vignettes/ro.html" rel="noopener noreferrer" target="_blank">vignette</a>, explaining what is rolling origin, how the function works and how to use it. So, if you are interested in finding out more, <a href="https://cran.r-project.org/web/packages/greybox/vignettes/ro.html" rel="noopener noreferrer" target="_blank">check it out on CRAN</a>.</p>
<p>As a wrap up, <span class="lang:r decode:true crayon-inline">greybox</span> package is focused on model building and forecasting and from now on will be periodically updated.</p>
<p>As a final note, I plan to do the following in <span class="lang:r decode:true crayon-inline">greybox</span> in future releases:</p>
<ol>
<li>Move <span class="lang:r decode:true crayon-inline">nemenyi()</span> function from <a href="https://github.com/trnnick/TStools" rel="noopener noreferrer" target="_blank">TStools</a> to <a href="https://github.com/config-i1/greybox" rel="noopener noreferrer" target="_blank">greybox</a>;</li>
<li>Develop functions for promotional modelling;</li>
<li>Write a function for multiple correlation coefficients (will be used for multicollinearity analysis);</li>
<li>Implement variables selection based on rolling origin evaluation;</li>
<li>Stepwise regression and combinations of models, based on Laplace and the other distributions;</li>
<li>AICc for Laplace and the other distributions;</li>
<li>Solve fat regression problem via combination of regression models (sounds crazy, right?);</li>
<li><span class="lang:r decode:true crayon-inline">xregTransformer</span> &#8211; Non-linear transformation of the provided xreg variables;</li>
<li>Other cool stuff.</li>
</ol>
<p>If you have any thoughts on what to implement, leave a comment &#8211; I will consider your idea.</p>
<p>Message <a href="https://openforecast.org/2018/05/04/greybox-package-for-r/">greybox package for R</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://openforecast.org/2018/05/04/greybox-package-for-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>&#8220;smooth&#8221; package for R. es() function. Part I</title>
		<link>https://openforecast.org/2016/10/14/smooth-package-for-r-es-i/</link>
					<comments>https://openforecast.org/2016/10/14/smooth-package-for-r-es-i/#respond</comments>
		
		<dc:creator><![CDATA[Ivan Svetunkov]]></dc:creator>
		<pubDate>Fri, 14 Oct 2016 15:29:45 +0000</pubDate>
				<category><![CDATA[About es() function]]></category>
		<category><![CDATA[Applied forecasting]]></category>
		<category><![CDATA[ETS]]></category>
		<category><![CDATA[Package smooth for R]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Univariate models]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[smooth]]></category>
		<guid isPermaLink="false">https://openforecast.org/?p=804</guid>

					<description><![CDATA[<p>Good news, everyone! &#8220;smooth&#8221; package is now available on CRAN. And it is time to look into what this package can do and why it is needed at all. The package itself contains some documentation that you can use as a starting point. For example, there are vignettes, which show included functions and what they [&#8230;]</p>
<p>Message <a href="https://openforecast.org/2016/10/14/smooth-package-for-r-es-i/">&#8220;smooth&#8221; package for R. es() function. Part I</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Good news, everyone! &#8220;smooth&#8221; package is now <a href="https://cran.r-project.org/package=smooth" target="_blank" rel="noopener noreferrer">available on CRAN</a>. And it is time to look into what this package can do and why it is needed at all. The package itself contains some documentation that you can use as a starting point. For example, there are <a href="https://cran.r-project.org/package=smooth/vignettes/smooth.html" target="_blank" rel="noopener noreferrer">vignettes</a>, which show included functions and what they allow to do, but do not go into details of what is happening inside those functions. If you don&#8217;t have a personal life and are ready to spend some time reading semi-scientific materials with formulae, then I have a thing especially for you &#8211; <a href="https://github.com/config-i1/smooth/blob/master/inst/doc/smooth-Documentation.pdf" target="_blank" rel="noopener noreferrer">smooth documentation</a>, which describes in details why models used in the package make sense, how they are optimised and what it leads to. Here we will try to look into some functions and their application to real life forecasting problems.</p>
<p>This is the first post in a series of posts on &#8220;smooth&#8221; functions. We start with <span class="lang:r decode:true  crayon-inline " >es()</span> &#8211; Exponential Smoothing.</p>
<h3>What is es() and why do we need it?</h3>
<p>&#8220;ES&#8221; stands for &#8220;Exponential Smoothing&#8221;. This function is an implementation of ETS model, alternative to Rob Hyndman&#8217;s <span class="lang:r decode:true  crayon-inline " >ets()</span> function from &#8220;<a href="https://github.com/robjhyndman/forecast" target="_blank" rel="noopener noreferrer">forecast</a>&#8221; package. The natural question would be: &#8220;Why bother if there already exists exponential smoothing function&#8221;? There are several reasons for that:</p>
<ol>
<li><span class="lang:r decode:true  crayon-inline " >ets()</span> does not allow constructing some mixed models. For example, classical Holt-Winters model, which corresponds to ETS(A,A,M) is unavailable. This is not a big loss, but these models may be of interest to researchers. So <span class="lang:r decode:true  crayon-inline " >es()</span> function has all 30 of them;</li>
<li><span class="lang:r decode:true  crayon-inline " >ets()</span> does not have exogenous variables. <span class="lang:r decode:true  crayon-inline " >es()</span> allows providing either vector or matrix of exogenous variables. Note, however, that currently only additive ETS models are guaranteed to work well with exogenous variables. It will most probably work fine for other models, but I cannot guarantee stable performance;</li>
<li>There are quite few papers in forecasting field that show that using combinations of forecasts of different models leads to increase in forecasting accuracy. Stephan Kolassa <a href="http://econpapers.repec.org/article/eeeintfor/v_3a27_3ay_3a_3ai_3a2_3ap_3a238-251.htm" target="_blank" rel="noopener noreferrer">applied one neat method</a> of combinations described in <a href="http://www.springer.com/la/book/9780387953649" target="_blank" rel="noopener noreferrer">Burnham and Anderson book</a> to exponential smoothing, showing that it leads to increase of forecast accuracy. So I took that method and implemented it in <span class="lang:r decode:true  crayon-inline " >es()</span> function;</li>
<li><span class="lang:r decode:true  crayon-inline " >ets()</span> function restricts number of seasonal coefficients by 24. The motivation here is that with higher number of coefficients, optimisers will do lousy job in finding optimal values of parameters. <span class="lang:r decode:true  crayon-inline " >es()</span> doesn&#8217;t have this restriction, claiming that users should be responsible for their own actions. Every action has consequences, you know? So, be smart and responsible!</li>
<li><span class="lang:r decode:true  crayon-inline " >ets()</span> function does not allow defining initial values for state vector. In general, who could care less, right? But they may become important in some cases, when optimisation of initial states is not an option. So I have implemented two methods of initialisation (optimisation and backcasting) + allowed users providing initial values if they really need to. This also allows addressing problem with large number of parameters because of number of seasonal coefficients. For example, if you deal with weekly data, then you can switch to backcasting or provide your own values for seasonal indices;</li>
<li>MSE as cost function looked too boring, so I have introduced MAE, cost functions based on multiple steps ahead forecasting errors and exotic &#8220;Half Absolute Moment&#8221;. Why? Well, just in order to make life more exiting! (although there is a rationale for that, which is discussed in the documentation)</li>
<li>There are several ways of constructing prediction intervals. <span class="lang:r decode:true  crayon-inline " >es()</span> allows selecting between parametric, semi-parametric and non-parametric ones. This additional flexibility allows dealing with cases, when for some reason basic assumptions of ETS do not hold;</li>
<li>The derived underlying statistical model in <span class="lang:r decode:true  crayon-inline " >es()</span> differs slightly from <span class="lang:r decode:true  crayon-inline " >ets()</span>. This becomes especially evident, when models with multiplicative errors are used. There we assume that error term is distributed log-normally on the contrast to assumption of normality in <span class="lang:r decode:true  crayon-inline " >ets()</span>;</li>
<li>All the functions of &#8220;smooth&#8221; package allow dealing with intermittent data. This is based on a <a href="/2016/07/01/19th-iif-workshop/">very recent research</a> done in collaboration with John Boylan. So <span class="lang:r decode:true  crayon-inline " >es()</span> function allows producing forecasts using Croston&#8217;s model (not method, this is not a typo!) and some other intermittent data models. We can even select between intermittent and normal models using this approach. This is still an on-going research, so more models will follow with more advanced mechanisms;</li>
<li>Last but not least, we have a fancy <span class="lang:r decode:true  crayon-inline " >holdout</span> parameter, which allows dividing provided time series into two parts, fitting model on the first one and assessing forecasts accuracy on the second.</li>
</ol>
<p>Having said that, I am not claiming that <span class="lang:r decode:true  crayon-inline " >es()</span> function always produces more accurate forecasts than <span class="lang:r decode:true  crayon-inline " >ets()</span>. From what I have experienced so far the function is sometimes more accurate and sometimes less accurate than <span class="lang:r decode:true  crayon-inline " >ets()</span>. However the main point of the function is not in precision, but in flexibility. You can do much more with it, than with <span class="lang:r decode:true  crayon-inline " >ets()</span>, the only restriction for you is your imagination! If you don&#8217;t have imagination and / or just need an efficient exponential smoothing function, don&#8217;t waste your time with <span class="lang:r decode:true  crayon-inline " >es()</span> and use Rob&#8217;s <span class="lang:r decode:true  crayon-inline " >ets()</span>.</p>
<p>Message <a href="https://openforecast.org/2016/10/14/smooth-package-for-r-es-i/">&#8220;smooth&#8221; package for R. es() function. Part I</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://openforecast.org/2016/10/14/smooth-package-for-r-es-i/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
