当前位置:文档之家› 时间序列分析讲义(下)

时间序列分析讲义(下)

事实上,通过IDENGTIFY语句,还可以实现序列 模型的识别,这个在下一章详细介绍。
时间序列分析讲义(下)
例2.2
data example2_2; input fred@@; year=intnx('year','1jan1970'd,_n_-1); format year year4.; cards; 97 154 137.7 149 164 157 188 204 179 210 202 218 209 204 211 206 214 217 210 217 219 211 233 316 221 239 215 228 219 239 224 234 227 298 332 245 357 301 389 ; proc arima data= example2_2; identify var=fred; run;
时间序列分析讲义(下)
第一章 SAS-时间序列数据
1.1 创建数据数据
1、数据直接录入
格式1
Data 数据集名; input 变量名1 变量名2 ;
cards; 数据
; run;
格式2
Data 数据集名; input 变量名1 变量名2@@;
cards; 数据
; run;
时间序列分析讲义(下)
例1-1 录入数据 3.41 3.45 3.42 3.53 3.45 方法1 data example1_1;input price;
时间序列分析讲义(下)
可以在数据库WORK看见数据集example1_4:
时间序列分析讲义(下)
时间序列分析讲义(下)
时间序列分析讲义(下)
3、缺失值插值
data example1_5;input price@@; t=intnx('month','1jan2005'd,_n_-1); format t date.;cards; 3.41 3.45 . 3.53 3.45 ; proc expand data=example1_5 out=example1_6;id t; proc print data=example1_5 ; proc print data=example1_6;run;
时间序列分析讲义(下)
时间序列分析讲义(下)
时间序列分析讲义(下)
描述性统计量
时间序列分析讲义(下)
自相关函数图
时间序列分析讲义(下)
时间序列分析讲义(下)
偏相关函数图
自相关和偏相关函数都能较快地进入2倍标准差内,认 为序列平稳.
时间序列分析讲义(下)
检验统计量的P值<0.001,序列不是白噪声,可以建模.
时间序列分析讲义(下)
可以在数据库WORK看见数据集ex1_3数据集中有3 个变量。
时间序列分析讲mple1_4;set example1_3; keep t logp; where t>='01mar2005'd; proc print data=example1_4;run;
时间序列分析讲义(下)
时间序列分析讲义(下)
时间序列分析讲义(下)
时间序列分析讲义(下)
时间序列分析讲义(下)
2.2 平稳检验与纯随机性检验 纯随机性检验也叫白噪声检验,这个检验着
SAS建模中至关重要,有两方面的作用: 对于待建模的时序,若检验结果为白噪声,则该
时序可不可以建模,一个白噪声序列是不能建立任 何模型的。
时间序列分析讲义(下)
proc gplot data= example3_1; plot x*time=1; symbol1 c=red,i=join,v=star; run; proc arima data=example3_1; identify var=x ; run;
时间序列分析讲义(下)
时序图在SAS分析中的作用: 时序图,直观观察序列的平稳性; 拟合效果图,直观地看到预测的效果。
时间序列分析讲义(下)
例2.1 以下表
时间序列分析讲义(下)
data example2_1; input price1 price2; time=intnx('month','01jul2004'd,_n_-1); format time date.;cards; 12.85 15.21 13.29 14.23 12.42 14.69 15.21 16.27 14.23 16.75 13.56 15.33 ; run; proc gplot data=example2_1; plot price1*time=1 price2*time=2/overlay; symbol1 c=black v=star i=join;symbol2 c=red v=circle i=spline; run;
以数据集example3_1为例来说明SAS序列模 型的识别的语句。
时间序列分析讲义(下)
例3.1
data example3_1; input x@@; time=_n_; cards; 0.30 -0.45 0.36 0.00 0.17 0.45 2.15 4.42 3.48 2.99 1.74 2.40 0.11 0.96 0.21 -0.10 -1.27 -1.45 -1.19 -1.47 -1.34 -1.02 -0.27 0.14 -0.07 0.10 -0.15 -0.36 -0.50 -1.93 -1.49 -2.35 -2.18 -0.39 -0.52 -2.24 -3.46 -3.97 -4.60 -3.09 -2.19 -1.21 0.78 0.88 2.07 1.44 1.50 0.29 -0.36 -0.97 -0.30 -0.28 0.80 0.91 1.95 1.77 1.80 0.56 -0.11 0.10 -0.56 -1.34 -2.47 0.07 -0.69 -1.96 0.04 1.59 0.20 0.39 1.06 -0.39 -0.16 2.07 1.35 1.46 1.50 0.94 -0.08 -0.66 -0.21 -0.77 -0.52 0.05 ;
可以在数据库WORK看见数据集example数据集中有两 个变量t和price。
我们没有输入时间变量的数据,但“t=_n_”命令 自动给时间变量赋值 。
时间序列分析讲义(下)
等间隔的年份时间数据可以利用间隔函数输入: 例1-2 录入下表中的数据:
我们可以运行如下程序:
data example1_2 ;input price@@; t=intnx('month','1jan2005'd,_n_-1); format t monyy.; cards; 101 82 66 35 31 7 ; run;
预测
SAS是通过IDENGTIFY、 Estimate及forecast三个语句来实 现这三个阶段的。
时间序列分析讲义(下)
3.1 模型识别 模型的识别可以通过IDENGTIFY语句实现 。
第二章提到,SAS的ARIMA过程中的IDENGTIFY 语句,不仅可以实现白噪声和平稳性的检验,还 可以实现序列模型的识别。
时间序列分析讲义(下)
cards; 3.41 3.45 3.42 3.53 3.45 ; run;
方法2
data example1_1;input price@@; cards; 3.41 3.45 3.42 3.53 3.45 ; run;
时间序列分析讲义(下)
说明:
(1)这2种方法都可以创建一个名叫example的临时 数据集,保存在数据库WORK中,本次开机可调用,关 机后数据不保存。 SAS提供了两个通用数据库:临时数据库WORK 和永 久数据库SASUSER。 SAS数据命名采用二级制:数 据库名.数据集名。 若命名中没有数据库名,则默认为临时数据库WORK 。
时间序列分析讲义(下)
可以在数据库WORK看见数据集example1_4:
时间序列分析讲义(下)
“proc print data=example1_5 ;” 是查看语句,可以在输出窗口看到两个数据集。
时间序列分析讲义(下)
第二章 SAS-时间序列预处理 2.1 时间序列图形 SAS时间序列作图的程序语句格式为: PROC GPLOT 数据集名 表明要对该数据集中的数据做图。
时间序列分析讲义(下)
若改为如下的程序:
data sassuser.example1_1; input price@@; cards; 3.41 3.45 3.42 3.53 3.45 ; run;
就创建了一个名叫 example1_1的永久数据集,保 存在永久数据库SASUSER中,关机后数据保存。
时间序列分析讲义(下)
可以在数据库WORK看见数据集ex1_2数据集中有两个 变量t和price。
时间序列分析讲义(下)
时间序列分析讲义(下)
format t monyy.指定时间的输出格式
此处monyy.指定时间的输出格式为月-年。
时间序列分析讲义(下)
3、 外部数据的读取
时间序列分析讲义(下)
对于建模的后的残差序列,若检验结果为白噪声, 模型通过检验,若残差不是白噪声则模型不通过。
平稳性检验的目的是确定该时序可不可以直接建 模,平稳序列(非白噪声)可以直接建模,非白噪 声非平稳(非白噪声)序列需要先做差分处理,然 后建模。
时间序列分析讲义(下)
SAS的ARIMA过程中的IDENGTIFY语句,提供了白 噪声检验的结果,同时提供了醒目的自相关、偏相 关函数图,可以帮助判 别平稳性。
时间序列分析讲义(下)
时间序列分析讲义(下)
本例IDENGTIFY得到的信息:
时间序列分析讲义(下)
序列自相关图
相关主题