R语言之时间序列图绘制 |
您所在的位置:网站首页 › 标志坐标图怎么画简单 › R语言之时间序列图绘制 |
目录 01 读取数据 02 赋值变量 03 时间序列值绘制 04 读取包 05 单位根检验,又称平稳性检验 06 自相关图和偏相关图 07 白噪声检验或纯随机性检验 08 模型拟合 09 显著性检验 10 预测未来趋势 结语: 我使用的是:R+Rstudio 读取数据(read.table),数据位置("F:/笔记/Rstudio/A1_7.csv") 首先找到文件 点击上方文件夹获取文件位置 复制文件位置“F:\笔记\Rstudio”后将“\”改为“/”,在后面加上文件名 改变后:"F:/笔记/Rstudio/A1_7.csv" sep=","(空格位置用“,”代替) header=T(数据第一行是标题,不属于数据) data(将数据赋值给data) data for(i in 0:3) print( + adfTest(x, + lag=i, + type="c", + title = "7级以上地震发生次数单位根检验")) Title: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 0 STATISTIC: Dickey-Fuller: -5.354 P VALUE: 0.01 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo Title: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 1 STATISTIC: Dickey-Fuller: -3.9179 P VALUE: 0.01 Description: Mon Jan 9 15:40:36 2023 by user: LenovoTitle: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 2 STATISTIC: Dickey-Fuller: -3.1832 P VALUE: 0.02451 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo Title: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 3 STATISTIC: Dickey-Fuller: -2.9558 P VALUE: 0.04427 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo Warning messages: 1: In adfTest(x, lag = i, type = "c", title = "7级以上地震发生次数单位根检验") : p-value smaller than printed p-value 2: In adfTest(x, lag = i, type = "c", title = "7级以上地震发生次数单位根检验") : p-value smaller than printed p-value > for(i in 0:3) print( + adfTest(x, + lag=i, + type="ct", + title = "7级以上地震发生次数单位根检验")) Title: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 0 STATISTIC: Dickey-Fuller: -5.5514 P VALUE: 0.01 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo Title: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 1 STATISTIC: Dickey-Fuller: -4.1418 P VALUE: 0.01 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo Title: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 2 STATISTIC: Dickey-Fuller: -3.5099 P VALUE: 0.04484 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo Title: 7级以上地震发生次数单位根检验 Test Results: PARAMETER: Lag Order: 3 STATISTIC: Dickey-Fuller: -3.3716 P VALUE: 0.06336 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo Warning messages: 1: In adfTest(x, lag = i, type = "ct", title = "7级以上地震发生次数单位根检验") : p-value smaller than printed p-value 2: In adfTest(x, lag = i, type = "ct", title = "7级以上地震发生次数单位根检验") : p-value smaller than printed p-value > adfTest(x) Title: Augmented Dickey-Fuller Test Test Results: PARAMETER: Lag Order: 1 STATISTIC: Dickey-Fuller: -1.0451 P VALUE: 0.28 Description: Mon Jan 9 15:40:36 2023 by user: Lenovo 从代码运行结果里找PVALUE的数值,数值大于0.05就是拒绝原假设,单位根不存在,序列平稳。 06 自相关图和偏相关图 par(mfrow=c(2,1))#分画布2行1列 acf(x) #自相关 pacf(x) #偏自相关acf自相关(上) pacf偏自相关(下) 观察两图,发现自相关拖尾,偏自相关1阶截尾,预测模型为AR模型 07 白噪声检验或纯随机性检验 for(k in 1:2) print( #白噪声检验,分析前后各一次 Box.test(x, lag=6*k, #type和l等价 type="Ljung-Box")) #服从卡方分布 #x-squared为卡方分布值,查表的值 #df为卡方检验自由度 #p-value 为p值 #若想显著性检验,检验目标为残差,验证残差是否为白噪声,为白噪声好代码运行结果: 观察p-value的值,两值均小于0.05,拒绝原假设,序列非白噪声,序列有继续研究的价值。 08 模型拟合 x.fit |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |