-
Notifications
You must be signed in to change notification settings - Fork 1
/
Global_characteristics.R
520 lines (419 loc) · 16.3 KB
/
Global_characteristics.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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
############################ Global Characteristics: CPI Inflation, log(EPU) and GPRC: BRIC ######################
# install.packages('entropy')
# Important 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)
################## Brazil ############################
setwd("/data/brazil")
getwd()
# Data
cpi.df <- read.csv("Brazil_CPI_inf_rate_Monthly_base_mulvar_cpi_epu_gprc_202201.csv",header=TRUE)
str(cpi.df)
# Calculate Coefficient of Variation and STDV
#calculate CV for each column in data frame
sapply(cpi.df[-1], function(x) sd(x) / mean(x) * 100)
#calculate STDV for each column in data frame
sapply(cpi.df[-1], function(x) sd(x))
# entropy(cpi.df$cpi_inflation_rate, method="MM")
sapply(cpi.df[-1], function(x) entropy(x, method="MM"))
# Find the Min-value, Max Value, Mean Value, Median Value, Q1-value, Q3-value
sapply(cpi.df[-1], function(x) min(x))
sapply(cpi.df[-1], function(x) max(x))
sapply(cpi.df[-1], function(x) mean(x))
sapply(cpi.df[-1], function(x) median(x))
sapply(cpi.df[-1], function(x) quantile(x, prob=c(.25,.5,.75), type=1))
# Check for Skewness
skewness(cpi.df$CPI_inflation_rate)
skewness(cpi.df$log_epu)
skewness(cpi.df$gprc_bra)
# Check for Kurtosis
kurtosis(cpi.df$CPI_inflation_rate)
kurtosis(cpi.df$log_epu)
kurtosis(cpi.df$gprc_bra)
# Test for Seasonality
isSeasonal(ts(cpi.df$CPI_inflation_rate), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$log_epu), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$gprc_bra), test = "combined", freq = 12)
#Tests for non-linearity
nonlinearityTest(ts(cpi.df$CPI_inflation_rate), verbose = TRUE) # Non -linear
nonlinearityTest(ts(cpi.df$log_epu), verbose = TRUE) # Non -linear
nonlinearityTest(ts(cpi.df$gprc_bra), verbose = TRUE) # Non -linear
# Check for Long-range dependence
hurstexp(cpi.df$CPI_inflation_rate)
hurstexp(cpi.df$log_epu)
hurstexp(cpi.df$gprc_bra)
#Test for Stationarity
kpss.test(cpi.df$CPI_inflation_rate) #Non-stationary
kpss.test(cpi.df$log_epu) #Non-stationary
kpss.test(cpi.df$gprc_bra) #Stationary
########################## 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)
time <- c(1:217)
library(car)
# CPI
test_out_cpi <- outlierTest(lm(CPI_brazil~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
# 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)
# 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)
############## Test for structural break-points: OLS - CUSUM ##############
# Identify the breakpoints
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
# Convert CPI inflation into a time series object
CPI_brazil <- ts(cpi.df$CPI_inflation_rate, start = 2003, end = 2021, frequency = 6)
CPI_brazil
length(CPI_brazil)
time <- c(1:109)
# Plot the Series
plot(CPI_brazil, type = "l", las = 1, xaxs = "i", xlab = "", ylab = "", col = "blue")
# Identify the breakpoints
length(CPI_brazil)
CPI_brazil_bp <- breakpoints(CPI_brazil ~ time, h = 7)
CPI_brazil_bp
# Check for the statistical significance of the break-points
coef(CPI_brazil_bp)
# Check for the statistical significance of the break-points
addi_CPI_BP <- efp(CPI_brazil ~ breakfactor(CPI_brazil_bp), type = "OLS-CUSUM")
plot(addi_CPI_BP)
################## Russia ############################
setwd("/dataset/russia")
getwd()
# Data
cpi.df <- read.csv("RUS_CPI_inf_rate_Monthly_mulvar_epu_gprc_202201.csv",header=TRUE)
str(cpi.df)
#calculate CV for each column in data frame
sapply(cpi.df[-1], function(x) sd(x) / mean(x) * 100)
# entropy(cpi.df$cpi_inflation_rate, method="MM")
sapply(cpi.df[-1], function(x) entropy(x, method="MM"))
# Find the Min-value, Max Value, Mean Value, Median Value, Q1-value, Q3-value
sapply(cpi.df[-1], function(x) min(x))
sapply(cpi.df[-1], function(x) max(x))
sapply(cpi.df[-1], function(x) mean(x))
sapply(cpi.df[-1], function(x) median(x))
sapply(cpi.df[-1], function(x) quantile(x, prob=c(.25,.5,.75), type=1))
# Check for Skewness
skewness(cpi.df$cpi_inflation_rate)
skewness(cpi.df$log_epu)
skewness(cpi.df$gprc_rus)
# Check for Kurtosis
kurtosis(cpi.df$cpi_inflation_rate)
kurtosis(cpi.df$log_epu)
kurtosis(cpi.df$gprc_rus)
# Test for Seasonality
isSeasonal(ts(cpi.df$cpi_inflation_rate), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$log_epu), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$gprc_rus), test = "combined", freq = 12)
#Tests for non-linearity
nonlinearityTest(ts(cpi.df$cpi_inflation_rate), verbose = TRUE) # Linear
nonlinearityTest(ts(cpi.df$log_epu), verbose = TRUE) # Non -linear
nonlinearityTest(ts(cpi.df$gprc_rus), verbose = TRUE) # Linear
# Check for Long-range dependence
hurstexp(cpi.df$cpi_inflation_rate)
hurstexp(cpi.df$log_epu)
hurstexp(cpi.df$gprc_rus)
#Test for Stationarity
kpss.test(cpi.df$cpi_inflation_rate) #Non-stationary
kpss.test(cpi.df$log_epu) #Non-stationary
kpss.test(cpi.df$gprc_rus) #Non-stationary
########################## Statistical Test for Outlier Detection ########################
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
CPI_russia <- ts(cpi.df$cpi_inflation_rate, start = 2003, end = 2021, frequency = 12)
CPI_russia
length(CPI_russia)
time <- c(1:217)
log_epu_russia <- ts(cpi.df$log_epu, start = 2003, end = 2021, frequency = 12)
log_epu_russia
length(log_epu_russia)
time <- c(1:217)
gprc_russia <- ts(cpi.df$gprc_rus, start = 2003, end = 2021, frequency = 12)
gprc_russia
length(gprc_russia)
time <- c(1:217)
library(car)
test_out_cpi <- outlierTest(lm(CPI_russia~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
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)
test_out_gprc <- outlierTest(lm(gprc_russia~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_gprc)
############## Test for structural break-points: OLS - CUSUM ##############
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
# Convert CPI inflation into a time series object
CPI_russia <- ts(cpi.df$cpi_inflation_rate, start = 2003, end = 2021, frequency = 6)
CPI_russia
length(CPI_russia)
time <- c(1:109)
# Plot the Series
plot(CPI_russia, type = "l", las = 1, xaxs = "i", xlab = "", ylab = "", col = "blue")
# Identify the breakpoints
length(CPI_russia)
CPI_russia_bp <- breakpoints(CPI_russia ~ time, h=7)
CPI_russia_bp
# Check for the statistical significance of the break-points
coef(CPI_russia_bp)
# Check for the statistical significance of the break-points
addi_CPI_BP <- efp(CPI_russia ~ breakfactor(CPI_russia_bp), type = "OLS-CUSUM")
plot(addi_CPI_BP)
################## India ############################
setwd("/dataset/india")
getwd()
# Data
cpi.df <- read.csv("India_CPI_inf_rate_Monthly_base_mulvar_cpi_epu_gprc_202201.csv",header=TRUE)
str(cpi.df)
#calculate CV for each column in data frame
sapply(cpi.df[-1], function(x) sd(x) / mean(x) * 100)
# entropy(cpi.df$cpi_inflation_rate, method="MM")
sapply(cpi.df[-1], function(x) entropy(x, method="MM"))
# Find the Min-value, Max Value, Mean Value, Median Value, Q1-value, Q3-value
sapply(cpi.df[-1], function(x) min(x))
sapply(cpi.df[-1], function(x) max(x))
sapply(cpi.df[-1], function(x) mean(x))
sapply(cpi.df[-1], function(x) median(x))
sapply(cpi.df[-1], function(x) quantile(x, prob=c(.25,.5,.75), type=1))
# Check for Skewness
skewness(cpi.df$CPI_inflation_Rate)
skewness(cpi.df$log_epu)
skewness(cpi.df$gprc_ind)
# Check for Kurtosis
kurtosis(cpi.df$CPI_inflation_Rate)
kurtosis(cpi.df$log_epu)
kurtosis(cpi.df$gprc_ind)
# Test for Seasonality
isSeasonal(ts(cpi.df$CPI_inflation_Rate), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$log_epu), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$gprc_ind), test = "combined", freq = 12)
#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
# Check for Long-range dependence
hurstexp(cpi.df$CPI_inflation_Rate)
hurstexp(cpi.df$log_epu)
hurstexp(cpi.df$gprc_ind)
#Test for Stationarity
kpss.test(cpi.df$CPI_inflation_Rate) #Non-stationary
kpss.test(cpi.df$log_epu) #Non-stationary
kpss.test(cpi.df$gprc_ind) #Non-stationary
########################## Statistical Test for Outlier Detection ########################
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$Date)
str(cpi.df)
# 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)
time <- c(1:217)
# Convert CPI inflation 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)
time <- c(1:217)
# Convert CPI inflation into a time series object
gprc_india <- ts(cpi.df$gprc_ind, start = 2003, end = 2021, frequency = 12)
gprc_india
length(gprc_india)
time <- c(1:217)
# Outlier Test using Bonferroni Outlier Test
test_out_cpi <- outlierTest(lm(CPI_india~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
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)
test_out_gprc <- outlierTest(lm(gprc_india~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_gprc)
############## Test for structural break-points: OLS - CUSUM ##############
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$Date)
str(cpi.df)
# Convert CPI inflation into a time series object
CPI_india <- ts(cpi.df$CPI_inflation_Rate, start = 2003, end = 2021, frequency = 6)
CPI_india
length(CPI_india)
time <- c(1:109)
# Plot the Series
plot(CPI_india, type = "l", las = 1, xaxs = "i", xlab = "", ylab = "", col = "blue")
# Identify the breakpoints
length(CPI_india)
CPI_india_bp <- breakpoints(CPI_india ~ time, h = 7)
CPI_india_bp
# Check for the statistical significance of the break-points
coef(CPI_india_bp)
# Check for the statistical significance of the break-points
addi_CPI_BP <- efp(CPI_india ~ breakfactor(CPI_india_bp), type = "OLS-CUSUM")
plot(addi_CPI_BP)
################## China ############################
setwd("/dataset/india")
getwd()
#calculate CV for each column in data frame
sapply(cpi.df[-1], function(x) sd(x) / mean(x) * 100)
# entropy(cpi.df$cpi_inflation_rate, method="MM")
sapply(cpi.df[-1], function(x) entropy(x, method="MM"))
# Find the Min-value, Max Value, Mean Value, Median Value, Q1-value, Q3-value
sapply(cpi.df[-1], function(x) min(x))
sapply(cpi.df[-1], function(x) max(x))
sapply(cpi.df[-1], function(x) mean(x))
sapply(cpi.df[-1], function(x) median(x))
sapply(cpi.df[-1], function(x) quantile(x, prob=c(.25,.5,.75), type=1))
# Data
cpi.df <- read.csv("China_CPI_inf_rate_Monthly_mulvariate_epu_gprc_202201.csv",header=TRUE)
str(cpi.df)
# Check for Skewness
skewness(cpi.df$cpi_inflation_rate)
skewness(cpi.df$log_scmp_epu)
skewness(cpi.df$gprc_chn)
# Check for Kurtosis
kurtosis(cpi.df$cpi_inflation_rate)
kurtosis(cpi.df$log_scmp_epu)
kurtosis(cpi.df$gprc_chn)
# Test for Seasonality
isSeasonal(ts(cpi.df$cpi_inflation_rate), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$log_scmp_epu), test = "combined", freq = 12)
isSeasonal(ts(cpi.df$gprc_chn), test = "combined", freq = 12)
#Tests for non-linearity
nonlinearityTest(ts(cpi.df$cpi_inflation_rate), verbose = TRUE) # Non - Linear (based on Keenan's test)
nonlinearityTest(ts(cpi.df$log_scmp_epu), verbose = TRUE) # Non - Linear (based on Tsay's test)
nonlinearityTest(ts(cpi.df$gprc_chn), verbose = TRUE) # Non - Linear (based on Tsay's test)
# Check for Long-range dependence
hurstexp(cpi.df$cpi_inflation_rate)
hurstexp(cpi.df$log_scmp_epu)
hurstexp(cpi.df$gprc_chn)
#Test for Stationarity
kpss.test(cpi.df$cpi_inflation_rate) #Stationary
kpss.test(cpi.df$log_scmp_epu) #Non-stationary
kpss.test(cpi.df$gprc_chn) #Non-stationary
########################## Statistical Test for Outlier Detection ########################
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
# 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)
time <- c(1:217)
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)
time <- c(1:217)
gprc_china <- ts(cpi.df$gprc_chn, start = 2003, end = 2021, frequency = 12)
gprc_china
length(gprc_china)
time <- c(1:217)
# Outlier Test using Bonferroni Outlier Test
library(car)
test_out_cpi <- outlierTest(lm(CPI_china~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_cpi)
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)
test_out_gprc <- outlierTest(lm(gprc_china~time,
cutoff=0.05,
n.max=10,
order=TRUE,
labels=names(rstudent)))
print(test_out_gprc)
############## Test for structural break-points: OLS - CUSUM ##############
# Convert Date into a numeric quantity
cpi.df$date_n <- as.numeric(cpi.df$date)
str(cpi.df)
# Convert CPI inflation into a time series object
CPI_china <- ts(cpi.df$cpi_inflation_rate, start = 2003, end = 2021, frequency = 6)
CPI_china
length(CPI_china)
time <- c(1:109)
# Plot the Series
plot(CPI_china, type = "l", las = 1, xaxs = "i", xlab = "", ylab = "", col = "blue")
# Identify the breakpoints
length(CPI_china)
CPI_china_bp <- breakpoints(CPI_china ~ time, h = 7)
CPI_china_bp
# Check for the statistical significance of the break-points
coef(CPI_china_bp)
# Check for the statistical significance of the break-points
addi_CPI_BP <- efp(CPI_china ~ breakfactor(CPI_china_bp), type = "OLS-CUSUM")
plot(addi_CPI_BP)
############################## End of Code #############################