[R] decomposing an irregularly spaced time series
ravi
rv15i at yahoo.se
Fri Feb 26 23:04:41 CET 2010
Hi,
I am interested in decomposing an irregularly spaced time series and getting results similiar to that obtained with the stl command for a regularly spaced time series. I would like to know if any of the time series packages like zoo can be used for this. From my search, I was only able to find some help with the tseries and pastecs passages, But I had difficulty in going the full length even with these packages . Let me explain with my sample code :
# Attemts with the functions irts, regul and tsd
n<-20
t1 <- runif(n)
n1<-(1:n)*1e6
t2<-t1*1e3
t3<-n1+t2
u <- rnorm(n)
n2<-rep(1:5,times=4); u<-u+n2
library(tseries)
x <- irts(t3, u) # could not find a decomposition method for irts
y<-data.frame(day=x$time,val=x$value)
y$day<-as.Date(y$day)
y$nday<-as.numeric(y$day)
y
with(y,plot(nday,val,type="b"))
library(pastecs)
y1<-y$day[1]
yf<-"y-m-d"
reg.y<-regul(x=as.numeric(y$day),y=y$val,units="days",methods=c("l"),
datemin=y1,dateformat=yf,deltat=5)
I get the following error message :
Error in approx(x, y, xout, method = "linear", rule = rule) :
need at least two non-NA values to interpolate
I would like to get help on the following points :
1. The actual decomposition is suposed to work with the tsd command. Is it possible to use it without first using regul?
2. Can I succeed with the regul command by a better choice of argument values? My attempts to set rule=2 did not help.
3. Would it be better to first get a regularly spaced time series by interpolation, and then try decompostion with stl?
I would appreciate some practical help here.
4.Is it hopeless to attemt decomposition when the irregularity level is high? The series that I am working on is
fairly regular in periods interpersed with either breaks or irregular data. I would like to see the trends and seasonal effects there.
Is there an alternative method of approaching this task?
Thanking you,
Ravi
More information about the R-help
mailing list