Keyword: 多変量時系列, 多入力モデル, 予測
概要
本サンプルは多入力モデルからの時系列の予測の計算を行うFortranによるサンプルプログラムです。 本サンプルは以下に示される時系列データを分析し、時系列の予測値を出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン g13bjf() のExampleコードです。本サンプル及びルーチンの詳細情報は g13bjf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はg13bjf のマニュアルページを参照)| このデータをダウンロード |
G13BJF Example Program Data 1 40 8 6 1 :: KFC,NEV,NFV,NSER,KZEF 1 0 0 0 0 1 4 :: MR 0 0 0 1 :: Transfer fun. series 1 MT(:,1) 0 0 0 1 :: Transfer fun. series 2 MT(:,2) 0 0 0 1 :: Transfer fun. series 3 MT(:,3) 0 0 0 1 :: Transfer fun. series 4 MT(:,4) 1 0 1 3 :: Transfer fun. series 5 MT(:,5) 0.4950 0.2380 -0.3670 -3.8760 4.5160 2.4740 8.6290 0.6880 -82.8580 :: End of PARA 1.0 1.0 0.0 0.0 8.075 105.0 1.0 0.0 1.0 0.0 7.819 119.0 1.0 0.0 0.0 1.0 7.366 119.0 1.0 -1.0 -1.0 -1.0 8.113 109.0 2.0 1.0 0.0 0.0 7.380 117.0 2.0 0.0 1.0 0.0 7.134 135.0 2.0 0.0 0.0 1.0 7.222 126.0 2.0 -1.0 -1.0 -1.0 7.768 112.0 3.0 1.0 0.0 0.0 7.386 116.0 3.0 0.0 1.0 0.0 6.965 122.0 3.0 0.0 0.0 1.0 6.478 115.0 3.0 -1.0 -1.0 -1.0 8.105 115.0 4.0 1.0 0.0 0.0 8.060 122.0 4.0 0.0 1.0 0.0 7.684 138.0 4.0 0.0 0.0 1.0 7.580 135.0 4.0 -1.0 -1.0 -1.0 7.093 125.0 5.0 1.0 0.0 0.0 6.129 115.0 5.0 0.0 1.0 0.0 6.026 108.0 5.0 0.0 0.0 1.0 6.679 100.0 5.0 -1.0 -1.0 -1.0 7.414 96.0 6.0 1.0 0.0 0.0 7.112 107.0 6.0 0.0 1.0 0.0 7.762 115.0 6.0 0.0 0.0 1.0 7.645 123.0 6.0 -1.0 -1.0 -1.0 8.639 122.0 7.0 1.0 0.0 0.0 7.667 128.0 7.0 0.0 1.0 0.0 8.080 136.0 7.0 0.0 0.0 1.0 6.678 140.0 7.0 -1.0 -1.0 -1.0 6.739 122.0 8.0 1.0 0.0 0.0 5.569 102.0 8.0 0.0 1.0 0.0 5.049 103.0 8.0 0.0 0.0 1.0 5.642 89.0 8.0 -1.0 -1.0 -1.0 6.808 77.0 9.0 1.0 0.0 0.0 6.636 89.0 9.0 0.0 1.0 0.0 8.241 94.0 9.0 0.0 0.0 1.0 7.968 104.0 9.0 -1.0 -1.0 -1.0 8.044 108.0 10.0 1.0 0.0 0.0 7.791 119.0 10.0 0.0 1.0 0.0 7.024 126.0 10.0 0.0 0.0 1.0 6.102 119.0 10.0 -1.0 -1.0 -1.0 6.053 103.0 :: XXY (observed values) 11.0 1.0 0.0 0.0 5.941 11.0 0.0 1.0 0.0 5.386 11.0 0.0 0.0 1.0 5.811 11.0 -1.0 -1.0 -1.0 6.716 12.0 1.0 0.0 0.0 6.923 12.0 0.0 1.0 0.0 6.939 12.0 0.0 0.0 1.0 6.705 12.0 -1.0 -1.0 -1.0 6.914 :: End of XXY (future values) 0.0 0.0 0.0 0.0 0.1720 :: End of RMSXY 2 0 2 0 1 1 4 :: Orders for series 5, MRX(:,5) 1.6743 -0.9505 1.4605 -0.4862 0.8993 :: Params for series 5, PARX(:,5)
- 1行目はタイトル行で読み飛ばされます。
- 2行目にモデルがフィットされた際に定数が推定されたかどうか(kfc=1:推定)、入力時系列と出力時系列の値の数(nev=40)、出力時系列の予測値の数(nfv=8)、入力時系列と出力時系列の数(nser=6)、入力時系列と出力時系列の値がXXYを上書きするかどうか(kzef=1:上書きする)を指定しています。
- 3行目はARIMAモデルの次数ベクトルmr(自己回帰の数、非季節階差の次数、移動平均、季節自己回帰、季節階差の次数、季節移動平均と季節期間)を指定しています。
- 4〜8行目は伝達関数モデルの次数(mt)を指定しています。
- 9〜10行目は多入力モデルの引数の推定値(para)を指定しています。
- 11〜50行目に入力時系列と出力時系列の過去値(xxy)を指定しています。
- 51〜58行目に出力時系列の予測に必要な入力時系列の将来値(xxy)を指定しています。
- 59行目に入力時系列ARIMAモデルの推定残差分散(rmsxy)を指定しています。
- 60行目に入力時系列ARIMAモデルの次数の配列(mrx)を指定しています。
- 61行目に入力時系列ARIMAモデルの引数の値(parx)を指定しています。
出力結果
(本ルーチンの詳細はg13bjf のマニュアルページを参照)| この出力例をダウンロード |
G13BJF Example Program Results
After processing 40 sets of observations
6 values of the state set are derived
6.0530 193.8741 2.0790 -2.8580 -3.5906 -2.5203
The residual mean square for the output
series is also derived and its value is 20.7599
The forecast values and their standard errors are
I FVA FSD
1 93.398 4.5563
2 96.958 6.2172
3 86.046 7.0933
4 77.589 7.3489
5 82.139 7.3941
6 96.276 7.5823
7 98.345 8.1445
8 93.577 8.8536
The values of z(t) and n(t) are
1 2 3 4 5 6
1 -0.3391 -3.8886 0.0000 0.0000 188.6028 -79.3751
2 -0.3391 0.0000 4.5139 0.0000 199.4379 -84.6127
3 -0.3391 0.0000 0.0000 2.4789 204.6834 -87.8232
4 -0.3391 3.8886 -4.5139 -2.4789 204.3834 -91.9402
5 -0.6782 -3.8886 0.0000 0.0000 210.6229 -89.0560
6 -0.6782 0.0000 4.5139 0.0000 208.5905 -77.4262
7 -0.6782 0.0000 0.0000 2.4789 205.0696 -80.8703
8 -0.6782 3.8886 -4.5139 -2.4789 203.4065 -87.6242
9 -1.0173 -3.8886 0.0000 0.0000 206.9738 -86.0678
10 -1.0173 0.0000 4.5139 0.0000 206.1317 -87.6283
11 -1.0173 0.0000 0.0000 2.4789 201.9196 -88.3812
12 -1.0173 3.8886 -4.5139 -2.4789 194.8194 -75.6979
13 -1.3564 -3.8886 0.0000 0.0000 203.9738 -76.7287
14 -1.3564 0.0000 4.5139 0.0000 209.8837 -75.0412
15 -1.3564 0.0000 0.0000 2.4789 210.7052 -76.8277
16 -1.3564 3.8886 -4.5139 -2.4789 210.3730 -80.9125
17 -1.6955 -3.8886 0.0000 0.0000 205.9421 -85.3580
18 -1.6955 0.0000 4.5139 0.0000 194.5753 -89.3937
19 -1.6955 0.0000 0.0000 2.4789 185.8662 -86.6496
20 -1.6955 3.8886 -4.5139 -2.4789 185.5090 -84.7094
21 -2.0346 -3.8886 0.0000 0.0000 191.6056 -78.6824
22 -2.0346 0.0000 4.5139 0.0000 193.1941 -80.6734
23 -2.0346 0.0000 0.0000 2.4789 199.8958 -77.3402
24 -2.0346 3.8886 -4.5139 -2.4789 203.4970 -76.3583
25 -2.3737 -3.8886 0.0000 0.0000 214.5519 -80.2896
26 -2.3737 0.0000 4.5139 0.0000 213.7702 -79.9104
27 -2.3737 0.0000 0.0000 2.4789 216.7963 -76.9015
28 -2.3737 3.8886 -4.5139 -2.4789 206.7803 -79.3024
29 -2.7128 -3.8886 0.0000 0.0000 200.4157 -91.8142
30 -2.7128 0.0000 4.5139 0.0000 185.9409 -84.7420
31 -2.7128 0.0000 0.0000 2.4789 171.4951 -82.2613
32 -2.7128 3.8886 -4.5139 -2.4789 166.6735 -83.8565
33 -3.0519 -3.8886 0.0000 0.0000 173.4176 -77.4771
34 -3.0519 0.0000 4.5139 0.0000 176.5733 -84.0353
35 -3.0519 0.0000 0.0000 2.4789 192.5940 -88.0211
36 -3.0519 3.8886 -4.5139 -2.4789 201.2606 -87.1045
37 -3.3910 -3.8886 0.0000 0.0000 207.8790 -81.5993
38 -3.3910 0.0000 4.5139 0.0000 210.2493 -85.3721
39 -3.3910 0.0000 0.0000 2.4789 205.2616 -85.3495
40 -3.3910 3.8886 -4.5139 -2.4789 193.8741 -84.3790
41 -3.7301 -3.8886 0.0000 0.0000 185.6167 -84.6003
42 -3.7301 0.0000 4.5139 0.0000 178.9692 -82.7953
43 -3.7301 0.0000 0.0000 2.4789 169.6066 -82.3091
44 -3.7301 3.8886 -4.5139 -2.4789 166.8325 -82.4095
45 -4.0692 -3.8886 0.0000 0.0000 172.7331 -82.6360
46 -4.0692 0.0000 4.5139 0.0000 178.5789 -82.7481
47 -4.0692 0.0000 0.0000 2.4789 182.7389 -82.8036
48 -4.0692 3.8886 -4.5139 -2.4789 183.5818 -82.8311
The first 5 columns hold the z(t) and the last column the n(t)
- 3〜6行目には40組の観測値が処理され、状態セットの6個の値が得られたことが示されています。
- 8〜9行目には出力時系列の残差平方和が出力されています。
- 15から22行目には予測値と標準誤差が出力されています。
- 26〜73行目にはZ値(最初の5つのカラム)、ノイズ(最後のカラム)が出力されています。
ソースコード
(本ルーチンの詳細はg13bjf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
PROGRAM g13bjfe
! G13BJF Example Program Text
! Mark 23 Release. nAG Copyright 2011.
! .. Use Statements ..
USE nag_library, ONLY : g13bjf, nag_wp, x04caf
! .. Implicit None Statement ..
IMPLICIT NONE
! .. Parameters ..
INTEGER, PARAMETER :: nin = 5, nout = 6
! .. Local Scalars ..
INTEGER :: dp, i, ifail, imwa, isttf, iwa, kfc, &
kzef, ldparx, ldxxy, mx, n, ncf, &
ncg, nch, nci, nev, nfv, nis, npara, &
nparx, nser, nsttf, qp, qx, smx
! .. Local Arrays ..
REAL (KIND=nag_wp), ALLOCATABLE :: fsd(:), fva(:), para(:), parx(:,:), &
rmsxy(:), sttf(:), wa(:), xxy(:,:)
INTEGER :: mr(7)
INTEGER, ALLOCATABLE :: mrx(:,:), mt(:,:), mwa(:)
! .. Intrinsic Functions ..
INTRINSIC max, sum
! .. Executable Statements ..
WRITE (nout,*) 'G13BJF Example Program Results'
WRITE (nout,*)
! Skip heading in data file
READ (nin,*)
! Read in problem size
READ (nin,*) kfc, nev, nfv, nser, kzef
! Number of input series
nis = nser - 1
ALLOCATE (mt(4,nser))
! Read in the orders for the output noise
READ (nin,*) mr(1:7)
! Read in transfer function
DO i = 1, nis
READ (nin,*) mt(1:4,i)
END DO
! Calculate NPARA
npara = 0
DO i = 1, nis
npara = npara + mt(2,i) + mt(3,i)
END DO
npara = npara + mr(1) + mr(3) + mr(4) + mr(6) + nser
! Calculate array sizes
n = nev + nfv
ldxxy = n
ncf = 0
DO i = 1, nis
IF (mt(4,i)>1) THEN
ncf = sum(mt(1:3,i))
END IF
END DO
isttf = mr(1)*mr(7) + mr(2) + mr(5)*mr(7) + mr(3) + &
max(mr(1),mr(6)*mr(7)) + ncf
qp = mr(3) + mr(6)*mr(7)
dp = mr(2) + mr(5)*mr(7)
smx = 0
qx = qp
nci = nser
DO i = 1, nis
IF (mt(4,i)==3) THEN
mx = max(mt(1,i)+mt(2,i),mt(3,i))
nci = nci + 1
ELSE
mx = 0
END IF
IF (mt(3,i)>0) THEN
nci = nci + 1
END IF
smx = smx + mx
qx = max(qx,mx)
END DO
ncg = npara + qx + smx
nch = dp + 6*qx + nev
IF (qx>0) THEN
nci = nci + 1
END IF
IF (mr(1)>0) THEN
nci = nci + 1
END IF
IF (mr(3)>0) THEN
nci = nci + 1
END IF
IF (mr(4)>0) THEN
nci = nci + 1
END IF
IF (mr(6)>0) THEN
nci = nci + 1
END IF
iwa = 2*(ncg**2) + nch*(nci+4)
imwa = 16*nser + 7*ncg + 3*npara + 27
ALLOCATE (para(npara),xxy(ldxxy,nser),rmsxy(nser),mrx(7,nser),fva(nfv), &
fsd(nfv),sttf(isttf),wa(iwa),mwa(imwa))
! Read in multi-input model parameters
READ (nin,*) para(1:npara)
! Read in the observed values for the input and output series
READ (nin,*) (xxy(i,1:nser),i=1,nev)
! Read in the future values for the input series
READ (nin,*) (xxy(nev+i,1:nis),i=1,nfv)
IF (nis>=1) THEN
! Read in residual variance of input series
READ (nin,*) rmsxy(1:nis)
! Read in orders for input series ARIMA where available
! (i.e. where residual variance is not zero)
ldparx = 0
DO i = 1, nis
IF (rmsxy(i)/=0.0E0_nag_wp) THEN
READ (nin,*) mrx(1:7,i)
nparx = mrx(1,i) + mrx(3,i) + mrx(4,i) + mrx(6,i)
ldparx = max(ldparx,nparx)
ELSE
mrx(1:7,i) = 0
END IF
END DO
ELSE
! No input series
ldparx = 1
END IF
ALLOCATE (parx(ldparx,nser))
! Read in parameters for each input series ARIMA
IF (nis>0) THEN
DO i = 1, nis
IF (rmsxy(i)/=0.0E0_nag_wp) THEN
nparx = mrx(1,i) + mrx(3,i) + mrx(4,i) + mrx(6,i)
IF (nparx>0) THEN
READ (nin,*) parx(1:nparx,i)
END IF
END IF
END DO
END IF
ifail = 0
CALL g13bjf(mr,nser,mt,para,npara,kfc,nev,nfv,xxy,ldxxy,kzef,rmsxy,mrx, &
parx,ldparx,fva,fsd,sttf,isttf,nsttf,wa,iwa,mwa,imwa,ifail)
! Display results
WRITE (nout,99999) 'After processing', nev, ' sets of observations'
WRITE (nout,99998) nsttf, ' values of the state set are derived'
WRITE (nout,*)
WRITE (nout,99997) sttf(1:nsttf)
WRITE (nout,*)
WRITE (nout,*) 'The residual mean square for the output'
WRITE (nout,99996) 'series is also derived and its value is', &
rmsxy(nser)
WRITE (nout,*)
WRITE (nout,*) 'The forecast values and their standard errors are'
WRITE (nout,*)
WRITE (nout,*) ' I FVA FSD'
WRITE (nout,*)
WRITE (nout,99995) (i,fva(i),fsd(i),i=1,nfv)
WRITE (nout,*)
FLUSH (nout)
ifail = 0
CALL x04caf('General',' ',n,nser,xxy,ldxxy, &
'The values of z(t) and n(t) are',ifail)
WRITE (nout,99994) 'The first ', nis, &
' columns hold the z(t) and the last column the n(t)'
99999 FORMAT (1X,A,I3,A)
99998 FORMAT (1X,I3,A)
99997 FORMAT (1X,6F10.4)
99996 FORMAT (1X,A,F10.4)
99995 FORMAT (1X,I4,F10.3,F10.4)
99994 FORMAT (1X,A,I0,A)
END PROGRAM g13bjfe
