Download Monahan, J.F.Two Algorithms for Analysis of ARMA Time Series Models."

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Matrix (mathematics) wikipedia , lookup

Jordan normal form wikipedia , lookup

Determinant wikipedia , lookup

Perron–Frobenius theorem wikipedia , lookup

Orthogonal matrix wikipedia , lookup

Four-vector wikipedia , lookup

Singular-value decomposition wikipedia , lookup

Cayley–Hamilton theorem wikipedia , lookup

Non-negative matrix factorization wikipedia , lookup

Gaussian elimination wikipedia , lookup

Principal component analysis wikipedia , lookup

Matrix multiplication wikipedia , lookup

Matrix calculus wikipedia , lookup

Transcript
TVJO
ALGORITHMS FOR ANALYSIS OF ARMA TIME SERIES MODELS
Abstract
Ansley (1978) derived an algorithm to compute the likelihood function of
data from an ARMA time series model.
The algorithm reported here follows
Ansley's basic idea but has some different features.
While it cannot accom-
modate seasonal models, it estimates the mean, gives forecasts and their
covariance matrix, and avoids computing square roots.
A second algorithm is
described which computes the necessarily information for a structured
Bayesian analysis.
I.
Notation and Definitions
Consider the autoregressive-moving average process
{Zt}' of order
(p,q), described by (1.1)
(1.1)
where
Zt - ~lZt - 1 - ... - ~ PZt-p
a 's
are iid normal random variables each having a normal distribu-
t
tion with mean zero and variance
observed:
Z = (zl, .•. ,zN)
T
a
2
a
A finite segment of this process is
which then has an N-dimensional multivariate
and covariance matrix
normal distribution with mean vector
The matrix
~
is described by
(1.2)
a
where the covariance function
characterizes this stationary time series
process.
By taking variances of both sides of (1.1), the covariance
function
a
can be determined
Cov (z t -~lz t- l···-~P Zt -p ' Zt+ s -~lZt+s- l···-~q Zt + s-q )
(1.3)
=
I r
i=O j=O
where
~o
= 6
0
= -1
and
~i
~. ~ J.a(!s+i-j I) =
1
= 6j = 0
for
I
j=O
i > P
(Cf. Anderson (1971, p. 237) and McLeod (1975)).
6.6,+
J J s
or
j
if s > 0
> q •
2
Since forecasting is of primary interest, the distribution of the future
n observations, that is
zF
=
(zN+l"",zN+n)
multivariate normal distribution with mean
covariance matrix
2 *
craA
nN
T
~ln
, conditional on
+
~,
-1
A21~ (zN-~~)
has a
and
where
~+n
=
n
and
In the notation to be used here,
Note that
A
-""N+n
is a function of
II.
Haximum Likelihood
The analysis for applying the maximum likelihood approach to this problem
is rather straightforward, but only when the model M = (p,q)
is assumed known.
The density of the observations is given by
(2.1)
By taking the natural
(2.2)
logarit~,
2
the log-likelihood function is given by
1
T -1
Cl-N/2lncra-;2tnl~1 - 2cr 2 (z-~ln) ~ (z-~lN)
a
3
C 's
where
i
are constants.
To concentrate on
~,
setting
yields:
(2.3)
Concentrating now on
0'
2
, setting
a
" 2,
a,Q,(~,cr
.
a
",)
'I' /"10'2
a
a
to zero
which yields
which involves the quadratic form
The concentrated log-
likelihood function is not
(2.4)
The MLE for the remaining parameters,
$
which must be found numerically.
,Q,3(1jJ),
is that vector
{Zt}
which maximizes
Note that for identifiability
purposes, the values of the parameter vector
region which insures the process
1jJ
1jJ
must be restricted to that
to be stationary and invertible.
The forecast function for the maximum likelihood approach is quite
simple, again, given M.
2
(zF!J.i'O"a,z,1jJ):
(2.5)
That is, the forecast is just the mean of
4
~
Likewise, the desired covariance matrix for the forecasts treats
as given:
(2.6)
The objective of this paper is to describe the algorithm ARMAML
i3(~)'
compute the concentrated likelihood function
covariance matrix.
(2.6).
to
the forecasts and their
The expressions for these are given by (2.4), (2.5) and
~.
All of. these,1are, again, given a set of ARMA parameters
III.
Bayesian Analysis
For the purposes of this paper, the description of the Bayesian approach
for which the algorithm presented here is intended begins: conditional on the
·e
model (p,q) and the parameters
(~,e).
Given
the prior distribution on the precision
.
var1ance
.
02
,1S
a
the model and the ARMA parameters,
T, the reciprocal of the disturbance
. h s h ape parameter
gamma W1t
a
and scale parameter
S ,
Le. ,
TI(rlp,q,~,e)
(3.1)
.where, again,
1/0
r ::
2
.
a
=
sa a-I -Sr
rea)
r
e
Conditional on
the process mean is normal with mean
Two distributions are now needed.
the observations
z
y
,r
>
r, p, q,
0 .
~
and precision
and e,
~r
the prior on
•
One is the unconditional distribution of
(still, however, conditional on the model and
~,
the ARMA
parameters), which is multivariate Student's t, N dimensional (naturally),
2a degrees of freedom, location vector
y~
and precision matrix
~~+~-llN~)-l (see DeGroot (1970), p. 59 for the definition of multivariate
t).
The density function for
z
is given by
~,
5
-II'&.
r(N/2 +a)
I~ + -r-l~~1
.
(o./S)N/2
(3.2)
The other important
distrib~tion
is the posterior distribution of the
forecasts, which is multivariate Student's t with
b + ca
degrees of freedom, location vector
n
20. + N
dimensions,
and precision matrix
(3.3)
where
a
= 1n
A ~-lL_
21-""N ~
-
-1
b = A21~ z
(3.4)
J
c = E ll\
Z
T -1
T -1
= (,y+z ~ ~) / ( -r+J.NAN~)
.
Notice that the main difference in the computation of the forecasts and the
covariance (precision, in this case) matrix between the maximum likelihood
and the Bayesian methods is the computation of a and b, which is not a great
hardship.
The quadratic form in the distribution of
z
is slightly more
difficult.
IV .
The Algori thIn ARMAML
The concentrated likelihood function given by 2.4 requires four scalars:
z
T -1
~
z,
T -1
Z ~{ ~.
the forecasts, i.e., the mean of
Additionally, two others are desired:
zFlz , which is
6
and their covariance matrix:
Note that
The algorithm to be described below is basically a modification of
Ansley's (1978, 1979).
Consider the
(N+n)
(N+n)
by
partitioned as
matrix
B
m,N
(4 •.1)
where
B
m,N
(-cj>p-cj>p-l
...
is
N by
-cj>ll),
unit lower triangular.
.-
N and each row of
(B
1
B )
includes
n
with zeroes elsewhere, staggered such that
B
m,N
Now
(4.2)
is also partitioned (with
rm
0
B
B
N-m
B
n
m = max(p,q))
=
B
m,N
3
so that
B
N-m
Note
has the same structure as
have the same structure:
Band
n
unit lower triangular and banded.
Now note the following product:
B
T
uA B
m,N"~
(4.4)
m,N
B
A_B
m,N-~
is
T
T
+ B_A
B
1
m,N"-12 n
7
But this product can be partitioned:
m
m T
BN+m~+n (BN+n ) =
(4.4)
where
last
Am = cov mx
(N+n-m)
of
~-A
A
m
T
D
1
0
D
1
C
1
E
N-m
0
E
C
2
n
m
N-m
process and
m
T
n
C (N-m
1
by
N-m) ,
C ,
2
and the
rows and columns, are the covariance matrices of a MA
process of appropriate length with the same parameters
(q and 6)
as always.
Hence all of the matrices are banded and can be mostly zeroes.
The crux of the algorithm is that the matrix
B-A_B T
m,N""£'l m,N
is a synnnetric,
positive definite banded matrix, with bandwidth not exceeding m, and, hence,
has a factorization of the form
banded and D is diagonal.
LDL
T
where
L
is unit lower triangular and
This factorization is slightly different than that
used by Ansley (1979) which can be found (in Algol) in Martin and Wilkinson
(1971).
since
The LDL T factorization avoids computing square roots.
IBm,N 1 = 1,
that
I~l
= IDI,
which is easily computed.
To compute the bilinear forms in
(4.5)
~,
=z
z, and
and
z
-1
~
, say, compute
T T
-1
Bm, N(Bm,N""£'l
A Bm,·
N) Bm, N1N
= zT~llN
and similarly obtain
Note also,
T -1
~
z .
8
To compute the forecasts, note that for an arbitrary vector a,
(0 ET)L-Tn-1(L-1Bm,Na)
(4.6)
= (0 ET)(LnLT)-~m,Na
T
= (B1A-Bm,
N+
T
T
-1
BnAZlBm, N)(B~-B
N) Bm, Na
m,N""~ m,J:
= B1a
-1
-~
+
BnA21~ a .
(4.7)
Sinc~
the necessary expression is
substituting
~
and
z
for
a
in (4.7) leaves the
the only extra computation (see below for
(0 ET)r.T) .
Now to compute the covariance matrix for the forecasts:
note the following expressions:
T
T
-(B 1An Bm,J:N + BZAZ1Bm,l'jN)(Bm,~-n
-~-B m,J:N)
-1
T
(B~"B1
m,W"""N
T
+ Bm,W·~12B)
n
(4.8)
Hence the needed computation is merely
(4.9)
-1'
3 :!
Note that the bracketed expression above is the one needed in (4.7).
9
V.
The algorithm BARMAD
follows
for (3.2), (3.3) and (3.4).
a
and
b
Other Algorithms
~~1L
but computes the expressions needed
The essential differendes are that both vectors
of (3.4) must be computed and that a scaled outer product of
a
must be added onto the covariance matrix calculated in ARMAML.
Algorithm CFARMA yields the covariance function
0
of (1.2).
The
method follows precisely the method of McLeod (1975).
Algorithm GETSET computes the entries of the covariance matrix in (4.4):
A
is found in
AMZ
D
l
is found in
Dl
m
C , E, C
2
l
·e
are found in
CC
Algorithm GETSET is a set-up algorithm (it calls CFARMA); requests for entries
of (4.4) are supplied through GRETA.
Algorithm ADJUST implements a device for avoiding overflow in the computation of the determinant by storing it in the form
DET'2
IID
.
Algorithm CRSEPP solves linear equations by the Crout factorization using
partial pivoting and is called by CFARMA.
10
References
Anderson, T. W.
New York.
(1970).
The Statistical Analysis of Time Series, Wiley,
Ansley, Craig F. (1979). "An Algorithm for the Exact Likelihood of a Mixed
Autoregressive-Moving Average Process," Biometrika 66, 1, pp. 59-65.
Ansley, Craig F. (1978). Subroutine ARMA -- E~act Likelihood for Univariate
ARMA Processes. Unpublished program documentation.
DeGroot, Morris H.
New York.
(1970).
Optimai Statistical Decisions.
McGraw-Hill,
Martin, R. S. and J. H. Wilkinson. (1971). Symmetric Decomposition of
Positive Definite Band Matrices, Numerische Mathematik 1, 355-61.
McLeod, Ian. (1975). Derivation of the Theoretical Autocovariance Function
of Autoregressive-Moving Average Time Series, Applied Statistics 24,
2, pp. 255-6. Correction: ~,p. 194.
APPENDIX
Listing of Programs
ARMAML
BARMAn
CFARMA
GRETA
ADJUST
GETSET
CRSEPP
00010
_0020 C
~0030 C
00040 C
00050 C
00060 C
00070 C
00080 C
00090
00100
00110
00120
00130
00140 C
00150 C
00160
00170
00180
00190 C
00200 C
00210 C
00220
00230
00240
00250 C
00260
0270
• 0280
00290
00300
00310
00320
00330
00340
00350
00360
00370
00380
00390 C
00400 C
SU8ROUTINE ARMAML(Z,P,Q,N,PHI,THETA,ZHM,DET,IID,QF,F,COVF,NS)
Z,P,Q,PHI,THETA
N=LENGTH OF SERIES; NS=NO. OF FORECASTS
OUT ZHM=MU*HAT ESTIMATE OF MEAN
OUT DET*2**IID = DETERMINANT OF A N
OUT QF = Q
OUT F = VECTOR OF FORECASTS
OUT COVF = COVARIANCE MATRIX OF FORECASTS
REAL Z(500) ,PHI(10) ,THETA(10) ,F(10) ,COVF(10,10)
REAL 8Z(500) ,80(500) ,E(10,10)
INTEGER P,Q
REAL L(100)
LOC(I,J)=MPl*MOD(I-l,MPl)+J-I+MPl
o LIES ON DIAGONAL OF L
L STORED SLIDING, AND ONLY RECENT PART
M=MAX0 (P, Q)
MPl=M+l
CALL GETSET(PHI,THETA,P,Q)
GETSET PREPARES VALUES OF A,D 1,C 1,C 2 AND E
USES COMMON AREA NAMED XARMAX- ***************
P,Q < 10 < N
NS <= 10
000=0.
ODZ=0.
ZDZ=0.
CREATE 8Z AND 8*ONE
DO 2I=1,M
8Z(I)=Z(I)
2
80(I)=l.
S=l.
IF (P.EQ.0) GO TO 6
DO 4I=1,P
4
S=S-PHI (I)
6
DO 8I=MPl,N
8Z(I)=Z(I)
IF(P.EQ.0) GO TO 8
DO 9J=1,P
9 8Z(I)=8Z(I)-PHI(J)*Z(I-J)
8
80(I)=S
8Z HOLDS 8 M,N * Z
80 HOLDS 8=M,N * ONE
IN
00410
_00420
00430
00440
130450
00460
00470
00480
00490
00500
130510
13135213
013530
00540
013550
005613
130570
0135813
130590
00600
0136113
00620
0136313
1306413
130650
00660
_130670
00680
013690
013700
130710
00720
00730
130740
00750
00760
013770
130730
00790
OO800
130810
00820
00830
013840
008513
008613
00870
00880
00890
00900
00910
_00920
O0930
00940
C
C
C
C
C
C
C
C
DET=I.
IID=0
DO 12I=I,N
W=GRETA(I,I)
GRETA GETS VALUES OF B M,N * A N * (B_M,N)-TRANSPOSE
AKA
A M, C 1, C 2,D 1, AND E
IF (I:-EQ.l) GO TO 14
IMQ=1
IF(I.LE.M)
GO TO 11
IF(Q.EQ.0) GO TO 14
IMQ=I-Q
11 IMl=I-l
DO 15J=IMQ, IMI
S=GRETA (I, J)
IF(IMQ.GE.J) GO TO 15
JMl=J-l
DO 16K=IMQ,JM1
16 S=S-L(LOC(J,K»*L(LOC(I,K»
15 L(LOC(I,J»=S
DO 1 7J=IMQ, IM1
S=L (LOC (I ,J»
L(LOC(I,J»=S/L(LOC(J,J»
W=W-S*L(LOC(I,J»
BZ(I)=BZ(I)-L(LOC(I,J»*BZ(J)
17 BO(I)=BO(I)-L(LOC(I,J»*BO(J)
14 CONTINUE
L(LOC(I,I»=W
COMPUTE BILINEAR FORMS
ODO=ODO+BO(I)*BO(I)/W
ZDZ=ZDZ+BZ(I)*BZ(I)/W
ODZ=ODZ+BO(I)*BZ(I)/W
DET=DET*W
CALL ADJUST(DET,IID)
12 CONTINUE
GET ESTIMATE OF MEAN
ZHM=ODZ/ODO
GET QUADRATIC FORM FOR LIKELIHOOD
QF=ZDZ-ODZ*ZHM
NOW START ON FORECASTS
DO 30 I=I,NS
F(I)=0.
DO 30 J=I,I
INITIALIZE COV MX FOR FORECASTS
30 COVF(I,J)=GRETA(N+I,N+J)
IF (Q.EQ.0) GO TO 39
GET D-INV L-INV
(0 E)
DO 32K=I,Q
DO 33I=K,Q
E(I,K)=GRETA(N+K,N-Q+I)
IF(I.EQ.K) GO TO 33
IM1=I-1
DO 34J=K, IMI
3 4 E (.I , K) =E (I , K) - L (L OC (N -Q + I , N-Q +J ) ) *E (J , K)
33 CONTINUE
DO 36I=K,Q
00950
S=E (I ,K)
00960
00970
KM1=K-1
IF(KM1.EQ.13) GO TO 38
00980
DO 37J=1, KM1
00990
37 COVF(K,J)=COVF(K,J)-S*E(I,J)
01000
38 E(I,K)=E(I,K)/L(LOC(N-Q+I,N-Q+I))
01010
COVF(K,K)=COVF(K,K)-S*E(I,K)
01020
36 F(K)=F(K)+E(I,K)*(BZ(N-Q+I)-ZHM*BO(N-Q+I))
01030
32 CONTINUE
01040
39 CONTINUE
01050
SYMMETRIZE
01060 C
DO 51I=1,NS
01070
DO 51J=1, I
01080
51 COVF(J,I)=COVF(I,J)
01090
IF(P.EQ.0) GO TO 48
01100
DO 41I=1,P
01110
01120
DO 41J=I,P
41 F(I)=F(I)+PHI(J)*(Z(N+I-J)-ZHM)
01130
FINISH FORECASTS WITH B NS-INV
01140 C
DO 42I=1,NS
01150
IF(I.EQ.1) GO TO 42
01160
K=M IN 0 (I -1, P)
01170
DO 43 J=1,K
131180
43 F(I)=F(I)+PHI(J)*F(I-J)
01190
01200
42 CONTINUE
NOW GET COV MX
01210 C FORECASTS NEAR DONE
B NS-INV IN FRONT
131220 C
-DO 52J=1,NS
01230
DO 52I=1,NS
01240
01250
LL=MIN0(I-1,P)
IF(I.EQ.1) GO TO 52
01260
DO 53K=1,LL
01270
53 COVF(I,J)=COVF(I,J)+PHI(K)*COVF(I-K,J)
01280
52 CONTINUE
01290
B NS-INV TRANSP IN BACK
01300 C
-DO 56J=1,NS
01310
DO 56I=1,NS
01320
IF(I.EQ.1) GO TO 56
01330
LL=MINQl (I-1, P)
01340
DO 55K=1, LL
01350
55 COVF(J,I)=COVF(J,I)+PHI(K)*COVF(J,I-K)
01360
56 CONTINUE
01370
48 CONTINUE
01380
DO 49I=1,NS
01390
49 F(I)=F(I)+ZHM
01400
RETURN
014113
END
01420
01430
_440
~450 C
01460
01470
01480
01490
01500
01510
01520
01530
01540
01550
01560
01570
01580
01590
01600
01610
01620
01630
01640
01650
01660
01670
01680
""690
~700
01710
01720
01730
01740
01750
01750
01770
01780
01790
01800
01810
01820
01830
01840
01850
01860
01870
01880
01890
01900
01910
01920
01930
..l1940
.950
01960
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
SUBROUTINE BARMAD(Z,P,Q,N,PHI,THETA,EMGZ,DB,IID,QF,F,COVF,NS,GAM,
1TAU)
IN Z,P,Q,PHI,THETA
N=LENGTH OF SERIES; NS=NO. OF FORECASTS
IN
PRIOR ON MEAN IS NORMAL (GAM,TAU)
OUT EMGZ=MEAN OF POSTEIOR OF MU
OUT DB*2**IID = DETERMINANT FOR DENSITY OF Z
OUT QF = QUADRATIC FORM FOR DENSITY OF Z
OUT F = VECTOR OF FORECASTS
OUT COVF = COVARIANCE MATRIX OF FORECASTS
REAL Z (500) ,PHI (10) ,THETA(10) ,F(10) ,COVF (10, 10)
REAL BZ(500) ,BO(500) ,E(10,10) ,AS(10) ,BS(10)
INTEGER P,Q
REAL L(100)
LOC(I,J)=MP1*MOD(I-1,MP1)+J-I+MP1
D LIES ON DIAGONAL OF L
L STORED SLIDING, AND ONLY RECENT PART
M=MAX0(P,Q)
MP1=M+1
CALL GETSET(PHI,THETA,P,Q)
GETSET PREPARES VALUES OF A,D 1,C 1,C 2 AND E
USES COMMON AREA NAMED XARMAX- ***************
P,Q < 10 < N
NS <= 10
000=0.
ODZ=0.
ZDZ=0.
CREATE BZ AND B*ONE
DO 2I=1,M
BZ(I)=Z(I)
2
BO(I)=l.
8=1IF (P.EQ.0) GO TO 6
DO 4I=1,P
4
S=S-PHI (I)
6
DO 8I=MP1,N
BZ(I)=Z(I)
IF(P.EQ.0) GO TO 8
DO 9J=1, P
9 BZ(I)=BZ(I)-PHI(J)*Z(I-J)
8
BO(I)=S
BZ HOLDS B M,N * Z
BO HOLDS B-M,N * ONE
DB=l.
IID=0
DO 12I=1,N
IN=GRETA (I, I)
GRETA GETS VALUES OF B M,N * A N * (B M,N)-TRANSPOSE
AKA
A M, C 1, C 2,D T, AND E
IF (I:-EQ.1) GO TO 14
IMQ=l
IF(I.LE.M)
GO TO 11
IF(Q.EQ.0) GO TO 14
IMQ=I-Q
11 IM1=I-1
_ 01970
.01980
01990
02000
02010
02020
02030
02040
02050
02060
020713
02080
02090
02100
02110
02120
02130
02140
02150
02160
02170
02180
02190
02200
02210
_ 02220
.02230
02240
02250
02260
02270
02280
02290
02300
02310
02320
02330
02340
02350
02360
02370
02380
02390
02400
02410
02420
C
C
C
C
C
C
C
DO 15J=IMQ, IMl
S=GRETA(I,J)
IF(IMQ.GE.J) GO TO 15
JMl=J-l
DO 16K=IMQ,JMl
16 S=S-L(LOC(J,K»*L(LOC(I,K»
15 L(LOC(I,J»=S
DO 17J=IMQ, IMI
S = L (L OC ( I , J) )
L(LOC(I,J»=S/L(LOC(J,J»
W=W-S*L(LOC(I,J»
BZ(I)=BZ(I)-L(LOC(I,J»*BZ(J)
17 BO(I)=BO(I)-L(LOC(I,J»*BO(J)
14 CONTINUE
L(LOC(I,I»=W
COMPUTE BILINEAR FORMS
ODO=ODO+BO(I)*BO(I)/W
ZDZ=ZDZ+BZ(I)*BZ(I)/W
ODZ=ODZ+BO(I)*BZ(I)/W
DB=DB*W
CALL ADJUST(DB,IID)
12 CONTINUE
GET MEAN OF POSTERIOR OF MU**** E(MU GIVEN Z)
EMGZ=(GAM*TAU+ODZ)/(TAU+ODO)
GET QUADRATIC FORM FOR DENSITY
QF=ZDZ+GAM*GAM*TAU-EMGZ*(GAM*TAU+ODZ)
ADJUST DETERMINANT FOR BAYESIAN ANALYSIS
DB=DB*(I.+0DO/TAU)
NOW START ON FORECASTS
DO 30 I=I,NS
F(I)=0.
AS(I)=0.
BS(I)=0.
DO 30 J=I,I
INITIALIZE COV MX FOR FORECASTS
30 COVF(I,J)=GRETA(N+I,N+J)
IF (Q.EQ.0) GO TO 39
GET D-INV L-INV (0 E)
DO 32K=I, Q
DO 33I=K,Q
E(I,K)=GRETA(N+K,N-Q+I)
IF(I.EQ.K) GO TO 33
IMl=I-l
DO 34J=K, IMI
34 E(I,K)=E(I,K)-L(LOC(N-Q+I,N-Q+J»*E(J,K)
33 CONTINUE
~430
4410
. 24510
1024610
024710
02480
02490
02500
02510
02520
02530
02540
02550 C
02560
02570
02580
02590
02600
02610
02620
102630
02640 C
02650
02660
02670
02680
~690
27100
027110
027210 C
02730 C
02740
02750
02760
102770
02780
02790
02800
102810 C
02820
028310
02840
02850
1028610
02870
02880
02890
02900
029110
02920
02930
.940
950
02960
02970
DO 36I=K,Q
S=E(I,K)
KM1=K-1
IF(KM1.EQ.0) GO TO 38
DO 37J=1, KM1
37 COVF(K,J)=COVF(K,J)-S*E(I,J)
38 E(I,K)=E(I,K)/L(LOC(N-Q+I,N-Q+I))
COVF(K,K)=COVF(K,K)-S*E(I,K)
AS(K)=AS(K)+E(I,K)*BO(N-Q+I)
36 BS(K)=BS(K)+E(I,K)*BZ(N-Q+I)
32 CONTINUE
39 CONTINUE
SYMMETRIZE
DO 51I=1,NS
DO 51J=1, I
51 COVF(J,I)=COVF(I,J)
IF(P.EQ.0) GO TO 48
DO 41I=1,P
DO 41J=I,P
AS(I)=AS(I)+PHI(J)
41 BS(I)=BS(I)+PHI(J)*Z(N+I-J)
FINISH FORECASTS WITH B NS-INV
DO 42I=1,NS
IF(I.EQ.1) GO TO 42
K=M IN 0 (I -1 , P )
DO 43 J=l,K
AS(I)=AS(I)+PHI(J)*AS(I-J)
43 BS(I)=BS(I)+PHI(J)*BS(I-J)
42 CONTINUE
FORECASTS NEAR DONE
NOW GET COY MX
B NS-INV IN FRONT
-DO 52J=1,NS
DO 52I=1,NS
LL=MIN0(I-1,P)
IF(I.EQ.1) GO TO 52
DO 53K=1,LL
53 COVF(I,J)=COVF(I,J)+PHI(K)*COVF(I-K,J)
52 CONTINUE
B NS-INV TRANSP IN BACK
-DO 56J=1,NS
DO 56I=1,NS
IF(I.EQ.1) GO TO 56
LL=MIN0 (I-I, P)
DO 55K=1,LL
55 COVF(J,I)=COVF(J,I)+PHI(K)*COVF(J,I-K)
56 CONTINUE
48 CONTINUE
DO 49I=1,NS
49 F(I)=EMGZ*(l.-AS(I))+BS(I)
W=TAU+ODO
DO 58 I=l, NS
DO 58 J=l,NS
58 COVF(I,J)=COVF(I,J)+AS(I)*AS(J)/W
RETURN
END
02980
SUBROUTINE CFARMA(PHI,THETA,P,Q,X)
COMPUTES
COVARIANCE FUNCTION, SIGMA(0) , ••• ,SIGMA(M)
.i2990 C
.3000 C FOR ARMA PROCESS USING MCLEOD'S ALGORITHM
03010 C
CRSEPP IS LINEAR EQUATIONS SOLVER
03020
REAL PHI(10) ,THETA(10) ,A(10,10) ,X(10) ,C(10)
03030
INTEGER P,Q,R,RP1,QP1
03040
R=MAX0(P,Q)
03050
RP1=R+1
03060
C(l)=l.
03070
IF(Q.EQ.0) GO TO 4
03080
DO 2K=1,Q
03090
J=K+1
03100
C(J)=-THETA(K)
03110
IF(P.EQ.0) GO TO 2
03120
L=MIN0(P,K)
03130
DO 3I=1,L
03140
3
C(J)=C(J)+PHI(I)*C(J-I)
03150
2
CONTINUE
03160
CONTINUE
4
X(l)=C(l)
03170
03180
DO 9I=2,10
03190
9
X(I)=0.
03200
IF(Q.EQ.0) GO TO 6
03210
DO 7I=1,Q
03220
7
X(1)=X(1)-THETA(I)*C(I+1)
03230
DO 8K=1,Q
J=K+1
~3240
DO 8I=K, Q
.,3250
03260
X(J)=X(J)-THETA(I)*C(I-K+1)
8
03270
6
IF(P.EQ.0) RETURN
03280
DO 12I=1,RP1
03290
DO 12J=1,RP1
03300
12 A(I,J)=0.
03310 C
NB THIS IS NEG OF MACLEOD'S A
03320
DO 14I=1,RP1
03330
A(I,I)=l.
03340
DO 14J=1,P
03350
L=IABS (I -J -1) +1
03360
14 A(I,L)=A(I,L)-PHI(J)
03370
CALL CRSEPP(A,RP1,S,X)
133380
RETURN
03390
END
REAL FUNCTION GRETA(I,J)
03400
GRETA GETS (QUICKLY) VALUES OF B M,N * A N * (B_M,N)-TRANSPOSE
03410 C
03420
REAL AM(10) ,D1 (10) ,CC(10)
03430
COMMON /XARMAX/M,IQ1,AM,CC,D1
133440
K=I -J+1
03450
GRETA=0.
03460
IF(K.LE.IQ1) GRETA=CC(K)
03470
IF(J.GT.M) RETURN
03480
IF(I.GT.M) GO TO 4
03490
GRETA=AM(K)
RETURN
3500
•
3510
4
GRETA=D1(K-1)
03520
RETURN
END
03530
SUBROUTINg ADJUST(D,I)
03540
ADJUST KEEPS DET FROM EXPLODING
03550 C
IF(D.LE.0.) GO TO 6
03560
IF (D'. GE. L) GO TO 4
03570
3
03580
D=D*16.
03590
I=I-4
GO TO 3
11'3600
IF(D.LE.16.) RETURN
11'3610
4
03620
D=D/16.
I=I+4
03630
036411'
GO TO 4
I=-2147483644
03650
6
RETURN
03660
END
03670
SUBROUTINE GETSET(PHI,THETA,P,Q)
11'3680
REAL PHI (10) ,THETA(lel) ,AM(lel) ,CC(10) ,Dl (10)
03690
INTEGER P,Q
03700
COMMON /XARMAX/M,IQ1,AM,CC,D1
03710
IQ1=Q+1
11'3720
M=MAXel (P, Q)
037311'
CALL CFARMA(PHI,THETA,P,Q,AM)
037411'
03750
CC(l)=l.
IF(Q.EQ.0) GO TO 6
03760
037711'
DO 2I=1,Q
CC(1)=CC(1)+THETA(I)**2
037811'
2
03790
DO 4I=1,Q
IP1=I+1
11'3800
CC(I+1)=-THETA(I)
03810
IF(I.EQ.Q) GO TO 4
03820
DO 5J=IP1, Q
03830
CC(I+1)=CC(IPl)+THETA(J)*THETA(J-I)
11'3840
5
CONTINUE
038511'
4
CONTINUE
038611'
6
038711'
DO 7I=1,M
11'3880
D1 (I) =AM (I + 1)
03890
IF(P.EQ.0) GO TO 7
039011'
DO 8K=1,P
D1(I)=D1(I)-PHI(K)*AM(IABS(I-K)+1)
03910
8
CONTINUE
03920
7
RETURN
11'39311'
END
039411'
e
·e
e
03950
03960
03970
03980
03990
04000
04010
04020
04030
04040
04050
041360
0413713
13413813
04090
04100
041113
04120
04130
04140
1341513
041613
041713
04180
041913
042130
042113
04220
1342313
042413
134250
042613
04270
04280
04290
04300
04310
04320
04330
04340
04350
134360
04370
04380
043913
0441313
134410
04420
04430
04440
04450
04460
04470
4
3
5
6
1
8
7
2
10
9
12
11
SUBROUTINE CRSEPP(A,N,D,V)
REAL A (10, 10) , V (10)
INTEGER R
D=l.
DO 2K=1,N
DO 3I=K,N
S=A (I, K)
IF(K.EQ.1) GO TO 3
KM1=K-1
DO 4L=1,KM1
S=S-A(I,L)*A(L,K)
A(I,K)=S
S=0.
R=0
DO 5I=K,N
IF (AB S (A ( I , K) ) • LE • S) GO TO 5
R=I
S =AB S (A ( I , K) )
CONTINUE
IF(S.EQ.0.) STOP
D=D*A(R,K)
IF(R.EQ.K) GO TO 1
D=-D
DO 6J=1, N
T=A(R,J)
A(R,J)=A(K,J)
A(K,J)=T
T=V(R)
V(R)=V(K)
V(K)=T
IF(K.EQ.N) GO TO 2
KP1=K+1
DO 7J=KP1,N
S=A(K,J)
IF(K.EQ.1) GO TO 7
DO 8L=1,KM1
S=S-A(K,L)*A(L,J)
A(K,J)=S/A(K,K)
CONTINUE
V (1) =V (1 ) /A ( 1 , 1)
DO 9K=2,N
KM1=K-1
DO 10I=1,KM1
V(K)=V(K)-A(K,I)*V(I)
V(K)=V(K)/A(K,K)
DO 11J=2,N
K=N+I-J
KPl=K+1
DO 12I=KPl,N
V(K)=V(K)-A(K,I)*V(I)
CONTINUE
RETURN
END