r - 我如何避免使用系列图 R 预测地块中的漏洞
问题描述
我写这个问题是因为我无法在情节中将系列与预测联系起来(我尝试了很多次)。
这是我使用的代码。
AA1<-AA_1
str(AA1)#OUTPUT: Time-Series [1:60] from 2013 to 2018: 309 368 1602 6742 19396
Serie1<-Serie_1
str(Serie1) ##OUTPUT:Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 60 obs. of 7 variables:
X_Reg_Mod_Completo <- cbind(A=ts(Serie1$A),B=ts(Serie1$B),
C=ts(Serie1$C), D=ts(Serie1$D),
E=ts(Google1$E), F=ts(Serie1$F))
Mod_Completo<-auto.arima(AA1, xreg=X_Reg_Mod_Completo, trace = TRUE, test = "kpss", ic="aic", seasonal = TRUE)
AIC(Mod_Completo)
FOR_Mod_Completo<-forecast(Mod_Completo,xreg=X_Reg_Mod_Completo)
plot(FOR_Mod_Completo,xlim=c(2016, 2019))
我的目标是避免 2018 年底和 2018 年之间的空白。
如果有人需要数据,请写评论,我会更新。
预先感谢您的帮助。
弗朗切斯科
解决方案
我已经尝试了一些东西,ggplot2
但没有过多地弄乱预测,也许它可以作为一个开始有所帮助:
library(forecast)
library(tidyverse)
fit <- auto.arima(WWWusage)
forec <- forecast(fit,h = 10)
现在,我们必须将 ts 和预测放入data.frame
s 中,绑定它们,并用 绘制结果ggplot2
:
# time series
ts_ <- data.frame(Point.Forecast = WWWusage,
Lo.80=NA,
Hi.80=NA,
Lo.95=NA,
Hi.95=NA,
type = 'ts')
# forecasting
forec <- data.frame(forec, type ='fc')
# together
tot <- union_all(ts_,forec)
# now add the date, in this case I put a sequence: len
tot$time <- seq( as.Date("2011-07-01"), by=1, len=nrow(ts_)+nrow(forec))
现在你可以绘制它:
ggplot(tot) + geom_line(aes(time,Point.Forecast))+
geom_line(aes(time, Lo.95))+
geom_line(aes(time, Hi.95))+
geom_line(aes(time, Lo.80))+
geom_line(aes(time, Hi.80))+
geom_vline(xintercept=tot$time[nrow(ts_)], color = 'red') + theme_light()
推荐阅读
- c++ - hello world 示例,用于在 C 中使用 SSL 的猫鼬网络服务器
- aerospike - 如何在 aerospike nodejs 客户端中运行多个谓词映射键过滤器?
- django - 在 Django 中动态从 view.py 中的引导手风琴菜单获取数据
- typescript - 删除函数不带参数值
- python - python'switches'(dict)是否应该调用内部的每个函数?
- python - 如何使用 Python 通过 knox 与 Hbase 交互?
- r - 带有“lm”的线性(对数对数)模型:如何获得预测值总和的预测方差
- azure - az vm run-command failed
- bluetooth - 支持蓝牙 5 的设备是否同时支持低功耗和经典?
- bash - How to use linux find command to replace special characters in all file names?