-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTable_02_Global_Characteristics_BRIC_FEWNet.R
431 lines (361 loc) · 16.4 KB
/
Table_02_Global_Characteristics_BRIC_FEWNet.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
################### Table 02: Global Characteristics - BRIC ###############
set.seed(20240101) # For reproducibility, we are using this seed value
# Load the necessary libraries
library(nonlinearTseries)
library(tseries)
library(forecast)
library(Metrics)
library(ggplot2)
library(readr)
library(WaveletArima)
library(caret)
library(nnfor)
library(tsDyn)
library(fracdiff)
library(bsts)
library(forecastHybrid)
library(e1071)
library(tseriesChaos)
library(pracma)
library(Kendall)
library(GeneCycle)
library(fpp2)
library(seastests)
library(entropy)
library(zoo)
library(sandwich)
library(strucchange)
library(tseries)
library(car)
################## Brazil ############################
# Set the working directory
setwd("/FEWNet/dataset/brazil")
getwd()
# Data
cpi.df <- read.csv("Brazil_CPI_inf_rate_Monthly_base_mulvar_cpi_epu_gprc_202201.csv",header=TRUE)
# Check
str(cpi.df) # Obs.: 227 for CPI Inflation, log(EPU) and GPRC Series
# Check for Skewness
skewness(cpi.df$CPI_inflation_rate) # reported values are rounded off to 2-decimal points
skewness(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
skewness(cpi.df$gprc_bra) # reported values are rounded off to 2-decimal points
# Check for Kurtosis
kurtosis(cpi.df$CPI_inflation_rate) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$gprc_bra) # reported values are rounded off to 2-decimal points
# Test for Seasonality
isSeasonal(ts(cpi.df$CPI_inflation_rate), test = "combined", freq = 12) # Non-Seasonal
isSeasonal(ts(cpi.df$log_epu), test = "combined", freq = 12) # Non-Seasonal
isSeasonal(ts(cpi.df$gprc_bra), test = "combined", freq = 12) # Non-Seasonal
#Tests for non-linearity
nonlinearityTest(ts(cpi.df$CPI_inflation_rate), verbose = TRUE) # Non -linear (Tsay's Test for nonlinearity)
nonlinearityTest(ts(cpi.df$log_epu), verbose = TRUE) # Non -linear (Tsay's Test for nonlinearity)
nonlinearityTest(ts(cpi.df$gprc_bra), verbose = TRUE) # Non -linear (Tsay's Test for nonlinearity)
# Check for Long-range dependence
hurstexp(cpi.df$CPI_inflation_rate) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation:0.725967
hurstexp(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.7665957
hurstexp(cpi.df$gprc_bra) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation:0.6274421
#Test for Stationarity
kpss.test(cpi.df$CPI_inflation_rate) #Non-stationary
# KPSS Level = 0.52913, Truncation lag parameter = 4, p-value = 0.03511
kpss.test(cpi.df$log_epu) #Non-stationary
# KPSS Level = 2.1582, Truncation lag parameter = 4, p-value = 0.01
kpss.test(cpi.df$gprc_bra) #Stationary
# KPSS Level = 0.15529, Truncation lag parameter = 4, p-value = 0.1
########################## Statistical Test for Outlier Detection ########################
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
CPI_brazil <- ts(cpi.df$CPI_inflation_rate, start = 2003, end = 2021, frequency = 12)
CPI_brazil
length(CPI_brazil)
log_epu_brazil <- ts(cpi.df$log_epu, start = 2003, end = 2021, frequency = 12)
log_epu_brazil
length(log_epu_brazil)
gprc_bra_brazil <- ts(cpi.df$gprc_bra, start = 2003, end = 2021, frequency = 12)
gprc_bra_brazil
length(gprc_bra_brazil)
# Create a time variable (monotonic sequence)
time <- c(1:217)
# CPI
test_out_cpi <- outlierTest(lm(CPI_brazil~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
# No Studentized residuals with Bonferroni p < 0.05
# log(EPU)
test_out_epu <- outlierTest(lm(log_epu_brazil~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_epu)
# 1 Outlier detected
# rstudent unadjusted p-value Bonferroni p
# 94 -3.944132 0.00010855 0.023555
# GPRC
test_out_gprc <- outlierTest(lm(gprc_bra_brazil~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_gprc)
# 4 Outliers detected
# rstudent unadjusted p-value Bonferroni p
# 89 5.732367 3.3413e-08 7.2507e-06
# 194 5.028396 1.0447e-06 2.2670e-04
# 193 3.998130 8.7894e-05 1.9073e-02
# 90 3.986227 9.2097e-05 1.9985e-02
################## Russia ############################
# Set the working directory
setwd("/FEWNet/dataset/russia")
getwd()
# Data
cpi.df <- read.csv("RUS_CPI_inf_rate_Monthly_mulvar_epu_gprc_202201.csv",header=TRUE)
# Check
str(cpi.df)
# Check for Skewness
skewness(cpi.df$cpi_inflation_rate) # reported values are rounded off to 2-decimal points
skewness(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
skewness(cpi.df$gprc_rus) # reported values are rounded off to 2-decimal points
# Check for Kurtosis
kurtosis(cpi.df$cpi_inflation_rate) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$gprc_rus) # reported values are rounded off to 2-decimal points
# Test for Seasonality
isSeasonal(ts(cpi.df$cpi_inflation_rate), test = "combined", freq = 12) # Non-Seasonal
isSeasonal(ts(cpi.df$log_epu), test = "combined", freq = 12) # Non-Seasonal
isSeasonal(ts(cpi.df$gprc_rus), test = "combined", freq = 12) # Non-Seasonal
#Tests for non-linearity
nonlinearityTest(ts(cpi.df$cpi_inflation_rate), verbose = TRUE) # Linear
nonlinearityTest(ts(cpi.df$log_epu), verbose = TRUE) # Non -linear (Tsay's Test for nonlinearity)
nonlinearityTest(ts(cpi.df$gprc_rus), verbose = TRUE) # Linear
# Check for Long-range dependence
hurstexp(cpi.df$cpi_inflation_rate) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.7828272
hurstexp(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.7939474
hurstexp(cpi.df$gprc_rus) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.7847786
#Test for Stationarity
kpss.test(cpi.df$cpi_inflation_rate) #Non-stationary
# KPSS Level = 2.1281, Truncation lag parameter = 4, p-value = 0.01
kpss.test(cpi.df$log_epu) #Non-stationary
# KPSS Level = 3.4507, Truncation lag parameter = 4, p-value = 0.01
kpss.test(cpi.df$gprc_rus) #Non-stationary
# KPSS Level = 1.4805, Truncation lag parameter = 4, p-value = 0.01
########################## Statistical Test for Outlier Detection ########################
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
# Create a time variable (monotonic sequence)
time <- c(1:217)
# CPI
CPI_russia <- ts(cpi.df$cpi_inflation_rate, start = 2003, end = 2021, frequency = 12)
CPI_russia
length(CPI_russia)
# log(EPU)
log_epu_russia <- ts(cpi.df$log_epu, start = 2003, end = 2021, frequency = 12)
log_epu_russia
length(log_epu_russia)
# GPRC
gprc_russia <- ts(cpi.df$gprc_rus, start = 2003, end = 2021, frequency = 12)
gprc_russia
length(gprc_russia)
# Oulier Test: CPI
test_out_cpi <- outlierTest(lm(CPI_russia~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
# No Studentized residuals with Bonferroni p < 0.05
# Oulier Test: log(EPU)
test_out_log_epu <- outlierTest(lm(log_epu_russia~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_log_epu)
# No Studentized residuals with Bonferroni p < 0.05
# Oulier Test: GPRC
test_out_gprc <- outlierTest(lm(gprc_russia~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_gprc)
# 2 Outliers detected
# rstudent unadjusted p-value Bonferroni p
# 135 5.240300 3.8328e-07 8.3172e-05
# 3 4.013253 8.2817e-05 1.7971e-02
################## India ############################
# Set the working directory
setwd("/FEWNet/dataset/india")
getwd()
# Data
cpi.df <- read.csv("India_CPI_inf_rate_Monthly_base_mulvar_cpi_epu_gprc_202201.csv",header=TRUE)
# # Check
str(cpi.df)
# Check for Skewness
skewness(cpi.df$CPI_inflation_Rate) # reported values are rounded off to 2-decimal points
skewness(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
skewness(cpi.df$gprc_ind) # reported values are rounded off to 2-decimal points
# Check for Kurtosis
kurtosis(cpi.df$CPI_inflation_Rate) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$gprc_ind) # reported values are rounded off to 2-decimal points
# Test for Seasonality
isSeasonal(ts(cpi.df$CPI_inflation_Rate), test = "combined", freq = 12) # Non - Sesonal
isSeasonal(ts(cpi.df$log_epu), test = "combined", freq = 12) # Non - Sesonal
isSeasonal(ts(cpi.df$gprc_ind), test = "combined", freq = 12) # Non - Sesonal
#Tests for non-linearity
nonlinearityTest(ts(cpi.df$CPI_inflation_Rate), verbose = TRUE) # Linear
nonlinearityTest(ts(cpi.df$log_epu), verbose = TRUE) # Linear
nonlinearityTest(ts(cpi.df$gprc_ind), verbose = TRUE) # Non - Linear (Tsay's Test for nonlinearity)
# Check for Long-range dependence
hurstexp(cpi.df$CPI_inflation_Rate) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.818633
hurstexp(cpi.df$log_epu) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.797259
hurstexp(cpi.df$gprc_ind) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.7253037
#Test for Stationarity
kpss.test(cpi.df$CPI_inflation_Rate) #Non-stationary
# KPSS Level = 0.71808, Truncation lag parameter = 4, p-value = 0.0119
kpss.test(cpi.df$log_epu) #Non-stationary
# KPSS Level = 0.62445, Truncation lag parameter = 4, p-value = 0.02041
kpss.test(cpi.df$gprc_ind) #Non-stationary
# KPSS Level = 1.1869, Truncation lag parameter = 4, p-value = 0.01
########################## Statistical Test for Outlier Detection ########################
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$Date)
str(cpi.df)
# Create a time variable (monotonic sequence)
time <- c(1:217)
# Convert CPI inflation into a time series object
CPI_india <- ts(cpi.df$CPI_inflation_Rate, start = 2003, end = 2021, frequency = 12)
CPI_india
length(CPI_india)
# Convert log(EPU) into a time series object
log_epu_india <- ts(cpi.df$log_epu, start = 2003, end = 2021, frequency = 12)
log_epu_india
length(log_epu_india)
# Convert GPRC into a time series object
gprc_india <- ts(cpi.df$gprc_ind, start = 2003, end = 2021, frequency = 12)
gprc_india
length(gprc_india)
# Outlier Test using Bonferroni Outlier Test: CPI
test_out_cpi <- outlierTest(lm(CPI_india~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
# No Studentized residuals with Bonferroni p < 0.05
# Outlier Test using Bonferroni Outlier Test: log(EPU)
test_out_log_epu <- outlierTest(lm(log_epu_india~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_log_epu)
# No Studentized residuals with Bonferroni p < 0.05
# Outlier Test using Bonferroni Outlier Test: GPRC
test_out_gprc <- outlierTest(lm(gprc_india~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_gprc)
# One outlier detected
# rstudent unadjusted p-value Bonferroni p
# 72 9.768904 7.098e-19 1.5403e-16
################## China ############################
# Set the working directory
setwd("/FEWNet/dataset/china")
getwd()
# Data
cpi.df <- read.csv("China_CPI_inf_rate_Monthly_mulvariate_epu_gprc_202201.csv",header=TRUE)
# Check
str(cpi.df)
# Check for Skewness
skewness(cpi.df$cpi_inflation_rate) # reported values are rounded off to 2-decimal points
skewness(cpi.df$log_scmp_epu) # reported values are rounded off to 2-decimal points
skewness(cpi.df$gprc_chn) # reported values are rounded off to 2-decimal points
# Check for Kurtosis
kurtosis(cpi.df$cpi_inflation_rate) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$log_scmp_epu) # reported values are rounded off to 2-decimal points
kurtosis(cpi.df$gprc_chn) # reported values are rounded off to 2-decimal points
# Test for Seasonality
isSeasonal(ts(cpi.df$cpi_inflation_rate), test = "combined", freq = 12) # Non - Sesonal
isSeasonal(ts(cpi.df$log_scmp_epu), test = "combined", freq = 12) # Non - Sesonal
isSeasonal(ts(cpi.df$gprc_chn), test = "combined", freq = 12) # Non - Sesonal
#Tests for non-linearity
nonlinearityTest(ts(cpi.df$cpi_inflation_rate), verbose = TRUE) # Non - Linear (based on Keenan's one-degree test for nonlinearity)
nonlinearityTest(ts(cpi.df$log_scmp_epu), verbose = TRUE) # Non - Linear (based on Tsay's Test for nonlinearity)
nonlinearityTest(ts(cpi.df$gprc_chn), verbose = TRUE) # Non - Linear (based on Tsay's Test for nonlinearity)
# Check for Long-range dependence
hurstexp(cpi.df$cpi_inflation_rate) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.6881485
hurstexp(cpi.df$log_scmp_epu) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.8194812
hurstexp(cpi.df$gprc_chn) # reported values are rounded off to 2-decimal points
# Simple R/S Hurst estimation: 0.7955109
#Test for Stationarity
kpss.test(cpi.df$cpi_inflation_rate) #Stationary
# KPSS Level = 0.26837, Truncation lag parameter = 4, p-value = 0.1
kpss.test(cpi.df$log_scmp_epu) #Non-stationary
# KPSS Level = 3.3998, Truncation lag parameter = 4, p-value = 0.01
kpss.test(cpi.df$gprc_chn) #Non-stationary
# KPSS Level = 1.8759, Truncation lag parameter = 4, p-value = 0.01
########################## Statistical Test for Outlier Detection ###################
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
# Create a time variable (monotonic sequence)
time <- c(1:217)
# Convert CPI inflation into a time series object
CPI_china <- ts(cpi.df$cpi_inflation_rate, start = 2003, end = 2021, frequency = 12)
CPI_china
length(CPI_china)
# Convert log(EPU) into a time series object
log_scmp_epu_china <- ts(cpi.df$log_scmp_epu, start = 2003, end = 2021, frequency = 12)
log_scmp_epu_china
length(log_scmp_epu_china)
# Convert GPRC into a time series object
gprc_china <- ts(cpi.df$gprc_chn, start = 2003, end = 2021, frequency = 12)
gprc_china
length(gprc_china)
# Outlier Test using Bonferroni Outlier Test: CPI
test_out_cpi <- outlierTest(lm(CPI_china~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
# No Studentized residuals with Bonferroni p < 0.05
# Outlier Test using Bonferroni Outlier Test: log(PEU)
test_out_log_epu <- outlierTest(lm(log_scmp_epu_china~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_log_epu)
# No Studentized residuals with Bonferroni p < 0.05
# Outlier Test using Bonferroni Outlier Test: GPRC
test_out_gprc <- outlierTest(lm(gprc_china~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_gprc)
# One outlier detected
# rstudent unadjusted p-value Bonferroni p
# 185 4.075311 6.476e-05 0.014053
################## End Of Code ############################