Tải dữ liệu

library(thongke.club)
library(ARDL)
## To cite ARDL in publications use:
##         
## Kleanthis Natsiopoulos and Nickolaos G. Tzeremes (2022). "ARDL bounds test for cointegration: Replicating the Pesaran et al. (2001) results for the UK earnings equation using R", Journal of Applied Econometrics, https://doi.org/10.1002/jae.2919
dulieu <-price_tom 
congthuc <- price_ao ~ price_bs + price_bl + price_xk 

Chạy ARDL tự động

#selection= c("AIC", "BIC", "AICc","adjr2" )
ardl1 <-auto_ardl(congthuc, data=dulieu, max_order = c(5,5,5,5),selection= c("BIC")) 
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
summary(ardl1)
##            Length Class      Mode   
## best_model 19     dynlm      list   
## best_order  4     -none-     numeric
## top_orders  5     data.frame list
ardl1
## $best_model
## 
## Time series regression with "ts" data:
## Start = 6, End = 120
## 
## Call:
## dynlm::dynlm(formula = full_formula, data = data, start = start, 
##     end = end)
## 
## Coefficients:
##    (Intercept)  L(price_ao, 1)  L(price_ao, 2)        price_bs  L(price_bs, 1)  
##      -76.58368        -0.04204        -0.09847         0.30270         0.19370  
## L(price_bs, 2)  L(price_bs, 3)  L(price_bs, 4)  L(price_bs, 5)        price_bl  
##        0.17677         0.12297         0.08797         0.04712         0.42834  
##       price_xk  
##        0.23728  
## 
## 
## $best_order
## [1] 2 5 0 0
## 
## $top_orders
##    price_ao price_bs price_bl price_xk      BIC
## 1         2        5        0        0 965.5527
## 2         1        0        4        0 967.6895
## 3         3        5        0        0 969.6228
## 4         2        4        0        0 971.5067
## 5         1        0        3        0 971.8280
## 6         4        5        0        0 972.1971
## 7         3        5        0        1 974.2118
## 8         2        4        0        1 976.1974
## 9         3        5        1        1 976.4438
## 10        1        0        2        0 976.5124
## 11        4        5        0        1 976.8185
## 12        2        4        1        1 978.3387
## 13        4        5        1        1 979.1185
## 14        3        5        1        2 980.1457
## 15        1        0        2        1 981.2324
## 16        4        5        1        2 983.0739
## 17        1        0        1        1 983.6634
## 18        2        3        1        1 984.5490
## 19        3        5        2        2 984.8886
## 20        1        1        1        1 987.4583
ardl(congthuc, data = dulieu,order = c(2,5,0,0)) -> ardl
ardl
## 
## Time series regression with "ts" data:
## Start = 6, End = 120
## 
## Call:
## dynlm::dynlm(formula = full_formula, data = data, start = start, 
##     end = end)
## 
## Coefficients:
##    (Intercept)  L(price_ao, 1)  L(price_ao, 2)        price_bs  L(price_bs, 1)  
##      -76.58368        -0.04204        -0.09847         0.30270         0.19370  
## L(price_bs, 2)  L(price_bs, 3)  L(price_bs, 4)  L(price_bs, 5)        price_bl  
##        0.17677         0.12297         0.08797         0.04712         0.42834  
##       price_xk  
##        0.23728

bound test

bounds_f_test(ardl, case=3)
## 
##  Bounds F-test (Wald) for no cointegration
## 
## data:  d(price_ao) ~ L(price_ao, 1) + L(price_bs, 1) + price_bl + price_xk +     d(L(price_ao, 1)) + d(price_bs) + d(L(price_bs, 1)) + d(L(price_bs,     2)) + d(L(price_bs, 3)) + d(L(price_bs, 4))
## F = 41.738, p-value = 1e-06
## alternative hypothesis: Possible cointegration
## null values:
##    k    T 
##    3 1000
bounds_t_test(ardl, case=3)
## 
##  Bounds t-test for no cointegration
## 
## data:  d(price_ao) ~ L(price_ao, 1) + L(price_bs, 1) + price_bl + price_xk +     d(L(price_ao, 1)) + d(price_bs) + d(L(price_bs, 1)) + d(L(price_bs,     2)) + d(L(price_bs, 3)) + d(L(price_bs, 4))
## t = -10.021, p-value = 1e-06
## alternative hypothesis: Possible cointegration
## null values:
##    k    T 
##    3 1000

Chạy ecm

uecm <- uecm(ardl)
test_uecm <- coint_eq(ardl, case = 3)
uecm
## 
## Time series regression with "ts" data:
## Start = 6, End = 120
## 
## Call:
## dynlm::dynlm(formula = full_formula, data = data, start = start, 
##     end = end)
## 
## Coefficients:
##       (Intercept)     L(price_ao, 1)     L(price_bs, 1)           price_bl  
##         -76.58368           -1.14051            0.93123            0.42834  
##          price_xk  d(L(price_ao, 1))        d(price_bs)  d(L(price_bs, 1))  
##           0.23728            0.09847            0.30270           -0.43483  
## d(L(price_bs, 2))  d(L(price_bs, 3))  d(L(price_bs, 4))  
##          -0.25806           -0.13509           -0.04712
test_uecm
## Time Series:
## Start = 1 
## End = 120 
## Frequency = 1 
##   [1] 190.8860 177.3682 188.4052 193.9411 194.5844 208.8365 172.2587 172.8222
##   [9] 173.4908 200.1070 173.7778 189.6741 198.2611 219.5198 149.1361 229.1037
##  [17] 174.8324 177.5419 176.3296 183.3783 194.9989 191.8913 184.6823 189.5414
##  [25] 202.3547 199.9677 209.0626 181.7841 191.6557 178.7234 186.2274 221.3612
##  [33] 155.8907 175.8835 191.8611 164.1312 204.3546 196.6395 159.1661 201.1632
##  [41] 179.2377 201.2858 176.8442 191.5800 188.0995 170.3731 181.9554 190.1695
##  [49] 195.3025 165.3101 181.3960 201.9514 200.5667 190.8221 187.4082 192.3597
##  [57] 218.3346 161.7268 165.8582 183.3392 195.7406 188.8800 196.3417 184.5986
##  [65] 179.6557 177.4961 173.7753 144.8594 176.3267 208.3872 181.7908 178.7688
##  [73] 194.2332 230.3587 179.3313 177.1179 203.4092 201.1103 170.8859 184.0245
##  [81] 190.1425 159.9984 184.6896 209.4148 182.2945 178.5414 198.7696 189.7750
##  [89] 176.0991 201.8097 229.7183 188.8647 184.9583 178.8372 184.4277 175.4632
##  [97] 187.4996 192.4856 193.8966 193.6097 190.9970 168.3758 185.1100 164.9908
## [105] 190.1759 198.0514 204.8728 183.0856 195.1142 177.2096 182.9091 169.8852
## [113] 174.2327 197.0704 163.4608 162.2401 174.2365 189.4988 224.4326 203.8004
#recm <- recm(ardl)
#test_recm <- coint_eq(ardl, case = 3)

Test sau khi chạy ardl

library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
bgtest(ardl)
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  ardl
## LM test = 3.0008, df = 1, p-value = 0.08322
bptest(ardl)
## 
##  studentized Breusch-Pagan test
## 
## data:  ardl
## BP = 16.448, df = 10, p-value = 0.08751
dwtest(ardl)
## 
##  Durbin-Watson test
## 
## data:  ardl
## DW = 2.1541, p-value = 0.7938
## alternative hypothesis: true autocorrelation is greater than 0
raintest(ardl) # test cho tuyến tính
## 
##  Rainbow test
## 
## data:  ardl
## Rain = 0.92874, df1 = 58, df2 = 46, p-value = 0.6082
resettest(ardl)
## 
##  RESET test
## 
## data:  ardl
## RESET = 1.0232, df1 = 2, df2 = 102, p-value = 0.3631