R 语言 ar模型

 R语言ar模型简介

    利用R语言实现时间序列的预报是一件很方便的事,但是目前由于其他语言的强大,几乎很难找到关于R的好的帖子。这里总结下本人利用ar模型预测的简单过程:

    首先数据的读入 data = read.table('L:\\R数据\\1.txt') 这个的作用是将1.txt中的数据流读入到一个数据集中,这个数据集采用表格形式存储数据流,默认的为空格符分割字段。

    data.y = data[1]将data表中的第一列数据提取出来

    plot(ts(data.y))  注意前面提取的data.y并不是一个时间序列(也就是只有obs,没有time_series),而是一个数据集列对象,为了做时间序列分析,还需利用ts命令将其转换成一个时间序列(自动补齐时间坐标轴上的序列,默认从0到obs的个数减1,间隔1),plot是画图命令

    pacf(data.y)偏自相关检验确定ar模型阶数  (acf(data.y)自相关检验) 

    win.graph() 重新打开一个画图窗口并处于激活状态

    ar(data.y,FALSE,3)  建立ar回归模型,3为阶数

     model = arima(ts(data.y),order=c(4,0,0))  英文帮助文档解释,不翻译了:This function is identical to the arimax function which builds on and extends the capability of the arima function in R stats by allowing the incorporation of transfer functions, and innovative and additive outliers. For backward compatitibility, the function is also named arima. Note in the computation of AIC, the number of parameters excludes the noise variance. This function is heavily based on the arima function of the stats core of R。注意如果ts(data.y)不做ts转换回报:错误于hasTsp(x) : 时间系列参数设定不对 的错误

    m = plot(model,n.ahead = 12) 预测语句,n.ahead 预测期数

 standard(model1)      r计算模型的线性或广义线性回归的诊断信息

   

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值