避免在R中使用stl()或decompose()函数时做季节性假设

4
我有高频商品价格数据需要分析。我的目标是不假设任何季节性因素,只需确定趋势。在这里,我遇到了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) 

我希望频率在单位时间内为1,但是使用decompose()和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)])

谢谢。


我不确定我是否理解正确,但“频率为一”会是一个线性和/或抛物线趋势吗?否则,这听起来像是将每个观察作为自己的虚拟变量。季节性的本质是必须重复某些事情或者必须存在某种循环性——这必然意味着至少有2个周期。 - isomorphismes
1个回答

16

无论是stl()还是decompose()都是用于季节性分解,因此您必须具有季节性组件。如果您只想估计趋势,则任何非参数平滑方法都可以完成工作。例如:

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

Hyndman教授,您能推荐一个用于趋势估计的Python包吗? - Hari
https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html - thistleknot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接