model x=t/ nlag=5 backstep method=ml noint;output out=out p=xp pm=trend;proc gplot data=out;plot x*t=2 xp*t=3 trend*t=4 / overlay;symbol2 v=star i=none c=black;symbol3 v=none i=join c=red w=2 l=3;symbol4 v=none i=join c=green w=2;run;语句说明:“outputout=outp=xppm=trend;”,该命令是指令系统将部分结果输入临时数据集OUT,选择输出的第一个信息为整体模型的拟合值(P选项),该拟合变量取名为XP;选择输出的第二个信息为线性趋势拟合值(PM选项),还可以选择R选项输出拟合残差项,本例不要求输出此项。输出图像如图4-4所示。180国信专#社管务#有公员专务有公司**4050102030t图4-4拟合效果图延迟因变量回归模型2.3proc autoreg data=example5_2;model x-lagx/lagdep=lagx;run;语句说明:(1)首先在DATA步中添加命令“lagx=lag(x);”,该语句指令系统使用延迟函数生成序列x的1阶延迟序列,并将该序列赋值给变量lagx。(2)“modelx=lagx/lagdep=lagx;”指令系统建立带有延迟因变量的22
22 model x=t/ nlag=5 backstep method=ml noint; output out=out p=xp pm=trend; proc gplot data=out; plot x*t=2 xp*t=3 trend*t=4 / overlay; symbol2 v=star i=none c=black; symbol3 v=none i=join c=red w=2 l=3; symbol4 v=none i=join c=green w=2; run; 语句说明: “output out=out p=xp pm=trend;”,该命令是指令系统将部分结果 输入临时数据集 OUT,选择输出的第一个信息为整体模型的拟合值(P 选项), 该拟合变量取名为 XP;选择输出的第二个信息为线性趋势拟合值(PM 选项), 还可以选择 R 选项输出拟合残差项,本例不要求输出此项。 输出图像如图4-4所示。 图4-4 拟合效果图 2.3 延迟因变量回归模型 proc autoreg data=example5_2; model x=lagx/lagdep=lagx; run; 语句说明: (1)首先在 DATA 步中添加命令“lagx=lag(x);”,该语句指令系统使用延 迟函数生成序列 x 的 1 阶延迟序列,并将该序列赋值给变量 lagx。 (2)“model x=lagx/lagdep=lagx;”指令系统建立带有延迟因变量的
回归模型并通过LAGDEP选项指令被延迟的因变量名。本例带延迟因变量回归分析结果如下所示。Vependent YariableOrdinary Least Squares Estimates11462.72DFESSE39MSERootMSE17.14398293.91590SBCAIC354.744717351.3175730.8701Total,R-SquareRegress R-Square0.87010.29160.3853Durbin hPr<hStandardPASPTEOTDFVariableEstimatet ValueError4.07211.46Intercept115.94590.15230.94010.058216.16<.0001lagx由于带有延迟因变量,所以这种场合在回归模型估计结果输出的是Durbinh统计量。本例中Durbinh统计量的分布函数达到0.3853,这表示残差序列不存在显著地相关性,不需要考虑对残差序列继续拟合自回归模型。参数检验结果,如下所示。StandardApproxDFPr >/tVariableEstimatet YalueErrorIntercept115.94594.07211.460.15230.940116.16<.00010.0582lagx在显著性水平默认为0.05的条件下,截距项不显著(P值大于0.05),所以可以考虑在模型拟合命令中增加NOINT选项。最后输出拟合结果,并绘制拟合时序图,相关命令如下:proc autoreg data=example5_2;model x=lagx/lagdep=lagx noint;output out=out p=xp;proc gplot data=out;plot x*t=2 xp*t=3 / overlay;symbol2v=star i=none c=black;symbol3 v=none i=join c=red w=2;run;输出的拟合效果图如图4-5所示。23
23 回归模型并通过LAGDEP选项指令被延迟的因变量名。本例带延迟因变量回归分 析结果如下所示。 由于带有延迟因变量,所以这种场合在回归模型估计结果输出的是 Durbin h 统计量。本例中 Durbin h 统计量的分布函数达到 0.3853,这表示残差序列不存在 显著地相关性,不需要考虑对残差序列继续拟合自回归模型。 参数检验结果,如下所示。 在显著性水平默认为 0.05 的条件下,截距项不显著(P 值大于 0.05),所以 可以考虑在模型拟合命令中增加 NOINT 选项。最后输出拟合结果,并绘制拟合 时序图,相关命令如下: proc autoreg data=example5_2; model x=lagx/lagdep=lagx noint; output out=out p=xp; proc gplot data=out; plot x*t=2 xp*t=3 / overlay; symbol2 v=star i=none c=black; symbol3 v=none i=join c=red w=2; run; 输出的拟合效果图如图 4-5 所示
1801701601001###n05331a50D304020+图4-5带有延迟因变量的回归模型拟合效果图3拟合GARCH模型SAS系统中AUTOREG过程功能非常强大,不仅可以提供上述的分析功能,还可以提供异方差性检验乃至条件异方差模型建模。以临时数据集example53数据为例,介绍GARCH模型的拟合,相关命令如下:dataexample5_3;input x@@;t=_n_icards;10.7713.3016.6419.5418.9720.5224.3623.51 27.16 30.80 31.84 31.63 32.68 34.9033.8533.0935.4635.3239.9437.47 35.2433.03 32.67 35.20 32.36 32.34 38.45 38.1732.1439.7049.4247.8648.3462.5063.5667.6164.5966.1767.5076.1279.31.78.8581.34 87.06 86.41 93.20 82.95 72.96 61.1061.2771.5888.3498.7097.3197.1791.1780.2085.1281.4070.8757.7552.3567.5087.9585.4684.5598.16102.42113.02119.95122.37126.96122.79127.96139.20141.05 140.87137.08145.53145.59134.36122.54106.9297.23110.39132.40 152.30 154.91 152.69 162.67 160.31142.57146.54153.83141.81 157.83161.79142.0724
24 图4-5 带有延迟因变量的回归模型拟合效果图 3 拟合 GARCH 模型 SAS 系统中 AUTOREG 过程功能非常强大,不仅可以提供上述的分析功能, 还可以提供异方差性检验乃至条件异方差模型建模。以临时数据集 example5_3 数据为例,介绍 GARCH 模型的拟合,相关命令如下: data example5_3; input x@@; t=_n_; cards; 10.77 13.30 16.64 19.54 18.97 20.52 24.36 23.51 27.16 30.80 31.84 31.63 32.68 34.90 33.85 33.09 35.46 35.32 39.94 37.47 35.24 33.03 32.67 35.20 32.36 32.34 38.45 38.17 32.14 39.70 49.42 47.86 48.34 62.50 63.56 67.61 64.59 66.17 67.50 76.12 79.31 78.85 81.34 87.06 86.41 93.20 82.95 72.96 61.10 61.27 71.58 88.34 98.70 97.31 97.17 91.17 80.20 85.12 81.40 70.87 57.75 52.35 67.50 87.95 85.46 84.55 98.16 102.42 113.02 119.95 122.37 126.96 122.79 127.96 139.20 141.05 140.87 137.08 145.53 145.59 134.36 122.54 106.92 97.23 110.39 132.40 152.30 154.91 152.69 162.67 160.31 142.57 146.54 153.83 141.81 157.83 161.79 142.07
139.43140.92154.61172.33191.78199.27197.57189.29181.49166.84154.28150.12165.17170.32;proc gplot data=example5_3;plot x*t=l;symboll c=black i=join v=start;proc autoreg data=example5_3;model x=t/nlag=5 dwprob archtest;model x=t/nlag=2 noint garch=(p=l,q=1);output out=out p=p residual=residual lcl=lcl ucl=ucl cev=cev;data out;set out;195=-1.96*sqrt(51.42515);u95=1.96*sqrt(51.42515);Lcl_GARCH=-1.96*sqrt(cev);Ucl_GARCH=1.96*sqrt(cev);Lcl_p=p-1.96*sqrt(cev);Ucl_p=p+1.96*sqrt(cev);proc gplot data=out;plotresidual*t=2195*t=3Lcl_GARCH*t=4u95*t=3Ucl_GARCH*t=4/overlay;plot x*t=5 lcl*t=3 LCL_p*t=4 ucl*t=3 UCL_p*t=4/overlay;symbol2 c=green i=needle v=none;symbol3 v=black i=join c=none w=2 l=2;symbol4 c=red i=join v=none;symbol5 c=green i=join v=none;run;该序列输出时序图如图4-6所示。25
25 139.43 140.92 154.61 172.33 191.78 199.27 197.57 189.29 181.49 166.84 154.28 150.12 165.17 170.32 ; proc gplot data=example5_3; plot x*t=1; symbol1 c=black i=join v=start; proc autoreg data=example5_3; model x=t/nlag=5 dwprob archtest; model x=t/nlag=2 noint garch=(p=1,q=1); output out=out p=p residual=residual lcl=lcl ucl=ucl cev=cev; data out; set out; l95=-1.96*sqrt(51.42515); u95=1.96*sqrt(51.42515); Lcl_GARCH=-1.96*sqrt(cev); Ucl_GARCH=1.96*sqrt(cev); Lcl_p=p-1.96*sqrt(cev); Ucl_p=p+1.96*sqrt(cev); proc gplot data=out; plot residual*t=2 l95*t=3 Lcl_GARCH*t=4 u95*t=3 Ucl_GARCH*t=4/overlay; plot x*t=5 lcl*t=3 LCL_p*t=4 ucl*t=3 UCL_p*t=4/overlay; symbol2 c=green i=needle v=none; symbol3 v=black i=join c=none w=2 l=2; symbol4 c=red i=join v=none; symbol5 c=green i=join v=none; run; 该序列输出时序图如图 4-6 所示
文国#EEES公600810000010-0102030405060708090100110120t图4-6序列时序图时序图显示序列具有显著线性递增趋势,目波动幅度随时间递增,所以考虑使用AUTOREG过程建立序列Xt?关于时间t的线性回归模型,并检验残差序列的自相关性和异方差性,如果检验结果显示残差序列具有显著自相关性,建立残差自回归模型;如果残差序列具有显著异方差性,则要建立条件异方差模型。语句说明:(1)“modelx=t/nlag=5 dwprobarchtest;”,该命令指令系统建立序列(Xt)关于时间t的线性回归模型,并检验残差序列5阶延迟的自相关性并输出DW检验的P值,同时对残差序列进行异方差检验。普通最小二乘估计输出结果中DW检验结果显示残差序列具有显著的正相关性,如下所示。Ordinary Least Squares Est imatesDFE24013.8586110218.30781Root MSE14.77524SBC928.482631AIC923.0456330.9184Total R-Square0.9184Regress R-Square0.3280Pr<DW<.0001Durbin-Watson1.0000Pr > DW残差序列5阶延迟自相关图显示残差序列至少具有2阶显著自相关性,如图4-7所示。Estimates of Autocorrelations-198765432101234567891LagCovarianceCorrelat ion214.401.000000kaokk1179.10.835094水激腺冰术求求冰术求激冰术求2.3116.90.54511058.46830.272694*****47.79430.036352&5-22.9080-0.106843图4-7残差序列自相关图26
26 图4-6 序列时序图 时序图显示序列具有显著线性递增趋势,且波动幅度随时间递增,所以考虑 使用 AUTOREG 过程建立序列{Xt}关于时间 t 的线性回归模型,并检验残差序列 的自相关性和异方差性,如果检验结果显示残差序列具有显著自相关性,建立残 差自回归模型;如果残差序列具有显著异方差性,则要建立条件异方差模型。 语句说明: (1)“model x=t/nlag=5 dwprob archtest;”,该命令指令系统 建立序列{Xt}关于时间 t 的线性回归模型,并检验残差序列 5 阶延迟的自相关性 并输出 DW 检验的 P 值,同时对残差序列进行异方差检验。 普通最小二乘估计输出结果中DW检验结果显示残差序列具有显著的正相 关性,如下所示。 残差序列 5 阶延迟自相关图显示残差序列至少具有 2 阶显著自相关性,如图 4-7 所示。 图4-7 残差序列自相关图