Reputation: 627
I would like to generate seasonally adjusted unemployment data for each county for the past 22 years.
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.
I can get an ARIMA model by using auto.arima(mytimeseries)
, but I can't figure out how to subtract the seasonal component (as is easy to do with (decompose(mytimeseries))$seasonal)
.
This site https://onlinecourses.science.psu.edu/stat510/?q=book/export/html/51 implies that I should be able to just subtract out the ARIMA residuals:
predicteds = oilindex - expsmoothfit$residuals
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.
I thought maybe the model that auto.arima()
came up with was poor, but when I plotted the model on the same plot as the original data, it looked quite good.
This site http://www.statoek.wiso.uni-goettingen.de/mitarbeiter/ogi/pub/r_workshop.pdf 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 data.frame(mytimeseries[date=seq])
line or if arima objects don't have the same methods as gam
objects, so the prediction doesn't work.
So: how do I use ARIMA to remove seasonality from data? Any help appreciated!
Here is an example of what I have so far. (I am an R newbie, so undoubtedly, this code is sub-optimal.)
# 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")
Upvotes: 5
Views: 11473
Reputation: 41
One of the most popular methods for decomposing quarterly and monthly data is X-12-ARIMA, which has its origins in methods developed by the US Bureau of the Census. It is now widely used by the Bureau and government agencies around the world. Earlier versions of the method included X-11 and X-11-ARIMA. X-13-ARIMA method is currently to most modern standard that combines X-12-ARIMA with TRAMO/SEATS. TRAMO/SEATS represents an ARIMA model based on a seasonal adjustment method developed by Victor Gomez and Agustin Maravall (Bank of Spain). You can find a short introduction to seasonal adjustment here:
https://economictheoryblog.com/2017/05/02/seasonal-adjustment/
There exists a solid R package called seasonal that facilitates seasonal adjustment in R. The R package provides an easy-to-use interface to the Fortran libraries provided by the US Bureau of the Census. The following link provides a short tutorial on how to conduct seasonal adjustment in R:
https://economictheoryblog.com/2017/05/16/seasonal-adjustment-in-r/
Upvotes: 4
Reputation: 846
The Bureau of Labor Statistics uses the X12 algorithm from the US Census Bureau to seasonally adjust data
There is an R package (x12) implements this functionality
US census bureau:
http://www.census.gov/srd/www/x12a/
x12 package r:
http://cran.r-project.org/web/packages/x12/x12.pdf
Upvotes: 6
Reputation: 132706
I understood that you would like to do deseasoning of you timeseries. I use data from http://research.stlouisfed.org/fred2/series/ILIROQ5URN/downloaddata?cid=27976 for demonstration.
unemploy<-read.table("ILIROQ5URN.txt",header=T,skip=11)
unemploy<-ts(unemploy$VALUE,frequency=12,start(1990,1))
plot(deseason<-stl(unemploy,s.window="periodic"))
plot(unemploy)
lines(deseason$time.series[,2],col="red")
Does that help you?
Upvotes: 1