如何提取并输出使用forecast函数的预测值,ARIMA model in R
来源:互联网 发布:用友进销存软件 编辑:程序博客网 时间:2024/06/05 17:30
Example code with given Fourier series order K
<R>#for daily time series forecasting and plot the forecasting result, ref : http://robjhyndman.com/hyndsight/longseasonality/n <- 2000m <- 200y <- ts(rnorm(n) + (1:n)%%100/30, f=m)fourier <- function(t,terms,period){ n <- length(t) X <- matrix(,nrow=n,ncol=2*terms) for(i in 1:terms) { X[,2*i-1] <- sin(2*pi*i*t/period) X[,2*i] <- cos(2*pi*i*t/period) } colnames(X) <- paste(c("S","C"),rep(1:terms,rep(2,terms)),sep="") return(X)}library(forecast)fit <- Arima(y, order=c(2,0,1), xreg=fourier(1:n,4,m))print(fit$aicc)pred = forecast(final_fit, h=2*m, xreg=fourier(n+1:(2*m),final_k,m))plot(pred)# finish plotting the forecasting result.print(pred$mean)# this is the forecasting values in the forecasting interval.# The code below is for writing the forecasting values in the file. ref:http://robjhyndman.com/hyndsight/batch-forecasting/fcast <- matrix(NA, nrow=2*m, ncol=1)fcast[,1] <- pred$meanwrite(t(fcast), file="result.csv", sep=",", ncol=ncol(fcast))</R>
Note
for the code above, we can see that the ‘pred’ is a list. According to the reference for the forecasting function (https://cran.r-project.org/web/packages/forecast/forecast.pdf), it has values list including ‘model’ to ‘fitted’. My trial tells me that pred[[4]] corresponds to pred$mean, i.e. the forecasting values.
Example code with Inferring Fourier series order K
Traversing all the possible K values. Choose the optimal K with the minimal AICc metric.
<R>min_aicc <- 10000000000final_k <- -1final_fit <- NULL for(k in seq(1, 15, by = 1)){fit <- auto.arima(y, seasonal=FALSE, xreg=fourier(1:n,k,m))print(k)print(fit$aicc) if(fit$aicc < min_aicc) { min_aicc <- fit$aicc final_k <- k final_fit <- fit }}print(final_k)print(final_fit$aicc)</R>
0 0
- 如何提取并输出使用forecast函数的预测值,ARIMA model in R
- R & ARIMA 时间序列预测
- R语言-时间序列-arima模型-forecast、tseries包
- #R#通过ARIMA自动拟合与预测
- Arima预测模型(R语言)
- Arima预测模型(R语言)
- ARIMA预测
- 使用ARIMA算法进行时间序列预测。
- 时间序列分析——ARIMA模型预测(R)
- R语言时间序列分析之ARIMA模型预测
- R语言 时间序列分析之ARIMA模型预测
- R中时间序列分析-趋势预测ARIMA
- 时间序列的分析和预测ARIMA
- 【R】auto.arima和Arima的联系和参数解释
- 使用OpenCV的函数findContours提取轮廓并绘制轮廓
- C# 实现Excel的线性插值Forecast函数
- Tensorflow保存模型,恢复模型,使用训练好的模型进行预测和提取中间输出(特征)
- Tensorflow保存模型,恢复模型,使用训练好的模型进行预测和提取中间输出(特征)【转】
- cocos2d-x-3.8.1在win10下自己创建和编译android工程
- BZOJ 1195 [HNOI2006]最短母串 状压DP
- http协议
- PROPAGATION_REQUIRED
- svn: Failed to run the WC DB work queue associated with
- 如何提取并输出使用forecast函数的预测值,ARIMA model in R
- 关于EXC_BAD_ACCESS,以及解决办法
- android绘制花边view-WaveLineView
- UE如何改变点击上传图片的弹出框的大小...
- 转自百度百科——eclips中的快捷键的总结
- Volley框架的学习总结(1)
- [渗透测试] 渗透测试板块TIPs
- Ios学习-oc学习1记录
- Linux 0.12内核与现代内核在内存管理上的区别