时间序列AR2模型程序.docx
《时间序列AR2模型程序.docx》由会员分享,可在线阅读,更多相关《时间序列AR2模型程序.docx(8页珍藏版)》请在冰点文库上搜索。
![时间序列AR2模型程序.docx](https://file1.bingdoc.com/fileroot1/2023-6/20/5bff6a2d-4592-4d0e-ae42-2953f0c60e0a/5bff6a2d-4592-4d0e-ae42-2953f0c60e0a1.gif)
时间序列AR2模型程序
时间序列AR
(2)模型程序
1、计算AR
(2)模型
的理论值,并作图,自协方差
=1,
=0.5。
在Matlab中输入如下程序:
>>clearall
>>r
(1)=0.5;
r
(2)=-0.125;
fort=3:
30
r(t)=0.75*r(t-1)-0.5*r(t-2);
end
>>r
r=
Columns1through6
0.5000 -0.1250 -0.3438 -0.1953 0.0254 0.1167
Columns7through12
0.0748 -0.0022 -0.0391 -0.0282 -0.0016 0.0129
Columns13through18
0.0105 0.0014 -0.0042 -0.0038 -0.0008 0.0013
Columns19through24
0.0014 0.0004 -0.0004 -0.0005 -0.0002 0.0001
Columns25through30
0.0002 0.0001 -0.0000 -0.0001 -0.0000 0.0000
>>plot(r)
由上图可看出AR
(2)模型的协方差函数是以负指数的数独趋于零的。
2、计算AR
(2)模型
的理论值,并作图,自相关系数
,
。
在Matlab中输入下列程序:
>>p
(1)=0.5;
>>p
(2)=-0.125;
>>fork=3:
30
p(k)=0.75*p(k-1)-0.5*p(k-2)
end
p=
Columns1through6
0.5000 -0.1250 -0.3438 -0.1953 0.0254 0.1167
Columns7through12
0.0748 -0.0022 -0.0391 -0.0282 -0.0016 0.0129
Columns13through18
0.0105 0.0014 -0.0042 -0.0038 -0.0008 0.0013
Columns19through24
0.0014 0.0004 -0.0004 -0.0005 -0.0002 0.0001
Columns25through30
0.0002 0.0001 -0.0000 -0.0001 -0.0000 0.0000
>>plot(p)
3.偏相关系数
=0.5,
,
在Matlab中输入以下程序:
>>l=10
f(1,1)=r
(1)
l=10
>>fork=2:
l
s1=r(k);
s2=1;
forj=1:
k-1
s1=s1-r(k-j)*f(k-1,j);
s2=s2-r(j)*f(k-1,j);
end
f(k,k)=s1/s2
forj=1:
k-1
f(k,j)=f(k-1,j)-f(k,k)*f(k-1,k-j);
end
end
f
f=
Columns1through6
0.5000 0 0 0 0 0
0.7500 -0.5000 0 0 0 0
0.7500 -0.5000 0 0 0 0
0.7500 -0.5000 0 0 0 0
0.7500 -0.5000 0 0 0 0
0.7500 -0.5000 0 0 0 0
0.7500 -0.5000 0 0 0 0
0.7500 -0.5000 0 0 0 0
0.7500 -0.5000 0 0 0 0
0 0 0 0 0 0
Columns7through10
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
4.利用AR
(2)模型
生成80个数据,在Matlab中输入如下程序:
>>randn('state',sum(clock));
elps=randn(1,80);
x
(1)=0;
x
(2)=0;
fort=3:
80
x(t)=0.75*x(t-1)-0.5*x(t-2)+elps(t);
end
x
x=
Columns1through6
0 0 -0.2492 -0.6748 -0.1084 -0.6113
Columns7through12
-2.4923 -0.7143 -0.0179 0.7345 0.8858 1.0636
Columns13through18
-0.1327 1.4434 -0.8127 -2.9505 -3.5379 -3.3865
Columns19through24
-0.6951 1.2985 2.0763 1.3498 -1.5169 -2.1432
Columns25through30
-2.4767 1.0650 -0.2907 -1.0784 1.1665 -0.9465
Columns31through36
-2.8014 -0.9212 2.2014 3.4788 1.5614 -0.5932
Columns37through42
-3.7326 -2.9347 -0.3274 0.0619 -0.5700 0.8801
Columns43through48
2.2475 0.0266 -0.3272 0.4410 0.8315 1.9017
Columns49through54
3.0902 1.9477 0.2166 -2.2133 -0.8312 2.7903
Columns55through60
3.5376 1.2748 -0.1106 0.3412 -0.3205 -0.7642
Columns61through66
0.6983 0.6822 -1.3009 -1.5067 -0.0793 1.4823
Columns67through72
2.9966 3.3724 1.5954 -0.7339 -1.0571 -1.8157
Columns73through78
-1.0558 0.0485 -0.7388 -1.0843 1.1825 0.7619
Columns79through80
-0.7860 -1.5674
>>plot(x)
利用
,计算
,并作图:
>>y=(x-mean(x));
gama0=var(x);
l=30;
>>forj=1:
l
gama(j)=y(j+1:
l)*y(1:
l-j)'/80;
end
>>gama
gama=
Columns1through6
0.4531 0.0607 -0.2502 -0.3999 -0.2065 -0.0156
Columns7through12
0.1400 0.1819 0.2083 0.1810 0.1161 0.0813