简体   繁体   English

有没有更简单的方法来提取R中ARIMA的组合拟合值和预测值?

[英]Is there an easier way to extract combined fitted values and forecast values of an ARIMA in R?

Simple question -- I want to extract the fitted values and mean forecast of an ARIMA as one single time series, using R. Right now, I use this slow and cumbersome code: 一个简单的问题-我想使用R提取ARIMA的拟合值和均值预测作为一个单一的时间序列。现在,我使用以下缓慢而麻烦的代码:

x<-auto.arima(y)
z<-forecast(x, 365)

fitted<-z$fitted
mean<-z$mean
merged<-merge.zoo(fitted, mean)
merged$fitted[is.na(merged$fitted)]<-0
merged$mean[is.na(merged$mean)]<-0

finalforecast<-merged$fitted+ merged$mean

There must be an esier way to do this, but looking at the documentation, I'm drawing a blank. 必须有一种简便的方法来执行此操作,但是在查看文档时,我处于空白状态。 I really want to avoid the hassle of merging the time series, then dropping in zeroes (to fill the NAs), and then doing the addition. 我真的想避免合并时间序列的麻烦,然后放入零(填充NA),然后进行加法。 I know I can create my own function, but I'd be surprised if there isn't something simple that's pre-baked. 我知道我可以创建自己的函数,但是如果没有简单的预编译功能,我会感到惊讶。

Thoughts? 有什么想法吗?

Why not just c(z$fitted, z$mean) ? 为什么不只是c(z$fitted, z$mean)

EDIT: If you need a ts object: ts(c(z$fitted, z$mean), start=start(y), frequency=frequency(y)) 编辑:如果您需要一个ts对象: ts(c(z$fitted, z$mean), start=start(y), frequency=frequency(y))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM