Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating seasonally adjusted data using ARIMA in R
    text
    copied!<p>I would like to generate seasonally adjusted unemployment data for each county for the past 22 years.</p> <p>The US Bureau of Labor Statistics uses ARIMA to seasonally adjust unemployment for the nation as a whole, but not for individual counties. I need help figuring out how to coerce ARIMA in R to do seasonal adjustment for each US county. </p> <p>I can get an ARIMA model by using <code>auto.arima(mytimeseries)</code>, but I can't figure out how to subtract the seasonal component (as is easy to do with <code>(decompose(mytimeseries))$seasonal)</code>.</p> <p>This site <a href="https://onlinecourses.science.psu.edu/stat510/?q=book/export/html/51" rel="nofollow">https://onlinecourses.science.psu.edu/stat510/?q=book/export/html/51</a> implies that I should be able to just subtract out the ARIMA residuals:</p> <pre><code>predicteds = oilindex - expsmoothfit$residuals </code></pre> <p>but that didn't look at all correct (by eye) when I tried it -- it didn't look like it recognized much of the seasonal variation at all.</p> <p>I thought maybe the model that <code>auto.arima()</code> came up with was poor, but when I plotted the model on the same plot as the original data, it looked quite good. </p> <p>This site <a href="http://www.statoek.wiso.uni-goettingen.de/mitarbeiter/ogi/pub/r_workshop.pdf" rel="nofollow">http://www.statoek.wiso.uni-goettingen.de/mitarbeiter/ogi/pub/r_workshop.pdf</a> talks about doing smoothing by using predict() with a sequence, but I can't get that to work: I can't tell if I am doing something wrong with my <code>data.frame(mytimeseries[date=seq])</code> line or if arima objects don't have the same methods as <code>gam</code> objects, so the prediction doesn't work.</p> <p>So: how do I use ARIMA to remove seasonality from data? Any help appreciated!</p> <p>Here is an example of what I have so far. (I am an R newbie, so undoubtedly, this code is sub-optimal.)</p> <pre><code># I put unadjusted values for one county at # http://tmp.webfoot.com/tmp/tmp/unemployment17019.csv a = read.table("/tmp/unemployment17019.csv", header=FALSE) # there is probably a simple seven-character way of doing the next line... all = c(a[1,], a[2,], a[3,], a[4,], a[5,], a[6,], a[7,], a[8,], a[9,], a[10,], a[11,], a[12,], a[13,], a[14,], a[15,], a[16,], a[17,], a[18,], a[19,], a[20,], a[21,], a[22,]) timeseries=ts(as.numeric(all), frequency=12, start=1990) arimabestfit = forecast::auto.arima(timeseries) title("Iroquois County", xlab="Date", ylab="Unemployment Rate") legend(1991,12,c("unadjusted", "adjusted"), col=c("grey", "red"), cex=0.8, lty=1) plot((timeseries - arimabestfit$residuals), col="red", ylim=c(0,12)) lines(timeseries, col="grey") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload