在 R 中,auto.arima 无法捕获季节性
In R, auto.arima fails to capture seasonality
auto.arima()
没有为我的系列提供季节性成分,尽管我可以看到有一件礼物。该函数为我提供了一个非季节性的 ARIMA 阶模型 (5,0,0)。所以,当我尝试使用该模型进行预测时,它只是给出了平均值。时间序列为澳大利亚墨尔本十年来每日最低气温。
Click this link to see the data and the auto.arima forecast
`
library(readr)
temp <- read_csv("~/Downloads/Melbourne Minimum Temp.csv",
col_types = cols(Date = col_date(format = "%m/%d/%y"),
Temp = col_number()))
t <- ts(temp$Temp, start = temp$Date\[1], end = temp$Date[nrow(temp)])
auto.arima(t, trace = T)
`
尝试将数据用作 ts 对象、xts 对象和向量。
只是报告一个很好的解释 - 像往常一样 - Rob Hyndman 的博文。
https://robjhyndman.com/hyndsight/dailydata/
你问题的相关部分说(完全引用页面):
When the time series is long enough to take in more than a year, then
it may be necessary to allow for annual seasonality as well as weekly
seasonality. In that case, a multiple seasonal model such as TBATS is
required.
y <- msts(x, seasonal.periods=c(7,365.25))
fit <- tbats(y)
fc <- forecast(fit)
plot(fc)
This should capture the weekly pattern as well as the longer annual
pattern. The period 365.25 is the average length of a year allowing
for leap years. In some countries, alternative or additional year
lengths may be necessary.
我认为它完全符合您的要求。
我也试过简单地用 msts 创建时间序列
y <- msts(x[1:1800], seasonal.periods=c(7,365.25))
(为了更快,我把时间序列减半了)
然后 运行 auto.arima() 直接在上面,用 D=1
强制季节性成分
fc = auto.arima(y,D=1,trace=T,stepwise = F)
这需要一段时间.. 因为我设置了 stepwise = FALSE(如果你想让它查看所有没有快捷方式的组合,你也可以设置 approximation=FALSE)
Series: y
ARIMA(1,0,3)(0,1,0)[365]
Coefficients:
ar1 ma1 ma2 ma3
0.9036 -0.3647 -0.3278 -0.0733
s.e. 0.0500 0.0571 0.0405 0.0310
sigma^2 estimated as 12.63: log likelihood=-3854.1
AIC=7718.19 AICc=7718.23 BIC=7744.54
然后是预测
for_fc = forecast(fc)
plot(for_fc)
我在输出之上添加了一个带有完整时间序列(红色)的图形
情节(for_fc)
它似乎工作正常 - 但它只是一个快速测试。
auto.arima()
没有为我的系列提供季节性成分,尽管我可以看到有一件礼物。该函数为我提供了一个非季节性的 ARIMA 阶模型 (5,0,0)。所以,当我尝试使用该模型进行预测时,它只是给出了平均值。时间序列为澳大利亚墨尔本十年来每日最低气温。
Click this link to see the data and the auto.arima forecast
`
library(readr)
temp <- read_csv("~/Downloads/Melbourne Minimum Temp.csv",
col_types = cols(Date = col_date(format = "%m/%d/%y"),
Temp = col_number()))
t <- ts(temp$Temp, start = temp$Date\[1], end = temp$Date[nrow(temp)])
auto.arima(t, trace = T)
`
尝试将数据用作 ts 对象、xts 对象和向量。
只是报告一个很好的解释 - 像往常一样 - Rob Hyndman 的博文。
https://robjhyndman.com/hyndsight/dailydata/
你问题的相关部分说(完全引用页面):
When the time series is long enough to take in more than a year, then it may be necessary to allow for annual seasonality as well as weekly seasonality. In that case, a multiple seasonal model such as TBATS is required.
y <- msts(x, seasonal.periods=c(7,365.25))
fit <- tbats(y)
fc <- forecast(fit)
plot(fc)
This should capture the weekly pattern as well as the longer annual pattern. The period 365.25 is the average length of a year allowing for leap years. In some countries, alternative or additional year lengths may be necessary.
我认为它完全符合您的要求。
我也试过简单地用 msts 创建时间序列
y <- msts(x[1:1800], seasonal.periods=c(7,365.25))
(为了更快,我把时间序列减半了)
然后 运行 auto.arima() 直接在上面,用 D=1
强制季节性成分fc = auto.arima(y,D=1,trace=T,stepwise = F)
这需要一段时间.. 因为我设置了 stepwise = FALSE(如果你想让它查看所有没有快捷方式的组合,你也可以设置 approximation=FALSE)
Series: y
ARIMA(1,0,3)(0,1,0)[365]
Coefficients:
ar1 ma1 ma2 ma3
0.9036 -0.3647 -0.3278 -0.0733
s.e. 0.0500 0.0571 0.0405 0.0310
sigma^2 estimated as 12.63: log likelihood=-3854.1
AIC=7718.19 AICc=7718.23 BIC=7744.54
然后是预测
for_fc = forecast(fc)
plot(for_fc)
我在输出之上添加了一个带有完整时间序列(红色)的图形 情节(for_fc) 它似乎工作正常 - 但它只是一个快速测试。