gpt4 book ai didi

R:如何在同一时间序列上绘制多个 ARIMA 预测

转载 作者:行者123 更新时间:2023-12-02 00:00:27 26 4
gpt4 key购买 nike

我想在同一个地 block 上用不同颜色绘制多个预测,但是,比例尺不对。我对任何其他方法持开放态度。

可重现的例子:

require(forecast)     

# MAKING DATA
data <- c(3.86000, 19.55810, 19.51091, 20.74048, 20.71333, 29.04191, 30.28864, 25.64300, 23.33368, 23.70870 , 26.16600 ,27.61286 , 27.88409 , 28.41400 , 24.81957 , 24.60952, 27.49857, 32.08000 , 29.98000, 27.49000 , 237.26150, 266.35478, 338.30000, 377.69476, 528.65905, 780.00000 )
a.ts <- ts(data,start=c(2005,1),frequency=12)

# FORECASTS
arima011_css =stats::arima(x = a.ts, order = c(0, 1, 1), method = "CSS") # css estimate
arima011_forecast = forecast(arima011_css, h=10, level=c(99.5))

arima321_css =stats::arima(x = a.ts, order = c(3, 2, 1), method = "CSS") # css estimate
arima321_forecast = forecast(arima321_css, h=10, level=c(99.5))

# MY ATTEMPT AT PLOTS
plot(arima321_forecast)
par(new=T)
plot(arima011_forecast)

enter image description here

最佳答案

这是类似于@jay.sf 但使用 ggplot2 的东西。

library(ggplot2)

autoplot(a.ts) +
autolayer(arima011_forecast, series = "ARIMA(0,1,1)", alpha = 0.5) +
autolayer(arima321_forecast, series = "ARIMA(3,2,1)", alpha = 0.5) +
guides(colour = guide_legend("Model"))

reprex package 创建于 2020-05-19 (v0.3.0)

关于R:如何在同一时间序列上绘制多个 ARIMA 预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61887022/

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