<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/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/"></div></div><div><a data-url="https://www.r-bloggers.com/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/" data-counturl="https://www.r-bloggers.com/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/" data-count="horizontal" data-text="seasonal 1.3: A Better Way to Seasonal Adjustment Diagnostics" 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="https://usefulr.wordpress.com/2016/08/07/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/"> R – usefulr</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The R package <a target="_blank" href="https://cran.r-project.org/web/packages/seasonal">seasonal</a> makes it easy to use <a target="_blank" href="https://www.census.gov/srd/www/x13as/">X-13ARIMA-SEATS</a>, the seasonal adjustment software by the United States Census Bureau. Thanks to the <a target="_blank" href="https://cloud.r-project.org/package=x13binary">x13binary</a> package, installing it from CRAN is now as easy as installing any other R package:</p>
<div>
<pre><code>install.packages(&quot;seasonal&quot;)
</code></pre>
</div>
<p>The latest version 1.3 comes with a new <code>udg</code> function and a customizable <code>summary</code> method, which give power users of X-13 a convenient way to check the statistics that are of <em>their</em> interest. For a full list of changes, see the package <a target="_blank" href="https://cran.r-project.org/web/packages/seasonal/NEWS">NEWS</a>.</p>
<h3>A generalized way to access diagnostics</h3>
<p>Version 1.3 offers a generalized way to access diagnostic statistics. In <a target="_blank" href="https://cran.r-project.org/web/packages/seasonal">seasonal</a>, it was always possible to use <em>all options</em> of X-13 and access <em>all output series</em>. Now it is easy to access <em>all diagnostics</em> as well.</p>
<p>The main new function is <code>udg</code>, named after the X-13 output file which it is reading. Consider a simple call to <code>seas</code> (the main function of the <a target="_blank" href="https://cran.r-project.org/web/packages/seasonal">seasonal</a> package) that uses the X-11 seasonal adjustment method:</p>
<div>
<pre><code>m &lt;- seas(AirPassengers, x11 = &quot;&quot;)
udg(m)
</code></pre>
</div>
<p>The <code>udg</code> function returns a list containing 357 named diagnostics. They are properly type-converted, so they can be directly used for further analysis within R.</p>
<p>If we ask for a specific statistic, such as the popular X-11 <em>M statistics</em>, the result will be simplified to a numeric vector (see <code>?udg</code> for additional options):</p>
<div>
<pre><code>udg(m, c(&quot;f3.m01&quot;, &quot;f3.m02&quot;, &quot;f3.m03&quot;, &quot;f3.m04&quot;))

## f3.m01 f3.m02 f3.m03 f3.m04 
##  0.041  0.042  0.000  0.283
</code></pre>
</div>
<p>There are also some new wrappers for commonly used statistics, such as <code>AIC</code>, <code>BIC</code>, <code>logLik</code> or <code>qs</code>, which use the <code>udg</code> function.</p>
<h3>A customizable summary</h3>
<p>The new functionality paves the way for a customizable <code>summary</code> method for <code>seas</code> objects. For example, if we want to add the <em>M statistics</em> for X-11 adjustments to the summary, we can write:</p>
<div>
<pre><code>summary(m, stats = c(&quot;f3.m01&quot;, &quot;f3.m02&quot;, &quot;f3.m03&quot;, &quot;f3.m04&quot;))

## Call:
## seas(x = AirPassengers, x11 = &quot;&quot;)
## 
## Coefficients:
##                     Estimate Std. Error z value Pr(>|z|)    
## Weekday           -0.0029497  0.0005232  -5.638 1.72e-08 ***
## Easter[1]          0.0177674  0.0071580   2.482   0.0131 *  
## AO1951.May         0.1001558  0.0204387   4.900 9.57e-07 ***
## MA-Nonseasonal-01  0.1156204  0.0858588   1.347   0.1781    
## MA-Seasonal-12     0.4973600  0.0774677   6.420 1.36e-10 ***
## ---
## Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
## 
## X11 adj.  ARIMA: (0 1 1)(0 1 1)  Obs.: 144  Transform: log
## AICc: 947.3, BIC: 963.9  QS (no seasonality in final):    0  
## Box-Ljung (no autocorr.): 26.65   Shapiro (normality): 0.9908  
## f3.m01: 0.041  f3.m02: 0.042  f3.m03: 0  f3.m04: 0.283 
</code></pre>
</div>
<p>Note the new line at the end, which shows the <em>M statistics</em>.</p>
<p>If we want to routinely consider these statistics in our <code>summary</code>, we can set the <code>seas.stats</code> option accordingly:</p>
<div>
<pre><code>options(seas.stats = c(&quot;f3.m01&quot;, &quot;f3.m02&quot;, &quot;f3.m03&quot;, &quot;f3.m04&quot;))
</code></pre>
</div>
<p>This will change the default behavior, and</p>
<div>
<pre><code>summary(m)
</code></pre>
</div>
<p>will return the same output as above. To restore the default behavior, set the option back to <code>NULL</code>.</p>
<div>
<pre><code>options(seas.stats = NULL)
</code></pre>
</div>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/usefulr.wordpress.com/201/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/usefulr.wordpress.com/201/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></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/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/"></div></div><div><a data-url="https://www.r-bloggers.com/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/" data-counturl="https://www.r-bloggers.com/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/" data-count="vertical" data-text="seasonal 1.3: A Better Way to Seasonal Adjustment Diagnostics" 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="https://usefulr.wordpress.com/2016/08/07/seasonal-1-3-a-better-way-to-seasonal-adjustment-diagnostics/"> R – usefulr</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/JkGNECZ_6nk"></a></div>