Kết nối dữ liệu
setwd("d:/DATA2020/PaerScopus/Von_Quy_GDP")
library(readxl)
dulieu <-read_excel("data.ardl.1.xlsx")
#dulieu <-data.frame(dulieu)
head(dulieu)
## # A tibble: 6 x 20
## Imputation_ TT YEAR QUY Time GDP LnGDP TI IG LnIG IP
## <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 1 1994 Q1 1994~ 150039 11.9 19457. 3782. 8.24 1782.
## 2 1 2 1994 Q2 1994~ 187686 12.1 24339. 4731. 8.46 2229.
## 3 1 3 1994 Q3 1994~ 176760 12.1 22922. 4455. 8.40 2099.
## 4 1 4 1994 Q4 1994~ 213193 12.3 27647 5374. 8.59 2532.
## 5 1 5 1995 Q1 1995~ 163693 12.0 22688. 4251. 8.35 2639.
## 6 1 6 1995 Q2 1995~ 205576 12.2 28493. 5339. 8.58 3314.
## # ... with 9 more variables: LnIP <dbl>, IF <dbl>, LnIF <dbl>, CPI <dbl>,
## # OILP <dbl>, LCU <dbl>, LnLCU <dbl>, LAB <dbl>, LnLAB <dbl>
Vẽ nguồn Vốn
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(ggthemes)
dulieu %>% ggplot()+
geom_point(aes(x=Time, y=LnIG), color="red", size=3) +
geom_line(aes(x=Time, y=LnIG), color="red", size=2) +
geom_point(aes(x=Time, y=LnIP), color="green", size=3) +
geom_point(aes(x=Time, y=LnIF), color="blue", size=3) +
theme_minimal()
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

Định dạng thơi gian
library(zoo)
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
dulieu$thoigian <- as.yearqtr(dulieu$Time)
dulieu %>% ggplot()+
geom_point(aes(x=thoigian, y=LnIG), color="red", size=3) +
geom_line(aes(x=thoigian, y=LnIG), color="red", size=1) +
geom_point(aes(x=thoigian, y=LnIP), color="green", size=3) +
geom_line(aes(x=thoigian, y=LnIP), color="green", size=1) +
geom_point(aes(x=thoigian, y=LnIF), color="blue", size=3) +
geom_line(aes(x=thoigian, y=LnIF), color="blue", size=1) +
theme_minimal()

Vẽ đồ thị phụ thuộc
dulieu <- ts(dulieu, start=c(1995,1), frequency = 4 )
layGDP <-dulieu[,7]
head(layGDP)
## [1] 11.91865 12.14253 12.08255 12.26995 12.00575 12.23357
chuoiGDP <-ts(layGDP, start=c(1995,1), frequency=4)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(pastecs)
##
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
##
## first, last
Kiểm tra xu hướng
trend.test(dulieu, R=1)
## Warning in cor(rank(x), rank(y)): the standard deviation is zero
## Warning in cor.test.default(x[, i], Time, alternative = "two.sided", method =
## "spearman"): Cannot compute exact p-value with ties
## Warning in cor.test.default(x[, i], Time, alternative = "two.sided", method =
## "spearman"): Cannot compute exact p-value with ties
## Warning in cor.test.default(x[, i], Time, alternative = "two.sided", method =
## "spearman"): Cannot compute exact p-value with ties
## Warning in cor.test.default(x[, i], Time, alternative = "two.sided", method =
## "spearman"): Cannot compute exact p-value with ties
## $Imputation_
##
## Spearman's rank correlation rho
##
## data: Imputation_ and time(Imputation_)
## S = NA, p-value = NA
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## NA
##
##
## $TT
##
## Spearman's rank correlation rho
##
## data: TT and time(TT)
## S = 0, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 1
##
##
## $YEAR
##
## Spearman's rank correlation rho
##
## data: YEAR and time(YEAR)
## S = 130.05, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9993063
##
##
## $QUY
##
## Spearman's rank correlation rho
##
## data: QUY and time(QUY)
## S = 180479, p-value = 0.7074
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.03724195
##
##
## $Time
##
## Spearman's rank correlation rho
##
## data: Time and time(Time)
## S = 0, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 1
##
##
## $GDP
##
## Spearman's rank correlation rho
##
## data: GDP and time(GDP)
## S = 7554, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9597034
##
##
## $LnGDP
##
## Spearman's rank correlation rho
##
## data: LnGDP and time(LnGDP)
## S = 7554, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9597034
##
##
## $TI
##
## Spearman's rank correlation rho
##
## data: TI and time(TI)
## S = 4508, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9759522
##
##
## $IG
##
## Spearman's rank correlation rho
##
## data: IG and time(IG)
## S = 9178, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9510402
##
##
## $LnIG
##
## Spearman's rank correlation rho
##
## data: LnIG and time(LnIG)
## S = 9178, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9510402
##
##
## $IP
##
## Spearman's rank correlation rho
##
## data: IP and time(IP)
## S = 2288, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9877947
##
##
## $LnIP
##
## Spearman's rank correlation rho
##
## data: LnIP and time(LnIP)
## S = 2288, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9877947
##
##
## $IF
##
## Spearman's rank correlation rho
##
## data: IF and time(IF)
## S = 30064, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.8396245
##
##
## $LnIF
##
## Spearman's rank correlation rho
##
## data: LnIF and time(LnIF)
## S = 30064, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.8396245
##
##
## $CPI
##
## Spearman's rank correlation rho
##
## data: CPI and time(CPI)
## S = 186512, p-value = 0.9594
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.005057106
##
##
## $OILP
##
## Spearman's rank correlation rho
##
## data: OILP and time(OILP)
## S = 63548, p-value = 2.239e-14
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.6610032
##
##
## $LCU
##
## Spearman's rank correlation rho
##
## data: LCU and time(LCU)
## S = 344726, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.838931
##
##
## $LnLCU
##
## Spearman's rank correlation rho
##
## data: LnLCU and time(LnLCU)
## S = 344726, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.838931
##
##
## $LAB
##
## Spearman's rank correlation rho
##
## data: LAB and time(LAB)
## S = 860, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9954124
##
##
## $LnLAB
##
## Spearman's rank correlation rho
##
## data: LnLAB and time(LnLAB)
## S = 860, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9954124
##
##
## $thoigian
##
## Spearman's rank correlation rho
##
## data: thoigian and time(thoigian)
## S = 0, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 1
trend.test(chuoiGDP)
##
## Spearman's rank correlation rho
##
## data: chuoiGDP and time(chuoiGDP)
## S = 7554, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9597034
Kiểm tra tính mùa thời vụ
library(seastests)
summary(wo(dulieu))
## Warning in qs(y, freq = freq, diff = F, residuals = T): Could not estimate any
## ARIMA model, original series is used.
## Warning in kw(y, freq = freq, diff = F, residuals = T): Could not estimate any
## ARIMA model, original series is used.
## Test used: WO
##
## Test statistic: 1
## P-value: 0 0 0.5545544
##
## The WO - test identifies seasonality
summary(wo(chuoiGDP))
## Test used: WO
##
## Test statistic: 1
## P-value: 0 0 0
##
## The WO - test identifies seasonality
Phân tác mùa + xu hướng + ngẫu nhiên
tachGDP <- decompose(chuoiGDP)
tachGDP
## $x
## Qtr1 Qtr2 Qtr3 Qtr4
## 1995 11.91865 12.14253 12.08255 12.26995
## 1996 12.00575 12.23357 12.17370 12.36393
## 1997 12.08972 12.32019 12.26394 12.45849
## 1998 12.16055 12.39419 12.34513 12.54343
## 1999 12.21447 12.44946 12.40198 12.60077
## 2000 12.25925 12.49493 12.45017 12.64827
## 2001 12.32272 12.57529 12.50762 12.70953
## 2002 12.39648 12.63004 12.57644 12.77998
## 2003 12.46229 12.69552 12.65031 12.84821
## 2004 12.53156 12.76072 12.72775 12.91951
## 2005 12.60021 12.83010 12.80567 13.00119
## 2006 12.66292 12.89851 12.88502 13.07894
## 2007 12.72277 12.95904 12.95797 13.15258
## 2008 12.78393 13.02334 13.02896 13.22844
## 2009 12.85055 13.07353 13.08578 13.27858
## 2010 12.88272 13.11864 13.13762 13.35079
## 2011 12.93571 13.17506 13.20427 13.41985
## 2012 12.99204 13.23399 13.26698 13.48246
## 2013 13.03393 13.28117 13.32116 13.53985
## 2014 13.08175 13.32939 13.37504 13.59829
## 2015 13.13067 13.38215 13.43590 13.66372
## 2016 13.18925 13.44492 13.50031 13.73363
## 2017 13.24326 13.49904 13.56437 13.79896
## 2018 13.29324 13.56126 13.63671 13.87153
## 2019 13.36491 13.62884 13.70120 13.94166
## 2020 13.43133 13.69300 13.77184 14.01072
##
## $seasonal
## Qtr1 Qtr2 Qtr3 Qtr4
## 1995 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 1996 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 1997 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 1998 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 1999 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2000 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2001 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2002 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2003 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2004 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2005 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2006 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2007 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2008 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2009 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2010 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2011 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2012 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2013 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2014 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2015 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2016 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2017 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2018 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2019 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
## 2020 -0.2089310382 0.0156744781 0.0003665618 0.1928899983
##
## $trend
## Qtr1 Qtr2 Qtr3 Qtr4
## 1995 NA NA 12.11431 12.13657
## 1996 12.15935 12.18249 12.20473 12.22606
## 1997 12.24816 12.27126 12.29194 12.31004
## 1998 12.32944 12.35021 12.36756 12.38121
## 1999 12.39523 12.40951 12.42227 12.43355
## 2000 12.44526 12.45722 12.47109 12.48907
## 2001 12.50629 12.52113 12.53801 12.55407
## 2002 12.56952 12.58693 12.60396 12.62037
## 2003 12.63779 12.65555 12.67274 12.68955
## 2004 12.70738 12.72597 12.74347 12.76072
## 2005 12.77913 12.79908 12.81713 12.83352
## 2006 12.85199 12.87163 12.88883 12.90388
## 2007 12.92056 12.93889 12.95574 12.97142
## 2008 12.98833 13.00668 13.02449 13.03909
## 2009 13.05247 13.06584 13.07613 13.08579
## 2010 13.09791 13.11342 13.12906 13.14274
## 2011 13.15812 13.17509 13.19076 13.20517
## 2012 13.22037 13.23604 13.24910 13.26024
## 2013 13.27291 13.28685 13.30001 13.31201
## 2014 13.32477 13.33881 13.35223 13.36494
## 2015 13.37915 13.39493 13.41043 13.42560
## 2016 13.44150 13.45829 13.47378 13.48729
## 2017 13.50207 13.51824 13.53265 13.54668
## 2018 13.56350 13.58161 13.59964 13.61705
## 2019 13.63356 13.65039 13.66746 13.68378
## 2020 13.70063 13.71809 NA NA
##
## $random
## Qtr1 Qtr2 Qtr3 Qtr4
## 1995 NA NA -3.212495e-02 -5.951127e-02
## 1996 5.533006e-02 3.540600e-02 -3.140198e-02 -5.501293e-02
## 1997 5.048516e-02 3.324915e-02 -2.836712e-02 -4.444286e-02
## 1998 4.004413e-02 2.830566e-02 -2.280437e-02 -3.067277e-02
## 1999 2.817342e-02 2.428222e-02 -2.065247e-02 -2.566832e-02
## 2000 2.292583e-02 2.203603e-02 -2.128384e-02 -3.368858e-02
## 2001 2.535541e-02 3.848674e-02 -3.075784e-02 -3.743510e-02
## 2002 3.589219e-02 2.743468e-02 -2.788696e-02 -3.328097e-02
## 2003 3.342820e-02 2.429353e-02 -2.280083e-02 -3.422934e-02
## 2004 3.311420e-02 1.907181e-02 -1.608348e-02 -3.410210e-02
## 2005 3.001245e-02 1.534043e-02 -1.182388e-02 -2.522460e-02
## 2006 1.985621e-02 1.121281e-02 -4.178773e-03 -1.782687e-02
## 2007 1.114405e-02 4.475681e-03 1.871760e-03 -1.172590e-02
## 2008 4.529224e-03 9.826584e-04 4.096041e-03 -3.545415e-03
## 2009 7.006040e-03 -7.985188e-03 9.283632e-03 -9.925928e-05
## 2010 -6.261788e-03 -1.045365e-02 8.192871e-03 1.515609e-02
## 2011 -1.348759e-02 -1.570393e-02 1.314161e-02 2.178757e-02
## 2012 -1.940746e-02 -1.772359e-02 1.750954e-02 2.933059e-02
## 2013 -3.004242e-02 -2.135997e-02 2.078602e-02 3.495202e-02
## 2014 -3.409200e-02 -2.509520e-02 2.244200e-02 4.045300e-02
## 2015 -3.954291e-02 -2.845393e-02 2.510448e-02 4.522398e-02
## 2016 -4.331676e-02 -2.904561e-02 2.616907e-02 5.344156e-02
## 2017 -4.987328e-02 -3.487937e-02 3.134780e-02 5.939556e-02
## 2018 -6.133147e-02 -3.602883e-02 3.670005e-02 6.158816e-02
## 2019 -5.971755e-02 -3.722150e-02 3.337901e-02 6.499518e-02
## 2020 -6.036594e-02 -4.076924e-02 NA NA
##
## $figure
## [1] -0.2089310382 0.0156744781 0.0003665618 0.1928899983
##
## $type
## [1] "additive"
##
## attr(,"class")
## [1] "decomposed.ts"
plot(tachGDP)

Vẽ đồ thị khi set data là TS
dulieu <- dulieu[,c(7,10,12,14,15,18,20)]
dulieu <-ts(dulieu,star=c(1995,1), frequency = 4)
head(dulieu)
## LnGDP LnIG LnIP LnIF CPI LnLCU LnLAB
## 1995 Q1 11.91865 8.237955 7.485379 9.539184 15.578648 4.064736 10.37810
## 1995 Q2 12.14253 8.461828 7.709219 9.763058 3.317664 4.352023 10.38342
## 1995 Q3 12.08255 8.401850 7.649264 9.703077 16.415442 4.086260 10.39223
## 1995 Q4 12.26995 8.589253 7.836646 9.890488 15.224859 4.180401 10.38293
## 1996 Q1 12.00575 8.354957 7.878004 9.667645 7.400000 4.070183 10.40073
## 1996 Q2 12.23357 8.582775 8.105851 9.895465 11.000000 4.030183 10.40570
library(ggfortify)
## Registered S3 methods overwritten by 'ggfortify':
## method from
## autoplot.Arima forecast
## autoplot.acf forecast
## autoplot.ar forecast
## autoplot.bats forecast
## autoplot.decomposed.ts forecast
## autoplot.ets forecast
## autoplot.forecast forecast
## autoplot.stl forecast
## autoplot.ts forecast
## fitted.ar forecast
## fortify.ts forecast
## residuals.ar forecast
autoplot(dulieu, facets = FALSE)

# Vẽ luôn đồ thị phân tách
autoplot(tachGDP)
## Warning: attributes are not identical across measure variables;
## they will be dropped
## Warning: Removed 8 row(s) containing missing values (geom_path).

Kiểm tra tính ổn định của dữ liệu
library(urca)
summary(ur.df(dulieu[,1], type=c("none")))
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.38035 -0.11198 0.06425 0.14913 0.26032
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 0.002301 0.001447 1.590 0.115
## z.diff.lag -0.674002 0.074119 -9.094 9.59e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1888 on 100 degrees of freedom
## Multiple R-squared: 0.4548, Adjusted R-squared: 0.4439
## F-statistic: 41.71 on 2 and 100 DF, p-value: 6.712e-14
##
##
## Value of test-statistic is: 1.5901
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(ur.pp(dulieu[,1], type=c("Z-tau"),model=c("constant")))
##
## ##################################
## # Phillips-Perron Unit Root Test #
## ##################################
##
## Test regression with intercept
##
##
## Call:
## lm(formula = y ~ y.l1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.4145 -0.1772 0.1004 0.1896 0.3266
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.69535 0.63776 2.658 0.00913 **
## y.l1 0.87053 0.04926 17.672 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2463 on 101 degrees of freedom
## Multiple R-squared: 0.7556, Adjusted R-squared: 0.7532
## F-statistic: 312.3 on 1 and 101 DF, p-value: < 2.2e-16
##
##
## Value of test-statistic, type: Z-tau is: -1.9275
##
## aux. Z statistics
## Z-tau-mu 1.9716
##
## Critical values for Z statistics:
## 1pct 5pct 10pct
## critical values -3.4945 -2.889471 -2.581483
summary(ur.ers(dulieu[,1], type=c("DF-GLS"), model=c("constant")))
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type DF-GLS
## detrending of series with intercept
##
##
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.024354 -0.002629 0.000815 0.003810 0.024583
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## yd.lag 0.001735 0.001605 1.081 0.2825
## yd.diff.lag1 -0.028456 0.019425 -1.465 0.1463
## yd.diff.lag2 -0.043912 0.019091 -2.300 0.0237 *
## yd.diff.lag3 -0.032075 0.019041 -1.685 0.0954 .
## yd.diff.lag4 0.993909 0.018847 52.736 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.008015 on 94 degrees of freedom
## Multiple R-squared: 0.9991, Adjusted R-squared: 0.999
## F-statistic: 1.999e+04 on 5 and 94 DF, p-value: < 2.2e-16
##
##
## Value of test-statistic is: 1.0809
##
## Critical values of DF-GLS are:
## 1pct 5pct 10pct
## critical values -2.59 -1.94 -1.62
summary(ur.kpss(dulieu[,1], type=c("mu")))
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 4 lags.
##
## Value of test-statistic is: 2.1836
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739