避免在R中使用stl()或分解()的季节性假设

1 r time-series

我有需要分析的高频商品价格数据.我的目标是不假设任何季节性因素,只是确定趋势.这是我遇到R问题的地方.我知道分析这个时间序列有两个主要功能:decompose()和stl().问题是他们都采用频率参数大于或等于2的ts对象类型.有什么方法我可以假设每单位时间的频率为1并且仍然使用R来分析这个时间序列?我担心如果我假设每单位时间的频率大于1,并且使用频率参数计算季节性,那么我的预测将取决于该假设.

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) 
Run Code Online (Sandbox Code Playgroud)

我希望频率为每单位时间1,但然后分解()和stl()不起作用!

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)])
Run Code Online (Sandbox Code Playgroud)

谢谢.

Rob*_*man 13

两者stl()decompose()季节性的分解,所以你必须有一个季节性成分.如果您只想估计趋势,那么任何非参数平滑方法都可以完成这项工作.例如:

fit <- loess(crude.data$Price ~ crude.data$Time)
plot(cbind(observed=crude.data$Price,trend=fit$fitted,random=fit$residuals),main="")
Run Code Online (Sandbox Code Playgroud)