gpt4 book ai didi

使用STL和Arima的R预测季节和数据趋势

转载 作者:行者123 更新时间:2023-12-04 03:51:00 46 4
gpt4 key购买 nike

我有一个包含季节性成分,趋势和军备成分的数据系列。我想根据历史来预测这个系列。

我可以使用该程序

data_ts <- ts(data, frequency = 24)
data_deseason <- stl(data_ts, t.window=50, s.window='periodic', robust=TRUE)
f <- forecast(data_deseason, method='arima', h = N)

但是这样做时,我无法选择Arima部分的参数,而我想要这样做。上面的代码似乎使用了auto.arima之类的东西,因为我自己选择了arima参数-但它的运行速度确实比auto.arima快得多,因此不确定发生了什么。

或者,我可以使用以上方法将数据分为季节,趋势和剩余部分。但是,我该如何预测呢?我应该为趋势和其余模型都建立一个模型吗?
trend_arima <- Arima(data_deseason$time.series[,'trend'], order = c(1,1,1))
remainder_arima <- Arima(data_deseason$time.series[,'remainder'], order = c(1,1,1))

然后使用Forecast()并添加上述两个组成部分和季节。还是有某种方法可以提取STL发现的趋势模型?

谢谢你的提示:)
本杰明

最佳答案

forecast.stl函数将auto.arima用于其余系列。它之所以快速,是因为它不需要考虑季节性ARIMA模型。

您可以通过forecastfunction参数选择具有特定参数的特定模型。例如,假设您想使用参数为0.7的AR(1),则下面的代码可以做到:

data_ts <- ts(data, frequency = 24)
data_deseason <- stl(data_ts, t.window=50, s.window='periodic', robust=TRUE)
f <- forecast(data_deseason, h=N,
forecastfunction=function(x,h,level){
fit <- Arima(x, order=c(1,0,0), fixed=0.7, include.mean=FALSE)
return(forecast(fit,h=N,level=level))})
plot(f)

如果只想选择ARIMA顺序,而不要选择参数,则省去 fixed参数。

关于使用STL和Arima的R预测季节和数据趋势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29347791/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com