tags:

views:

192

answers:

1

Hello everybody, I have high frequency commodity price data that I need to analyze. My objective is to not assume any seasonal component and just identify a trend. Here is where I run into problems with R. There are two main functions that I know of to analyze this time series: decompose() and stl(). The problem is that they both take a ts object type with a frequency parameter greater than or equal to 2. Is there some way I can assume a frequency of 1 per unit time and still analyze this time series using R? I'm afraid that if I assume frequency greater than 1 per unit time, and seasonality is calculated using the frequency parameter, then my forecasts are going to depend on that assumption.

names(crude.data)=c('Date','Time','Price')
names(crude.data)
freq = 2
win.graph()
plot(crude.data$Time,crude.data$Price, type="l")
crude.data$Price = ts(crude.data$Price,frequency=freq) 

I want frequency to be 1 per unit time but then decompose() and stl() don't work!

dim(crude.data$Price)
decom = decompose(crude.data$Price)
win.graph()
plot(decom$random[2:200],type="line")
acf(decom$random[freq:length(decom$random-freq)])

Thank you.

+7  A: 

Both stl() and decompose() are for seasonal decomposition, so you must have a seasonal component. If you just want to estimate a trend, then any nonparametric smoothing method will do the job. For example:

fit <- loess(crude.data$Price ~ crude.data$Time)
plot(cbind(observed=crude.data$Price,trend=fit$fitted,random=fit$residuals),main="")
Rob Hyndman