GNAR data

GNAR
Author

SEOYEON CHOI

Published

January 5, 2023

GNAR

GNAR

import rpy2
import rpy2.robjects as ro 
from rpy2.robjects.vectors import FloatVector 
from rpy2.robjects.packages import importr
%load_ext rpy2.ipython
%%R
library(GNAR)
library(igraph)
R[write to console]: Loading required package: igraph

R[write to console]: 
Attaching package: ‘igraph’


R[write to console]: The following objects are masked from ‘package:stats’:

    decompose, spectrum


R[write to console]: The following object is masked from ‘package:base’:

    union


R[write to console]: Loading required package: wordcloud

R[write to console]: Loading required package: RColorBrewer

2.3 GNAR network example

  • edge(list)
  • dist(list)
%%R
plot(fiveNet, vertex.label = c("A", "B", "C", "D", "E"))

%%R
summary("fiveNet")
   Length     Class      Mode 
        1 character character 

other examples

  • igraphtoGNAR or GNARtoigraph쓰는 예제
%%R
fiveNet2 <- GNARtoigraph(net = fiveNet)
summary(fiveNet2)
IGRAPH 2b4460d U-W- 5 5 -- 
+ attr: weight (e/n)
%%R
fiveNet3 <- igraphtoGNAR(fiveNet2)
all.equal(fiveNet, fiveNet3)
[1] TRUE
%%R
print(igraphtoGNAR(fiveNet2))
GNARnet with 5 nodes 
edges:1--4 1--5 2--3 2--4 3--2 3--4 4--1 4--2 4--3 5--1 
     
 edges of each of length  1 

edge들 보고 싶을 때

whereas the reverse conversion would be performed as

%%R
g <- make_ring(10)
print(igraphtoGNAR(g))
GNARnet with 10 nodes 
edges:1--2 1--10 2--1 2--3 3--2 3--4 4--3 4--5 5--4 5--6 
     6--5 6--7 7--6 7--8 8--7 8--9 9--8 9--10 10--1 10--9 
     
 edges of each of length  1 
%%R
make_ring(10)
IGRAPH 22f6be5 U--- 10 10 -- Ring graph
+ attr: name (g/c), mutual (g/l), circular (g/l)
+ edges from 22f6be5:
 [1] 1-- 2 2-- 3 3-- 4 4-- 5 5-- 6 6-- 7 7-- 8 8-- 9 9--10 1--10

이어진 방향으로 각각의 edge를 만들어주는 게 igrapphtoGNAR이다

GNARtoigraph function으로 높은 수준의 이웃 구조를 포함한 그래프를 추출할 수 있다.

  • as.matrix or matrixtoGNAR로 인접 행렬 구할 수 있음

we can prosucean adjacency matrix for the fiveNet obeject with

%%R
as.matrix(fiveNet)
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    1    1
[2,]    0    0    1    1    0
[3,]    0    1    0    1    0
[4,]    1    1    1    0    0
[5,]    1    0    0    0    0

and an example converting a weighted adjacency matrix to a GNARnet object is

%%R
adj <- matrix(runif(9), ncol = 3, nrow = 3)
adj[adj < 0.3] <- 0
print(matrixtoGNAR(adj))
WARNING: diagonal entries present in original matrix, these will be removed
GNARnet with 3 nodes 
edges:1--2 1--3 2--1 2--3 3--1 3--2 
 edges of unequal lengths 

2.4. Example: GNAR model fitting

  • GNAR로 fit과 predict 가능
%%R
data("fiveNode")
answer <- GNARfit(vts = fiveVTS, net = fiveNet, alphaOrder = 2, betaOrder = c(1, 1))
answer
Model: 
GNAR(2,[1,1]) 

Call:
lm(formula = yvec ~ dmat + 0)

Coefficients:
 dmatalpha1  dmatbeta1.1   dmatalpha2  dmatbeta2.1  
    0.20624      0.50277      0.02124     -0.09523  
  • 파라메터 4개 가지고 있음
%%R
layout(matrix(c(1, 2), 2, 1))
plot(fiveVTS[, 1], ylab = "Node A Time Series")
lines(fitted(answer)[, 1], col = 2)
plot(fiveVTS[, 2], ylab = "Node B Time Series")
lines(fitted(answer)[, 2], col = 2)

%%R
layout(matrix(c(1, 2), 2, 1))
plot(fiveVTS[, 3], ylab = "Node C Time Series")
lines(fitted(answer)[, 3], col = 2)
plot(fiveVTS[, 4], ylab = "Node D Time Series")
lines(fitted(answer)[, 4], col = 2)

  • 각 노드의 time series(검정), fitted values from ‘answer’ model overlaid in red
%%R
myresiduals <- residuals(answer)[, 1]
layout(matrix(c(1, 2), 2, 1))
plot(ts(residuals(answer)[, 1]), ylab = "`answer' model residuals")
hist(residuals(answer)[, 1], main = "", xlab = "`answer' model residuals")

%%R
myresiduals <- residuals(answer)[, 2]
layout(matrix(c(1, 2), 2, 1))
plot(ts(residuals(answer)[, 1]), ylab = "`answer' model residuals")
hist(residuals(answer)[, 2], main = "", xlab = "`answer' model residuals")

%%R
myresiduals <- residuals(answer)[, 3]
layout(matrix(c(1, 2), 2, 1))
plot(ts(residuals(answer)[, 1]), ylab = "`answer' model residuals")
hist(residuals(answer)[, 3], main = "", xlab = "`answer' model residuals")

%%R
myresiduals <- residuals(answer)[, 4]
layout(matrix(c(1, 2), 2, 1))
plot(ts(residuals(answer)[, 1]), ylab = "`answer' model residuals")
hist(residuals(answer)[, 4], main = "", xlab = "`answer' model residuals")

  • residual plots from ‘answer’ model fit. Top: time sereies, Bottom: Histogram

2.5. Example: GNAR data simulation on a given network

  • fiveNet 네트워크를 사용하여 네트워크 시계열 시뮬레이션 진행

  • 두 시뮬레이션 모두 sigma argument를 사용하여 표준 편차가 제어되는 표준 정규 노이즈를 사용하여 생성된다.

%%R
set.seed(10)
fiveVTS2 <- GNARsim(n = 200, net = fiveNet, alphaParams = list(c(0.4, 0, -0.6, 0, 0)), betaParams = list(c(0.3)))
  • fiveVTS2 네트워크를 사용하여 시뮬레이션 된 것이다보니 파라메터 계수 비슷
%%R
print(GNARfit(vts = fiveVTS2, net = fiveNet, alphaOrder = 1, betaOrder = 1, globalalpha = FALSE))
Model: 
GNAR(1,[1]) 

Call:
lm(formula = yvec ~ dmat + 0)

Coefficients:
dmatalpha1node1  dmatalpha1node2  dmatalpha1node3  dmatalpha1node4  
        0.45902          0.13133         -0.49166          0.03828  
dmatalpha1node5      dmatbeta1.1  
        0.02249          0.24848  
%%R
set.seed(10)
fiveVTS3 <- GNARsim(n = 200, net = fiveNet, alphaParams = list(rep(0.2, 5), rep(0.3, 5)), betaParams = list(c(0.2, 0.3), c(0)))
print(GNARfit(vts = fiveVTS3, net = fiveNet, alphaOrder = 2, betaOrder = c(2,0)))
Model: 
GNAR(2,[2,0]) 

Call:
lm(formula = yvec ~ dmat + 0)

Coefficients:
 dmatalpha1  dmatbeta1.1  dmatbeta1.2   dmatalpha2  
     0.2537       0.1049       0.3146       0.2907  
%%R
fiveVTS4 <- simulate(GNARfit(vts = fiveVTS2, net = fiveNet, alphaOrder = 1, betaOrder = 1, globalalpha = FALSE), n = 200)
print(GNARfit(vts = fiveVTS4, net = fiveNet, alphaOrder = 1, betaOrder = 1, globalalpha = FALSE))
Model: 
GNAR(1,[1]) 

Call:
lm(formula = yvec ~ dmat + 0)

Coefficients:
dmatalpha1node1  dmatalpha1node2  dmatalpha1node3  dmatalpha1node4  
      0.4478300       -0.0008695       -0.4822675        0.0523652  
dmatalpha1node5      dmatbeta1.1  
     -0.0063702        0.2249530  
  • 위와 같이 GNAR 모델에 있는 시계열을 simulate하기 위해 GNARfit object에 대해 simulate S3 method 사용할 수 있다

2.6 Missing data and changing connection weights with GNAR models

  • The flexibility of GNAR modelling이 의미하는 것은 연결 가중치를 바꾸지 않고 변하는 네트워크로 missing data 를 모델링 할 수 있다.
  • 한 노드가 missing data 구간이 생기면 그 구간에서만 네트워크를 변화하여 weight가 변경된다.
%%R
fiveVTS0 <- fiveVTS
fiveVTS0[50:150, 3] <- NA
nafit <- GNARfit(vts = fiveVTS0, net = fiveNet, alphaOrder = 2, betaOrder = c(1, 1))
layout(matrix(c(1, 2), 2, 1))
plot(ts(fitted(nafit)[, 3]), ylab = "Node C fitted values")
plot(ts(fitted(nafit)[, 4]), ylab = "Node D fitted values")

A key advantage of our parsimonious GNAR model is that it models via neighborhoods across the entire data set. If a node is missing for a given time, then it does not contribute to the estimation of neighborhood parameters that the network structure suggests it should, and there are plenty of other nodes that do contribute, generally resulting in a high number of observations to estimate each coefficient. In GNAR models, missing data of this kind is not a problem.

  • 우리의 간결한 GNAR 모델의 주요 장점은 전체 데이터 세트에 걸쳐 이웃을 통해 모델링한다는 것입니다. 노드가 특정 시간 동안 누락되면 네트워크 구조가 제안하는 인접 매개 변수의 추정에 기여하지 않으며, 기여하는 다른 노드도 많아 일반적으로 각 계수를 추정하기 위한 관측치 수가 많습니다. GNAR 모델에서는 이런 종류의 데이터가 누락되는 것은 문제가 되지 않습니다.

2.7. Stationary conditions for a GNAR process with fixed network

Theorem 1

  • Given an unchanging network, \(\mathcal{G}\) a sufficient condition for the GNAT model (1) to be stationary is

\[\sum^p_{j=1}(|\alpha_{i,j}| + \sum^{C}_{c=1} \sum^{s_j}_{r=1} |\beta_{j,t,c}|)<1 , \forall_i \in 1,\dots, N\]

위 조건을 GNARsim을 이용하여 확인 할 수 있다.

%%R
set.seed(10)
fiveVTS4 <- GNARsim(n = 200, net = fiveNet, alphaParams = list(rep(0.2, 5)), betaParams = list(c(0.85)))
c(mean(fiveVTS4[1:50, ]), mean(fiveVTS4[51:100, ]), mean(fiveVTS4[101:150, ]), mean(fiveVTS4[151:200, ]))
[1]    -120.511   -1370.216  -15725.884 -180319.140
  • The mean increases rapidly indicating nonstationarity.
  • 평균이 빠르게 증가하는 것으로 보아 정상성을 띄고 있지 않다.

2.8. Benefits of our model and comparisons to others

3.1. Order selection

Bayesian information criterion

\[BIC(p,s) = ln|\sum^{\hat{}}_{p,s}| + T^{-1} M ln(T)\]

%%R
BIC(GNARfit())
[1] -0.003953124
%%R
BIC(GNARfit(betaOrder = c(2, 1)))
[1] 0.02251406

Akaike information criterion

\[AIC(p,s) = ln|\sum^{\hat{}}_{p,s}| + 2T^{-1} M\]

%%R
AIC(GNARfit())
[1] -0.06991947
%%R
AIC(GNARfit(betaOrder = c(2, 1)))
[1] -0.05994387

3.2. Model selection on a wind network time series

the data suite vswind that contains a number of R objects pertaining to 721 wind speeds taken at each of 102 weather stations in England and Wales. The suite contains the vector time series vswindts, the associated network vswindnet, a character vector of the weather station location names in vswindnames and coordinates of the stations in the two column matrix vswindcoords. The data originate from the UK Met Office site http://wow.metoffice.gov.uk and full details can be found in the vswind help file in the GNAR package.

  • nodes : 102
  • time step : 721
%%R
oldpar <- par(cex = 0.75)
windnetplot()
par(oldpar)

Plot of the wind speed network

  • blue numbers are relative distance between sites
  • labels are the site name
%%R
BIC(GNARfit(vts = vswindts, net = vswindnet, alphaOrder = 1, betaOrder = 0))
[1] -233.3848
%%R 
fiveFit <- GNARfit(fiveVTS[1:160,],net=fiveNet, alphaOrder=2, betaOrder=c(2,0)) #learn 
dim(fitted(fiveFit))
[1] 158   5
%%R
dummyFit <- GNARfit(fiveVTS,net=fiveNet, alphaOrder=2, betaOrder=c(2,0)) #learn 
dummyFit$mod$coefficients <- fiveFit$mod$coefficients
%%R
fitted(dummyFit)[161:200]
 [1]  0.01093152  0.07611113  0.50989356  0.84380803  0.90488185 -0.12703505
 [7] -0.57721780 -0.36681689 -0.26281975 -0.47712098 -0.62293008 -0.58121816
[13] -0.81149078 -0.45403821 -0.60487041  0.28617606  0.20580455  0.19341988
[19]  0.35296420  0.15628117  0.68350847  0.49043974  0.29627168 -0.35666858
[25] -0.47565960  0.06692171 -0.14924170 -0.36616239 -0.49994894  0.22625500
[31] -0.08023045  0.25371268 -0.47415540 -0.99390660 -1.16821429 -0.18438203
[37] -1.10766872 -0.76969390  0.71828989  0.69737474
%%R
fitted(fiveFit)
               [,1]         [,2]         [,3]          [,4]         [,5]
  [1,]  0.300764573  0.731759572  0.645747192  0.6590441235  0.329408573
  [2,]  0.584155581  0.709939766  0.504838042  0.4006542005  0.002404727
  [3,]  0.248206643 -0.053672929  0.089912292  0.3569760840  0.886027241
  [4,]  0.431422029 -0.596332784 -0.445500333 -0.1950437084  0.998677531
  [5,]  0.369251545 -0.131646096 -0.151852774 -0.0307057532  0.602574799
  [6,] -0.281163998  0.372761568  0.470612441  0.0640593261 -0.793452225
  [7,] -0.629184394  0.122210560 -0.064188223  0.2614228537  0.027403171
  [8,]  0.176102146  0.054605602  0.001654112 -0.0679337406 -0.041235943
  [9,] -0.168610998 -0.212095723 -0.204125726 -0.2125261302 -0.010579734
 [10,] -0.161421278 -0.007465513  0.149274060 -0.0249484567 -0.327041759
 [11,]  0.359655447 -0.077039236 -0.039580520 -0.0457447866  0.112500734
 [12,] -0.015390804 -0.224700395 -0.236137628 -0.1566997305 -0.032236173
 [13,] -0.254595294 -0.052425427 -0.222029463 -0.1955623614 -0.090852345
 [14,] -0.133378083 -0.231175869 -0.262111004 -0.4557269171 -0.613390251
 [15,] -0.299492590 -1.329777415 -1.157380728 -0.7395871328  0.367735930
 [16,] -0.092939379 -0.649485715 -0.649077093 -0.5677985865  0.018220159
 [17,] -0.197734475  0.006055154  0.003767933  0.0142878952  0.017169293
 [18,] -0.593128663 -0.029057099  0.019930836 -0.1995170085 -0.699678586
 [19,] -0.406803183 -0.080878255 -0.076916012 -0.0142207300  0.084031465
 [20,]  0.195661742  0.636973567  0.514808183  0.1521298877 -0.565262518
 [21,] -0.646798007  0.034595763 -0.038468526 -0.2844049647 -1.200687294
 [22,] -0.858660467 -0.279197317 -0.100300563 -0.1774862659 -0.600631944
 [23,]  0.072500668  0.171516441  0.137895886  0.1253750409  0.109017776
 [24,]  0.361169443 -0.134591857 -0.172907391 -0.0276254736  0.454886946
 [25,] -0.555837928  0.021772877  0.086135588 -0.5401601843 -1.758757275
 [26,] -0.907025497 -0.516889787 -0.601369437 -0.4907248867 -0.518976355
 [27,] -0.577788165 -0.883706611 -0.990274375 -0.5655498386  0.219126828
 [28,] -0.381253476 -1.020667212 -0.974967606 -0.8163078225 -0.224880458
 [29,] -0.418889129 -1.136651964 -1.192973176 -0.8278078873  0.075705061
 [30,] -0.430848760 -0.711242749 -0.645456670 -0.7835485785 -0.902099485
 [31,] -0.408762558 -0.330133901 -0.313267801 -0.2950574688 -0.516672981
 [32,] -0.397456978 -0.177503203 -0.123190622  0.0851676997  0.175790185
 [33,] -0.321504797  0.137826136  0.185516044 -0.0469442492 -0.541534195
 [34,] -0.446890348  0.425984103  0.440639199  0.0859296090 -0.911239457
 [35,] -0.409664931  0.661582101  0.615592428  0.4648149587 -0.620671093
 [36,] -0.178853576  1.134703079  1.170584884  0.7788603566 -0.614547790
 [37,] -0.187107405  0.975055141  0.894986103  0.7556786981  0.299963760
 [38,] -0.421512891  0.230443777  0.311288224  0.3783662241  0.481463020
 [39,]  0.551866636  0.010017627 -0.031712684 -0.0291730137  0.299117468
 [40,] -0.415705371 -0.084974037 -0.102059950  0.0729357811 -0.004680301
 [41,] -0.596582277 -0.181138675 -0.037759798 -0.0710576429 -0.300907209
 [42,] -0.264388277  0.136784757  0.077185718  0.0270845136 -0.311590329
 [43,]  0.413516614  0.932841430  0.935079115  0.7161523403 -0.158898407
 [44,]  0.095801809  0.920995408  0.955252555  0.8459697803 -0.127453246
 [45,]  0.975373534  1.209886345  1.185240223  1.0015804496  0.169827608
 [46,]  0.618868253 -0.058442807 -0.058935046  0.2370795943  0.914954875
 [47,]  0.366854292  0.267881271  0.247344186  0.2400219950  0.479987689
 [48,] -0.150157867 -0.777932308 -0.717286974 -0.5794468369  0.195377648
 [49,]  0.075029321 -0.299959011 -0.355342761 -0.1920419709  0.334423437
 [50,]  0.386593451 -0.135877992 -0.072542184  0.2518678243  0.984484742
 [51,]  0.697822864 -0.311896474 -0.295669625 -0.2502382955  0.585030936
 [52,]  0.062654477 -0.191584061 -0.107314176  0.2208996954  1.056837103
 [53,]  0.728773427 -0.477836693 -0.494169917 -0.4843342717  0.451358938
 [54,]  0.585069845  0.665543312  0.719452401  0.5820396956  0.545931719
 [55,]  1.079661317  0.127297862  0.038038488  0.0677187351  0.907180658
 [56,]  0.651000271  0.443573833  0.461237609  0.2318123507  0.355931847
 [57,]  0.047340441  0.061483244 -0.142562719 -0.0074741198  0.203598849
 [58,]  0.020722674 -0.855956709 -0.772986200 -0.7280158105 -0.072139463
 [59,] -0.197216261 -0.894976325 -0.740954981 -0.7972459012 -0.237856418
 [60,] -0.335837112 -0.488349114 -0.651565734 -0.7163113371 -0.703717928
 [61,] -0.573434288 -1.566963776 -1.470953366 -0.9358838106  0.340002593
 [62,] -0.019967493 -1.006103326 -1.203028246 -0.7206978782  0.426166645
 [63,]  0.289165755 -0.676589963 -0.529091393 -0.3863962807  0.580747013
 [64,] -0.063683833 -0.320450285 -0.325613255 -0.2974046265 -0.105675029
 [65,] -0.112032969 -0.527479112 -0.523398055 -0.1590403400  0.496544412
 [66,] -0.286173235 -0.053400092  0.018863005 -0.0124208740 -0.118724115
 [67,] -0.499744957  0.041067235  0.076504951 -0.2048682261 -0.787362589
 [68,] -0.547870145 -0.732546310 -0.770409578 -0.7369449312 -0.331821251
 [69,] -0.905056316 -0.829491825 -0.850502405 -0.7607730212 -0.656264847
 [70,] -0.246440697 -0.279850678 -0.269853546 -0.5660758221 -1.111827018
 [71,] -0.186335645  0.010799425 -0.077495418  0.0601490253  0.102437820
 [72,]  0.010493539 -0.479453043 -0.453954591 -0.3426073144 -0.040090049
 [73,] -0.673580794 -0.734494634 -0.564315445 -0.8190023610 -1.019947630
 [74,] -0.640032299 -0.558498277 -0.596977420 -0.5456733025 -0.090276605
 [75,] -0.464960459 -0.529199551 -0.552331950 -0.8884973812 -1.066744453
 [76,] -0.887182659 -0.141258133 -0.110786546  0.0237603066  0.003998690
 [77,] -0.073105627 -0.207336194 -0.187193599 -0.6930066146 -1.105251019
 [78,] -0.689981040  0.027486354  0.151691133  0.2650861359 -0.203709649
 [79,]  0.258382277  0.652801148  0.545006830  0.3925781271 -0.249181067
 [80,]  0.751377138  0.239900459  0.276168396  0.6057405726  1.262601102
 [81,]  0.631390471  0.411822991  0.543334476  0.2438621480  0.112347717
 [82,] -0.034969641 -0.104184784 -0.097705561  0.1498464790  0.895833940
 [83,]  0.120113065  0.049356967  0.046034277 -0.0721309377  0.217972070
 [84,] -0.200386785 -0.203495710 -0.239586254 -0.1172887981  0.323191787
 [85,]  0.185644181 -0.395187380 -0.370733604 -0.5009300085 -0.211102667
 [86,] -0.237732516  0.276454796  0.287754635  0.2080093644 -0.223951494
 [87,]  0.216163467  0.192130141  0.177949800 -0.0753244143 -0.351364565
 [88,] -0.142649364 -0.186692214 -0.168987298 -0.1166303744  0.011404103
 [89,]  0.548618117  0.747707315  0.770581155  0.5221810333  0.172075628
 [90,]  0.028104354  0.688465275  0.636215214  0.5500772784  0.059464762
 [91,] -0.495363724 -0.071919605 -0.008154852 -0.4353087653 -1.271143508
 [92,] -1.107134875 -0.172815824 -0.303687490 -0.0844525666 -0.236711607
 [93,] -0.149354271  0.009431534  0.092873697 -0.4137230613 -1.079758945
 [94,] -0.480127162 -0.759207617 -0.733556252 -0.1155717520  0.856016011
 [95,] -0.068768871 -0.262250231 -0.276510238 -0.4068034977 -0.281317568
 [96,] -0.204766674 -0.466093264 -0.516820813 -0.4012743931 -0.036227691
 [97,]  0.450365055 -0.345449271 -0.277951368 -0.0735386028  0.626942400
 [98,]  0.825252322 -0.102070954  0.029346323  0.2224587296  0.891243876
 [99,]  0.918255191  0.974393754  0.785132509  0.9588950601  0.747082329
[100,]  1.161471681  0.803193156  1.046464965  1.2474096963  1.536524225
[101,]  0.796513581  0.943461644  0.698756745  0.5968311778  0.275247231
[102,]  0.189772234  0.088167353  0.193522913 -0.1055246595 -0.205361362
[103,] -0.486312684  0.528260131  0.609425778  0.4533837262 -0.448633125
[104,] -0.780106474  0.619638040  0.487082196  0.2699333424 -1.074329863
[105,]  0.001495171  0.043686101  0.071429149 -0.0068869393  0.109059794
[106,]  0.412811020  0.589258087  0.534530373  0.1827023688 -0.169191222
[107,]  0.230033356  0.369815780  0.441499631  0.4808802972  0.619074058
[108,]  0.887957665  0.299276196  0.242694214  0.2120811348  0.437908215
[109,] -0.003445154 -0.934051132 -0.730038077 -0.3220444395  0.707556500
[110,] -0.138607950 -0.723059594 -0.801323554 -0.7383525593 -0.366013353
[111,] -0.761794858 -0.776583246 -0.767390838 -0.6281202398 -0.286591883
[112,] -0.143995206 -0.994654745 -0.891931956 -0.8145750541  0.194529857
[113,] -0.158840376 -0.789802525 -0.720611341 -0.3434589195  0.705106074
[114,]  0.213701938  0.094954893 -0.066337346 -0.1715778242 -0.301015012
[115,]  0.353147878 -0.162438159 -0.035453134  0.2417453098  0.692188468
[116,] -0.259026322 -0.062564122 -0.069539905  0.0494333669  0.016725122
[117,]  0.439567933  0.334238798  0.123452083  0.2899531832  0.536404389
[118,]  0.243694767 -0.136731679 -0.062368473 -0.0505163356  0.329751821
[119,] -0.221760052 -0.034088224 -0.073079140 -0.0719693132  0.080492952
[120,] -0.639870092 -0.346958117 -0.350162454 -0.6158933852 -1.052705642
[121,]  0.191514800  0.198936857  0.188570749  0.0576140540 -0.098783032
[122,]  0.497040376  0.104911046  0.183534206  0.3233013200  0.725368718
[123,]  0.912741276  0.906110114  0.847102372  0.9050828507  0.840894148
[124,]  0.761509505  0.486180954  0.657445208  0.6485641139  0.813518998
[125,]  0.316821416 -0.083720193 -0.173493262 -0.1007134067  0.356082268
[126,] -0.067185056 -0.753094489 -0.702750670 -0.2621385119  1.046954137
[127,] -0.091228436 -0.675109353 -0.703565297 -0.5564405787  0.258988050
[128,] -0.109253436 -0.444143304 -0.399640932 -0.3580561559 -0.035762392
[129,] -0.232521560 -0.039990247 -0.095241200 -0.0443450553 -0.430664437
[130,]  0.123446724  0.200420996  0.173518282  0.5184071044  0.313636742
[131,]  0.285159008 -0.032242166  0.027550780  0.1048459050 -0.132334038
[132,] -0.029094326  0.291860928  0.394652562  0.4297945912  0.077465921
[133,]  0.607314455  0.854271821  0.946947611  0.7446008823  0.229008010
[134,]  0.114274696  0.395094364  0.372741933  0.2933528915  0.073135295
[135,]  0.058334948  0.020883512 -0.064495939 -0.0002935146  0.194116690
[136,] -0.485203794  0.162128088  0.243616443  0.0173331790 -0.588154182
[137,]  0.361414229  0.497203208  0.361158226  0.5018799742  0.573470360
[138,]  0.819903948  0.366313425  0.363516294  0.3796662479  0.699684917
[139,] -0.216165855 -0.335708047 -0.251520773 -0.2682301442  0.062768414
[140,] -0.454294227 -0.359066363 -0.294969357 -0.4097376437 -0.479590775
[141,] -0.062418172  0.009466708 -0.051169781  0.1398314442  0.275918751
[142,]  0.546927988  0.424770686  0.388169659  0.1288546957 -0.347653081
[143,] -0.311508529  0.345041027  0.500511866  0.3303953879 -0.189245985
[144,]  0.156321321  0.623518356  0.518171727  0.4513620372  0.284295098
[145,]  0.039622964  0.299954776  0.356381605  0.3469508290  0.326305082
[146,]  0.579791654  0.695810253  0.652099702  0.5011115910  0.023065334
[147,]  0.554655907  0.093490122  0.153079897  0.4182759318  0.767121199
[148,]  0.384057236 -0.065678272 -0.023948715  0.0451867298  0.454508452
[149,]  0.447874514  0.392017250  0.266888939  0.3039632644  0.540801889
[150,]  0.497810670  0.980726335  1.014061377  0.9632510637  0.560362395
[151,]  0.044270389  0.550595322  0.526083974  0.5090146051 -0.039702900
[152,]  0.128989148  0.501717816  0.494582107  0.2658346703 -0.283886186
[153,]  0.003640933  0.471547028  0.593579063  0.5105159483  0.179982706
[154,]  0.207081614  0.420074580  0.265684904  0.2159979026 -0.161101019
[155,] -0.478137997  0.240399554  0.349195339  0.3926704926 -0.290283502
[156,] -0.368038032  0.588505317  0.539132547  0.2403574312 -0.831187194
[157,] -0.452959327  0.212753187  0.402307299  0.1713284561 -0.415735323
[158,]  0.013726373  0.132970935  0.077022243  0.0243587773 -0.211000744
%%R 
fiveVTS
#gdpVTSn2[52,]
               [,1]         [,2]         [,3]         [,4]        [,5]
  [1,] -0.106526553  1.077613724 -0.244694569  0.933710066  0.44443593
  [2,]  0.664495737  0.935476457  1.402823610  0.826656526  0.02097885
  [3,] -0.255977521 -1.478171940  2.160938890  1.746276180  0.80188586
  [4,]  1.684436464  0.180662387  0.398879113 -0.418094544  0.28037722
  [5,]  1.451205104  0.584157057 -1.700218367 -1.219724913  1.63810802
  [6,]  0.728846398  0.536253148 -0.730310794 -0.297010221  1.04864255
  [7,] -1.526780869  1.957817106 -0.506088728  0.470747730 -0.63167929
  [8,]  1.269035583 -0.519870107  0.773038576 -0.176065931 -3.13354575
  [9,] -0.403340381 -0.398760476  1.358212255 -0.755544421  1.58592625
 [10,] -0.057805476 -0.932876792  0.163580296 -0.299486667 -0.31232748
 [11,] -0.498505318  1.005323196 -0.762045202  0.136725053 -0.43412619
 [12,]  0.057551667  0.252414834 -1.585146661  0.892773199  0.64534882
 [13,] -0.235969810  0.168738145 -0.927906887 -0.201182245  0.28394360
 [14,] -0.574265201 -0.451671164  1.523378623 -1.466113999  0.88143283
 [15,] -1.120369546 -2.167955049 -0.290951250  0.951438750 -0.63430591
 [16,]  0.734315543 -1.074175821 -2.550164018 -1.843026440  0.16372069
 [17,] -0.300708705 -0.215965234 -1.251829204 -1.147084336  0.81200151
 [18,]  0.168111491  0.617846030 -0.067553835 -0.316813889 -0.57552628
 [19,] -1.130660662  1.049382642 -0.219923688 -0.838450813 -0.84289855
 [20,]  0.491603006  0.911202204 -0.037939755 -1.146905077 -0.70878526
 [21,] -1.282680651 -0.037695723  1.273889958  1.222120228  0.48792144
 [22,] -1.977860407 -1.476586870  0.618312041  0.541447907 -1.59494685
 [23,] -0.566157633  1.007129193 -0.421914435 -1.255494830 -1.57780757
 [24,]  0.427751755  0.446864227 -0.006556415  0.235046101 -0.13251371
 [25,]  0.588963964 -0.510977075 -0.208215798 -0.038859202  1.03505405
 [26,] -3.577108873  0.063814248 -0.764773488  0.750897963 -0.57677829
 [27,] -0.762998219 -0.715903539  0.070974165 -1.767866460 -0.85886671
 [28,]  1.154873570 -2.505711766 -0.235496918 -1.464120269 -1.74689908
 [29,] -0.272693870 -1.857460255 -1.012583601 -1.478438760 -0.20065611
 [30,]  0.395708110 -2.601309968 -1.102332663 -1.418525692 -0.67074519
 [31,] -1.632021790 -1.389226367 -1.406639927 -0.164463613 -0.57992151
 [32,] -0.593868925 -0.604746854 -0.889344852  0.170550009 -1.19152282
 [33,]  0.902385866  0.859337939 -0.216488189 -1.019066503 -1.20331830
 [34,] -0.755599082  1.205454399 -0.315142793 -0.182216870 -0.76219579
 [35,] -1.402617202  1.327218071  0.030109089  0.508358610 -1.19204930
 [36,] -0.248901260  0.835443000  0.673836075  1.249100802 -2.50681088
 [37,] -0.821889741  2.683690391  1.991361276  0.628557722 -0.63183483
 [38,]  0.509052231  2.387571425  3.198218488 -1.313720751  0.41614740
 [39,]  1.760264680  1.329747672  0.589082315 -0.959062662 -2.17248032
 [40,]  0.407692882 -0.494160904 -0.336544078  0.518871030  1.17098422
 [41,]  0.529542953 -0.109371157  0.276546799 -0.441917032 -1.77465267
 [42,]  0.071422121  1.390859571 -0.656166400 -1.112883997 -1.53889722
 [43,] -0.038685141  0.343631869 -0.121075284  0.189519172 -1.28519302
 [44,]  0.032507365  1.105775541  0.745569895  2.313785056 -0.54606867
 [45,]  0.326298291  1.672376452  0.867801558  1.596593083 -1.38530798
 [46,]  0.493735214  0.828445070  0.665517459  3.545540325  0.17892418
 [47,]  1.046193130  0.182022439  0.076358398 -0.564071723  2.31894117
 [48,]  0.487801423  0.402192928  0.660265277  0.160859127  0.85916399
 [49,]  0.012036883 -0.575802156 -1.375502706 -1.555497631  0.78253503
 [50,]  0.566249612 -0.679123506 -0.342116629 -0.293370938  0.16791547
 [51,]  1.983899460  0.325870466 -0.462247924 -0.144103964  0.20428669
 [52,]  0.082477869 -0.015707410 -0.827420937 -0.533338717  3.03848854
 [53,]  2.025321199  1.260059506 -0.667274520 -0.983423623 -0.25069462
 [54,] -0.182207953 -0.492329932 -1.572486971 -0.318050791  3.11590615
 [55,]  0.310016519  2.163157480  0.539075569  0.775034293  1.55599197
 [56,]  0.344219807 -0.289984010  0.019376746  0.352604618  3.88803701
 [57,] -0.628460347  0.908826573  0.839215153  0.387888048  2.79852674
 [58,]  0.219514752 -1.949662023  1.297952270  0.245509848 -0.10715958
 [59,] -0.703231049 -1.872499373 -0.948118550 -0.956147553  1.46327573
 [60,] -1.037484518 -0.353586885 -2.197040404 -1.022195776  1.03019923
 [61,] -1.671104120 -1.807816077 -0.456726722 -0.275561042  0.23349098
 [62,]  1.082454650 -2.163914674 -2.772699788 -1.867484810 -1.15276058
 [63,]  0.733526181 -2.901286567 -0.144692022 -1.533368920  0.64538823
 [64,]  0.607622782 -0.564034684 -1.024446572 -0.860302664  1.46464103
 [65,] -0.249447697 -0.622497600 -0.860157861  0.059602510 -0.28629810
 [66,]  1.242991882 -0.553213122 -0.784868076 -0.866755329 -0.50726271
 [67,]  0.025808026  1.134045937 -0.194833475 -0.766397319 -0.66714031
 [68,] -1.280038469  0.969797971 -0.529341149 -0.274648131 -0.88451275
 [69,] -0.899437152 -0.455454165 -0.889218336 -2.081201461  0.63782940
 [70,] -0.485225451 -1.579881065 -1.542956678 -0.728773133 -2.63529295
 [71,] -2.232840088 -0.666470900 -0.802215707  0.306471316  0.36000506
 [72,]  0.263283350 -0.473210196  0.858443996 -0.330691066 -0.23528971
 [73,]  0.194868023 -1.673792947 -1.157081284  0.464290012 -0.67196384
 [74,] -2.374209088  0.746939110 -1.641811447 -1.805924541  0.66216561
 [75,] -0.319164807  0.368646446 -0.675529010 -2.103798682  0.06414596
 [76,] -2.347006749 -0.926133386 -1.280596322 -0.435692565  0.21824222
 [77,]  0.446994651  1.473521493  0.734103122 -2.231131628 -1.36931119
 [78,] -2.402766578 -0.673636271 -1.514644362  0.766704957  0.57180703
 [79,]  0.591165442  1.638210347 -0.954659887  0.008337226 -2.90507678
 [80,] -0.284550885  0.812008860  0.745209777  1.099796776  0.12632330
 [81,]  2.404372924  0.494780967 -0.137672593  0.738809147  0.71597343
 [82,] -0.732204526  2.210038243 -0.355431422  0.339909653  2.46725315
 [83,]  1.437145004  1.547713162 -0.345952409 -1.578834604  0.52850356
 [84,] -0.084957358  1.234464257 -0.032386550 -0.956802127  1.29018233
 [85,]  0.630013261  0.172600953 -0.127816246 -1.056826347 -0.23795324
 [86,] -0.893457396 -0.660542921 -1.265061454  0.015612038  1.27234265
 [87,] -0.287301062  0.963686285  0.359594848  0.203580641 -0.80393259
 [88,] -1.133229025  0.151632482 -0.040554491  0.515841576  1.28839412
 [89,] -0.023953670 -0.117144878 -0.537169309 -0.192949617 -0.19885872
 [90,] -0.238994400  1.725878556  1.063475592  0.828811176  1.72692730
 [91,]  0.299232378  0.799624873  1.181753039  0.831726730 -0.84857446
 [92,] -2.481179710  0.113529319 -0.650053446  0.011672273 -0.33558946
 [93,]  0.312713660 -0.079515578  1.502108851 -2.180229770 -2.24161884
 [94,] -1.996496328 -0.407588562 -0.652585366  0.923280995 -0.15832811
 [95,]  2.250167112 -0.220512659 -0.805730284 -2.066199413 -1.28057608
 [96,] -0.763689773 -0.031020794 -0.208759418 -0.867474784  0.72626616
 [97,]  0.014431435 -1.336163148 -0.640654650 -0.333381100 -0.44435745
 [98,]  0.957691513 -0.361694475 -0.967050395  0.060214711  1.10246612
 [99,]  1.469745730  0.554733531 -1.990318074  1.277950650  0.91469843
[100,]  1.356192755  0.363980993  1.646543813  2.153855538  0.49502358
[101,]  3.001712443  2.666746291 -0.368684582  1.849950555  0.63675201
[102,] -0.281234965  0.456235005  2.292473984  0.854928226  2.22619190
[103,] -1.140727890  0.202030354 -0.219402824  0.310787559  1.38376301
[104,] -0.101523413  1.693526806  0.088496042  0.849098718 -2.58113447
[105,] -1.122014513  0.674017745  1.696074464  0.065284585 -2.46042966
[106,] -0.050503692  0.476461163  0.741019471 -1.033544711  1.30742678
[107,] -0.977589842  0.119899249  1.188456997  1.081889577  1.41965239
[108,]  0.909422801  1.255343375  0.842509208 -0.192153747  0.71392520
[109,]  0.441028047 -0.896440332 -0.270300473  1.985698469  1.24604331
[110,]  1.237351903  0.285784091 -2.573210003 -1.364613642  0.30715435
[111,] -0.812621272 -1.216797535 -1.946208168 -0.293442424  0.01613793
[112,] -0.569590223 -0.000629766 -0.657769831 -2.422099355 -0.23850071
[113,]  0.013135413 -0.269047393 -2.386679520 -1.612243344  1.04220642
[114,]  1.497050345  0.473005141 -2.121414725 -1.449151157 -0.36453856
[115,] -0.826489548 -0.635578799  0.160746530  0.588310936  0.64139235
[116,]  1.714414681 -0.069917852 -1.565924860  1.120471391 -0.78042307
[117,]  0.090005879  1.200734542  0.270198304 -1.404710351 -0.03628579
[118,]  1.236752409 -1.518803758  1.237344754  1.129076932 -0.20967169
[119,] -0.087766705  0.109758177  0.830463404 -1.215657793  2.10369911
[120,]  0.171155851 -0.458798255  0.673636072 -0.491339577 -0.55057403
[121,] -2.015292503 -0.870762059 -0.029309395 -0.793820162 -0.46857349
[122,] -0.362231614 -0.364385616  0.389845581  0.862317056  0.58137591
[123,]  1.134908449  0.528983153 -0.215140490  0.381732812  0.95051905
[124,]  1.457741194  0.847372382  1.281677103  1.882417946  0.73169697
[125,]  1.108355891  2.153722703 -0.310021511  0.663789759  1.50520899
[126,]  0.071438586 -0.058006918 -0.325876606 -0.374044712  1.44845100
[127,]  1.793527240  0.106114670 -0.893934806 -2.276541783  0.63834022
[128,]  0.315117203 -0.717323756 -0.955019446 -1.370627155  0.39051426
[129,] -0.043340209 -0.312945747 -1.197591049 -0.317055511 -0.20153262
[130,] -0.102618844 -0.880170227 -0.604543790  1.138606188 -2.06784587
[131,]  1.740909147 -0.637353850 -0.010562729  1.561563247 -2.32157478
[132,]  0.188345255 -0.469433386 -0.998242748  1.333047029 -0.61688863
[133,]  0.478267920  1.814870921 -0.214383410  0.211463195 -0.68793981
[134,]  0.520210151  2.448452650 -0.463708150  1.952197392  0.18188706
[135,] -0.269362229  1.911952464  0.242272223 -0.444547682  1.07677467
[136,]  0.423190923 -0.410880998 -0.195993929  0.257239829 -0.28741994
[137,] -1.026903990  1.526871656  0.360358335 -0.772639199 -0.55385790
[138,]  1.450078506 -0.349330702  1.034884543  1.105119122 -0.44915787
[139,]  0.550436921  0.247527774  1.257978907  0.192344787  2.62949378
[140,] -0.191655801  0.134136826 -0.521197521 -1.048113725  0.16877213
[141,] -0.791900380  0.321889000 -1.170523314 -0.640876817 -0.67475039
[142,]  0.971146450  0.021298110 -0.039896748  0.046666821 -0.88362522
[143,] -0.982608481 -0.377262589  0.171316614  1.854723760  0.99834845
[144,] -0.495627812  2.483176264  0.354246741 -0.684488580 -0.02501307
[145,]  0.561938527  0.993967044  1.211151634  0.257789007  0.12399797
[146,]  0.709311790  1.260796758  0.500729309 -0.317030392 -0.10472747
[147,]  0.242781056  0.024085820  0.200161589  2.499565048 -0.35615091
[148,]  1.391448147  0.433674956 -0.406153463  0.535043661  0.73457838
[149,]  0.412636662  0.657392857 -0.602350630 -0.222007914  1.28589205
[150,]  0.464724442  0.241309629  1.384164088 -0.007823340  1.51425328
[151,]  1.387500492  1.166650199  1.425112356  1.867514447 -0.82096695
[152,]  0.324362289  0.546923900  1.123115609  0.598062895 -0.86820404
[153,] -0.642847662  0.488927474  1.005998211  0.623605903  0.36832761
[154,]  0.580613501  1.826643913  0.215912542  0.360628058 -0.61370894
[155,] -0.144307876 -0.646151661  0.724633376  1.186826797 -0.31028196
[156,]  0.546715317  0.754951418 -0.046634000  0.644574743 -3.02529497
[157,] -1.292512590  1.254904828  1.493495999 -0.128867226 -0.51111891
[158,] -0.178360098  1.914596966 -0.981080025  0.228541535 -1.75337640
[159,] -0.292207540  0.598820101 -0.516651587  0.274304089  0.03373131
[160,] -2.308524149  0.208852278  1.461230272 -0.500911249 -2.27810147
[161,] -1.379791032  0.145882158  0.915799429  1.484776097 -3.50041126
[162,] -0.687780533 -0.916656103  1.270414228  1.016692379 -0.33067553
[163,]  0.719998169  2.802816864  1.671148575 -0.623046401  0.58186844
[164,]  0.720895216 -0.441022235  1.355521153  0.169312739  1.37392204
[165,]  1.255917246  1.237433250 -1.261445845  1.156903886  1.34803048
[166,]  1.705742677 -2.082080117  1.178644006  0.035092003  2.31810280
[167,] -1.241297515 -1.810899663  0.429577096 -1.605573403  1.82238571
[168,] -1.733594362 -1.512615033 -0.660630798 -0.541034771 -0.51548359
[169,]  0.792480615  1.111823458 -0.087410649 -0.471304848 -1.46894677
[170,] -1.308490289 -0.820921717 -1.060340478 -0.848828375  0.61581232
[171,] -0.151371781 -1.755296255 -2.178401224 -1.133293893 -0.73148664
[172,] -1.440949271 -1.701461336  0.086620787 -0.574783622 -0.96759066
[173,] -0.602659336  0.088764382 -1.505800731 -1.165425847 -0.71480221
[174,]  1.275259704 -0.410086120  0.494580410 -2.991666233 -1.27793672
[175,] -1.404478046 -0.271241519  0.442854733 -0.222198583 -0.71844124
[176,] -0.656202533  1.203821570  0.978017687  0.126331498 -1.96978752
[177,] -0.394150009 -0.161910841  2.176312978  0.695232617  0.89852498
[178,]  0.942635640  0.627373149  1.433906899 -0.365531957  0.60603188
[179,] -0.023229999  1.377273430 -0.409007667  1.061813530 -0.29478037
[180,]  0.365704922  1.211613739 -1.923486162  0.212759987  0.96275639
[181,] -0.005420862 -0.765759383 -1.517079711  0.902219156 -0.34235656
[182,]  0.024961781  0.098786009 -0.242548348  0.230247435  2.58670863
[183,]  0.827409379 -0.019279260  1.645100501 -0.517327835  1.97867114
[184,]  0.446528306 -0.641671765  0.183926490  0.194955794  0.61934460
[185,] -0.852794309 -0.150650614 -1.175556623 -0.749290811 -0.16935739
[186,]  0.545053341 -0.164000579 -0.705192833 -2.243859141 -0.09017822
[187,] -1.237547900  0.639970678 -0.071693146  0.802596589  0.36885061
[188,] -0.400597906 -0.490175656  1.285472941  0.566619402 -0.76045074
[189,] -0.346030030 -0.031140831  0.468958960 -0.626935003 -0.58954715
[190,] -0.242598074 -0.643482354  0.637618122  0.729482578 -2.59565491
[191,]  1.906927330  1.295421628 -0.473359922  0.009433931 -0.45087521
[192,]  0.247556013  0.380624945  0.511373051 -0.303734068 -0.35216521
[193,]  0.109182478 -1.095266046 -1.117244679  0.260695357  0.63022764
[194,] -0.428068355  0.957493744  1.147709215 -1.806721502  0.20508136
[195,] -2.391696093  1.006982896  0.469035946 -1.029263987 -1.23612823
[196,] -2.210774865 -1.403493412  0.556772208 -0.600485513 -2.42048578
[197,] -0.722601932 -0.414053540  0.988636770 -0.610321642  0.58772892
[198,] -2.938590715 -0.559749691  0.078615069  0.010633188 -2.36841490
[199,] -0.985951916  0.215394351 -0.119048423  0.779733910 -2.98799845
[200,]  0.447242609  0.404155027  0.719959458 -0.442525233 -1.78159592
%%R
BIC(GNARfit(vts = vswindts, net = vswindnet, alphaOrder = 1, betaOrder = 0, globalalpha = FALSE))
[1] -233.1697
%%R
BIC.Alpha2.Beta <- matrix(0, ncol = 15, nrow = 15)
for(b1 in 0:14)
    for(b2 in 0:14)
        BIC.Alpha2.Beta[b1 + 1, b2 + 1] <- BIC(GNARfit(vts = vswindts,
                    net = vswindnet, alphaOrder = 2, betaOrder = c(b1, b2)))
contour(0:14, 0:14, log(251 + BIC.Alpha2.Beta), xlab = "Lag 1 Neighbour Order", ylab = "Lag 2 Neighbour Order")
Exception ignored from cffi callback <function _processevents at 0x7f1829767f70>:
Traceback (most recent call last):
  File "/home/csy/anaconda3/envs/csy/lib/python3.8/site-packages/rpy2/rinterface_lib/callbacks.py", line 277, in _processevents
    try:
KeyboardInterrupt: 
Exception ignored from cffi callback <function _processevents at 0x7f1829767f70>:
Traceback (most recent call last):
  File "/home/csy/anaconda3/envs/csy/lib/python3.8/site-packages/rpy2/rinterface_lib/callbacks.py", line 277, in _processevents
    try:
KeyboardInterrupt: 
Exception ignored from cffi callback <function _processevents at 0x7f1829767f70>:
Traceback (most recent call last):
  File "/home/csy/anaconda3/envs/csy/lib/python3.8/site-packages/rpy2/rinterface_lib/callbacks.py", line 277, in _processevents
    try:
KeyboardInterrupt: 
  • a set of GNAR(2,[b1,b2]) models with b1, b2 ranging from zero to 14
  • Contour plot of BIC values for the two-lag autoregressive model incorporating b1-stage and b2-stage neighbours at time lags one and two. Values shown are log(251 + BIC) to display clearer contours.

이해 덜 됨..

  • increasing the lag two neighbour sets beyond first stage neighbours would appear to increase the BIC for those lag one neighbour stages greater than five

chatGPT

이 문장을 조금 더 자세히 설명하면, BIC(Bayesian Information Criterion)는 모델을 선택할 때 사용하는 지표로서, 우리가 선택한 모델이 얼마나 적합한지를 측정합니다. 이 문장에서는, 이웃 집합의 대기 시간이 증가할수록 BIC 값이 증가할 것이라고 언급하고 있습니다. 이는 우리가 선택한 모델이 적합하지 않을 가능성이 있다는 의미입니다. 그래프를 보고 있을 때, 수평 윤곽선은 BIC 값이 0인 스테이지를 의미합니다. 이는 우리가 선택한 모델이 완벽하게 적합한다는 의미입니다.

%%R
goodmod <- GNARfit(vts = vswindts, net = vswindnet, alphaOrder = 2, betaOrder = c(5, 1))
goodmod
Model: 
GNAR(2,[5,1]) 

Call:
lm(formula = yvec ~ dmat + 0)

Coefficients:
 dmatalpha1  dmatbeta1.1  dmatbeta1.2  dmatbeta1.3  dmatbeta1.4  dmatbeta1.5  
    0.56911      0.10932      0.03680      0.02332      0.02937      0.04709  
 dmatalpha2  dmatbeta2.1  
    0.23424     -0.04872  

3.3. Constructing a network to aid prediction

We propose a network construction method that uses prediction error, but note here that our scope is not to estimate an underlying network, but merely to find a structure that is useful in the task of prediction.

we use a prediction error measure, understood as the sum of squared differences between the observations and the estimates:

\[\sum^N_{i=1} (X_{i,t} - \hat{X}_{i,t})^2\]

%%R
prediction <- predict(GNARfit(vts = fiveVTS[1:199,], net = fiveNet, alphaOrder = 2, betaOrder = c(1, 1)))
prediction
Time Series:
Start = 1 
End = 1 
Frequency = 1 
    Series 1  Series 2  Series 3  Series 4   Series 5
1 -0.6427718 0.2060671 0.2525534 0.1228404 -0.8231921

4. OECD GDP: Network structure aids prediction

GOP growth rate time series

  • 35 countries from the OECD website

  • time series : 1961 - 2013

  • T = 52

  • Nodes = 35

  • In this data set 20.8% (379 out of 1820) of the observations were missing due to some nodes not being included from the start.

  • we do not uese covariate information, so C=1

%%R
library("fields")
layout(matrix(c(1, 2), nrow = 1, ncol = 2), widths = c(4.5, 1))
image(t(apply(gdpVTS, 1, rev)), xaxt = "n", yaxt = "n", col = gray.colors(14), xlab = "Year", ylab = "Country")
axis(side = 1, at = seq(from = 0, to = 1, length = 52), labels = FALSE, col.ticks = "grey")
axis(side = 1, at = seq(from = 0, to = 1, length = 52)[5*(1:11)], labels = (1:52)[5*(1:11)])
axis(side = 2, at = seq(from = 1, to = 0, length = 35), labels = colnames(gdpVTS), las = 1, cex = 0.8)
layout(matrix(1))
image.plot(zlim = range(gdpVTS, na.rm = TRUE), legend.only = TRUE, col = gray.colors(14))
R[write to console]: Loading required package: spam

R[write to console]: Spam version 2.8-0 (2022-01-05) is loaded.
Type 'help( Spam)' or 'demo( spam)' for a short introduction 
and overview of this package.
Help for individual functions is also obtained by adding the
suffix '.spam' to the function name, e.g. 'help( chol.spam)'.

R[write to console]: 
Attaching package: ‘spam’


R[write to console]: The following objects are masked from ‘package:base’:

    backsolve, forwardsolve


R[write to console]: Loading required package: viridis

R[write to console]: Loading required package: viridisLite

R[write to console]: 
Try help(fields) to get started.

Heat plot(grey scale) of the differenced time series,

  • white space indicates missing time series observations

4.1. Finding a network to aid prediction

%%R
net1 <- seedToNet(seed.no = seed.nos[1], nnodes = 35, graph.prob = 0.15)
net2 <- seedToNet(seed.no = seed.nos[2], nnodes = 35, graph.prob = 0.15)
%%R
layout(matrix(c(2, 1), 1, 2))
par(mar=c(0,1,0,1))
plot(net1, vertex.label = colnames(gdpVTS), vertex.size = 0)
plot(net2, vertex.label = colnames(gdpVTS), vertex.size = 0)

  • Erdos-Renyi random graphs xonstructed from the first two elements of the seed.nos variable with 35 nodes and connection probability 0.15.

  • 자기회귀 모델인 GNAR 모델을 예측에 사용할 때, 어떤 네트워크가 가장 적합한지 조사해야 함.

  • 이때 각 노드의 자기 상관 함수를 이용한 초기 분석 결과, 2차 자기회귀 구성 요소가 충분할 것으로 예상되어 p = 2까지의 GNAR 모델을 시험함.

  • 각 시간 지연에서 최대 2개의 이웃 집합을 포함함.

  • 이에 따라 아래와 같은 GNAR 모델이 시험됨.

    • GNAR(1, [0]), GNAR(1, [1]), GNAR(2, [0, 0]), GNAR(2, [1, 0]), GNAR(2, [1, 1]), GNAR(2, [2, 0]), GNAR(2, [2, 1]), 그리고 GNAR(2, [2, 2])가 시험되며, 각각 individual-\(\alpha\)와 global-\(\alpha\) GNAR 모델로 적합함.
    • 총 16개의 모델이 생성됨.
    • 이 중에서 전체 GDP 예측에 사용할 GNAR 모델을 선택할 것.
    • 연결 확률이 0.15인 10,000개의 임의의 양방향 네트워크를 생성하고, 위에서 언급한 GNAR 모델을 이용해 예측할 것.
    • 그래서 이 예제는 상당한 계산 시간이 필요(데스크탑 PC에서 약 90분).
    • 이를 위해 아래 코드에는 일부 분석만 포함.
    • 계산 상의 이유로, 우선 각 노드에서 표준 편차로 나눠서 잔차가 각 노드에서 동일한 분산을 가지게 함.
    • seedSim 함수는 예측값과 원래 값의 제곱 차이의 합을 출력하고, 이를 예측 정확도의 측정 기준으로 사용
%%R
gdpVTSn <- apply(gdpVTS, 2, function(x){x / sd(x[1:50], na.rm = TRUE)})
alphas <- c(rep(1, 2), rep(2, 6))
betas <- list(c(0), c(1), c(0, 0), c(1, 0), c(1, 1), c(2, 0), c(2, 1), c(2, 2))
seedSim <- function(seedNo, modelNo, globalalpha){
    net1 <- seedToNet(seed.no = seedNo, nnodes = 35, graph.prob = 0.15)
    gdpPred <- predict(GNARfit(vts = gdpVTSn[1:50, ], net = net1,
                               alphaOrder = alphas[modelNo], betaOrder = betas[[modelNo]],
                               globalalpha = globalalpha))
    return(sum((gdpPred - gdpVTSn[51, ])^2))
    }
%%R
seedSim(seedNo = seed.nos[1], modelNo = 1, globalalpha = TRUE)
[1] 23.36913
%%R
seedSim(seed.nos[1], modelNo = 3, globalalpha = TRUE)
[1] 11.50739
%%R
seedSim(seed.nos[1], modelNo = 3, globalalpha = FALSE)
[1] 18.96766

image.png
  • 10,000개의 임의의 네트워크와 16개의 모델로부터 시뮬레이션한 예측 오류의 박스 그래프
  • (계산 시간이 길어(90분) 코드는 생략).
  • 일반적으로 global-α 모델은 더 낮은 예측 오류를 일으킴.
  • 그래서 이 버전의 GNAR 모델을 사용할 것.
  • 그림 9에서 첫 번째 모델인 GNAR(1, [0])과 세 번째 모델인 GNAR(2, [0, 0])의 경우, “박스 그래프”는 인접한 매개변수가 적합되지 않아 결과가 전부 동일해 짧은 수평선으로 표시됨.
  • 다른 global-α 모델들은 이 안에 포함되어 있기 때문에, global-α GNAR(2, [2, 2])의 예측 오류가 최소가 되는 임의의 그래프를 선택할 것.
  • 이는 seed.nos[921]에서 생성된 네트워크가 선택되게 됩니다.
%%R
net921 <- seedToNet(seed.no = seed.nos[921], nnodes = 35, graph.prob = 0.15)
layout(matrix(c(1), 1, 1))
plot(net921, vertex.label = colnames(gdpVTS), vertex.size = 0)

Randomly generated un-weighted and un-directed graph over the OECD ountries that minimises the prediction error at t = 51 using GNAR(2, [2, 2]).

  • seed.nos[921]에서 생성된 네트워크
  • 네트워크에는 전부 2개 이상의 이웃을 가지고 있는 countries들이 있고, 총 97개의 edges이 있음.
  • 이 “921” 네트워크는 GDP 예측을 위해 생성되었기 때문에, 찾은 네트워크에 인식 가능한 구조가 있지 않을 것이라고 예상할 수 있음
  • 그러나 미국, 멕시코, 캐나다는 각각 8개, 8개, 6개의 edge을 가지고 있어 매우 잘 연결되어 있음.
  • 스웨덴과 칠레도 잘 연결되어 있으며, 각각 8개와 7개의 edge을 가지고 있습니다.
  • 예측 성능이 유사한 적은 개수의 edge를 가진 네트워크를 찾기 위해 테스트 될 수 있지만, 여기서는 전체 선택된 네트워크를 그대로 사용.
  • 이 네트워크를 사용하면 BIC를 이용해 최적의 GNAR 순서를 선택할 수 있음.
%%R
res <- rep(NA, 8)
for(i in 1:8){
    res[i] <- BIC(GNARfit(gdpVTSn[1:50, ],
                          net = seedToNet(seed.nos[921], nnodes = 35, graph.prob = 0.15),
                          alphaOrder = alphas[i], betaOrder = betas[[i]]))}
order(res)
[1] 6 3 4 7 8 5 1 2
%%R
sort(res)
[1] -64.44811 -64.32155 -64.18751 -64.12683 -64.09656 -63.86919 -60.67858
[8] -60.54207

4.2. Results and comparisons

  • 이전 섹션의 모델을 사용해 t=52일 때의 값을 예측
  • 이 예측 오류를 표준 AR과 VAR 모델을 사용해 찾은 예측 오류와 비교
  • GNAR 예측은 선택된 네트워크(seed.nos[921]에 해당)를 가진 GNAR(2, [2, 0]) 모델을 t=51까지의 데이터에 적합시키고, t=52일 때의 값을 예측
  • 우선 series를 정규화한 다음, 모델 적합으로부터 SSE를 계산합니다.
%%R
gdpVTSn2 <- apply(gdpVTS, 2, function(x){x / sd(x[1:51], na.rm = TRUE)})
gdpFit <- GNARfit(gdpVTSn2[1:51,], net = net921, alphaOrder = 2, betaOrder = c(2, 0))
summary(gdpFit)

Call:
lm(formula = yvec2 ~ dmat2 + 0)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.4806 -0.5491 -0.0121  0.5013  3.1208 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
dmat2alpha1  -0.41693    0.03154 -13.221  < 2e-16 ***
dmat2beta1.1 -0.12662    0.05464  -2.317   0.0206 *  
dmat2beta1.2  0.28044    0.06233   4.500  7.4e-06 ***
dmat2alpha2  -0.33282    0.02548 -13.064  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.8926 on 1332 degrees of freedom
  (23 observations deleted due to missingness)
Multiple R-squared:  0.1859,    Adjusted R-squared:  0.1834 
F-statistic: 76.02 on 4 and 1332 DF,  p-value: < 2.2e-16

GNAR BIC: -62.86003
%%R
sum((predict(gdpFit) - gdpVTSn2[52, ])^2)
[1] 5.737203

이 GNAR 모델의 적합된 매개변수는 \(\alpha^1 = - 0.42, \beta^1,1 = - 0.13, \beta^1,2 = 0.28\), 그리고 \(\alpha^2 = - 0.33\)입니다.

Model parameters prediction error
GNAR(2,[2,0]) 4 5.7
Individual AR(2) 38 8.1
VAR(1) 199 26.2

Estimated prediction error of differenced real GDP change at t = 52 for all 35 countries.

우리의 방법과 CRAN forecast 패키지의 버전 8.0에서의 forecast.ar()과 auto.arima() 함수를 사용해 각 노드별로 AR 모델을 적합한 결과를 비교

  • 섹션 4.1의 자기상관 분석을 고려해 각각 35개의 개별 모델의 최대 AR 순서를 p=2로 설정
%%R
library("forecast")
arforecast <- apply(gdpVTSn2[1:51, ], 2, function(x){
            forecast(auto.arima(x[!is.na(x)], d= ,D=0,max.p = 2,max.q=0,
                                max.P=0,max.Q = 0,stationary = TRUE, seasonal = FALSE), ic = "bic",
                     allowmean = FALSE, allowdraft = FALSE, trace = FALSE, h=1)$mean
})
sum((arforecast - gdpVTSn2[52, ])^2)
R[write to console]: Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
[1] 7.8974

We fit the model using the VAR function and then use the restrict function to reduce dimensionality further, by setting to zero any coefficient whose associated absolute t-statistic value is less than two.

%%R
library("vars")
gdpVTSn2.0 <- gdpVTSn2
gdpVTSn2.0[is.na(gdpVTSn2.0)] <- 0
varforecast <- predict(restrict(VAR(gdpVTSn2.0[1:51, ], p = 1, type = "none")), n.ahead = 1)

compute the prediction error

%%R
getfcst <- function(x){return(x[1])}
varforecastpt <- unlist(lapply(varforecast$fcst, getfcst))
sum((varforecastpt - gdpVTSn2.0[52, ])^2)
[1] 26.19805

GNAR 모델은 AR과 VAR 결과보다 적은 예측 오류를 제공합니다. 이는 AR과 비교했을 때 29%가 줄어들고, VAR과 비교했을 때 78%가 줄어듭니다.

위 절차를 반복해 2단계 앞으로의 예측을 기반으로 분석을 수행합니다.

이 경우 다른 네트워크가 GNAR(2,[2,2]) 모델의 예측 오류를 최소화합니다.

그러나 BIC 단계에서 GNAR(2,[0,0]) 모델이 최적으로 적합된 것을 식별하였고, 이는 네트워크 회귀 매개변수를 포함하지 않는 모델입니다.

%%R
library("vars")
gdpVTSn2.0 <- gdpVTSn2
gdpVTSn2.0[is.na(gdpVTSn2.0)] <- 0
varforecast <- predict(restrict(VAR(gdpVTSn2.0[1:51, ], p = 1, type = "none")), n.ahead = 40)