Phương sai sai số thay đổi: Kiểm tra và khắc phục

A, Kết nối data

library(readxl)
setwd("d:/DATA2021/ThuySan.VECM/data5.5.21")
solieu <-read_excel("data.ca.5.5.21.xlsx")

congthuc1 <-LnGDP ~ LnFEX + LnLAB + REER + LnOPEN + LnFDI
congthuc3 <-LnFGDP ~ LnFEX + LnLAB + REER + LnOPEN + LnFDI
lm(data=solieu,congthuc1) -> hoiquy1

library(dynlm)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
hoiquy2 <-dynlm(data=solieu,congthuc1)

summary(hoiquy1)
## 
## Call:
## lm(formula = congthuc1, data = solieu)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.210940 -0.058072  0.003733  0.039472  0.269841 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 23.35330    4.89950   4.766 9.14e-06 ***
## LnFEX        0.40039    0.06716   5.962 7.86e-08 ***
## LnLAB       -2.96920    0.63490  -4.677 1.28e-05 ***
## REER        -1.00061    0.53801  -1.860  0.06688 .  
## LnOPEN       0.53708    0.08649   6.210 2.81e-08 ***
## LnFDI        0.13661    0.04067   3.359  0.00124 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09556 on 74 degrees of freedom
## Multiple R-squared:  0.9455, Adjusted R-squared:  0.9418 
## F-statistic: 256.6 on 5 and 74 DF,  p-value: < 2.2e-16
summary(hoiquy2)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 80
## 
## Call:
## dynlm(formula = congthuc1, data = solieu)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.210940 -0.058072  0.003733  0.039472  0.269841 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 23.35330    4.89950   4.766 9.14e-06 ***
## LnFEX        0.40039    0.06716   5.962 7.86e-08 ***
## LnLAB       -2.96920    0.63490  -4.677 1.28e-05 ***
## REER        -1.00061    0.53801  -1.860  0.06688 .  
## LnOPEN       0.53708    0.08649   6.210 2.81e-08 ***
## LnFDI        0.13661    0.04067   3.359  0.00124 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09556 on 74 degrees of freedom
## Multiple R-squared:  0.9455, Adjusted R-squared:  0.9418 
## F-statistic: 256.6 on 5 and 74 DF,  p-value: < 2.2e-16

B, Kiểm định

1. The Breusch-Pagan Test

library(lmtest)
bptest(hoiquy1)
## 
##  studentized Breusch-Pagan test
## 
## data:  hoiquy1
## BP = 11.791, df = 5, p-value = 0.03776
bptest(hoiquy2)
## 
##  studentized Breusch-Pagan test
## 
## data:  hoiquy2
## BP = 11.791, df = 5, p-value = 0.03776
library("skedastic") # Không hỗ trợ dynlm
## Warning: package 'skedastic' was built under R version 4.0.5
breusch_pagan(hoiquy1)
## # A tibble: 1 x 5
##   statistic p.value parameter method                alternative
##       <dbl>   <dbl>     <dbl> <chr>                 <chr>      
## 1      11.8  0.0378         5 Koenker (studentised) greater
library(car)
## Loading required package: carData
ncvTest(hoiquy1)
## Non-constant Variance Score Test 
## Variance formula: ~ fitted.values 
## Chisquare = 14.97445, Df = 1, p = 0.00010898
library("olsrr")
## Warning: package 'olsrr' was built under R version 4.0.5
## 
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
## 
##     rivers
ols_test_breusch_pagan(hoiquy1)
## 
##  Breusch Pagan Test for Heteroskedasticity
##  -----------------------------------------
##  Ho: the variance is constant            
##  Ha: the variance is not constant        
## 
##               Data                
##  ---------------------------------
##  Response : LnGDP 
##  Variables: fitted values of LnGDP 
## 
##          Test Summary           
##  -------------------------------
##  DF            =    1 
##  Chi2          =    14.97445 
##  Prob > Chi2   =    0.0001089765
ols_test_breusch_pagan(hoiquy1, rhs = TRUE, multiple = TRUE)
## 
##  Breusch Pagan Test for Heteroskedasticity
##  -----------------------------------------
##  Ho: the variance is constant            
##  Ha: the variance is not constant        
## 
##                   Data                   
##  ----------------------------------------
##  Response : LnGDP 
##  Variables: LnFEX LnLAB REER LnOPEN LnFDI 
## 
##           Test Summary (Unadjusted p values)          
##  ---------------------------------------------------
##   Variable            chi2        df         p       
##  ---------------------------------------------------
##   LnFEX            13.05466741     1    0.0003025296 
##   LnLAB            10.40351041     1    0.0012577598 
##   REER              0.05259098     1    0.8186145835 
##   LnOPEN           12.48558439     1    0.0004101044 
##   LnFDI             8.83139845     1    0.0029609140 
##  ---------------------------------------------------
##   simultaneous     16.12819970     5    0.0064874316 
##  ---------------------------------------------------

2. Goldfeld-Quandt Test

gqtest(hoiquy2)
## 
##  Goldfeld-Quandt test
## 
## data:  hoiquy2
## GQ = 2.8686, df1 = 34, df2 = 34, p-value = 0.001423
## alternative hypothesis: variance increases from segment 1 to 2
goldfeld_quandt(hoiquy1)
## # A tibble: 1 x 5
##   statistic       p.value parameter method                 alternative
##       <dbl>         <dbl>     <int> <chr>                  <chr>      
## 1      17.5 0.00000000619        20 Goldfeld-Quandt F Test greater

3. Vẽ đồ thị

hetplot(hoiquy1)

4. White test

white_lm(hoiquy1)
## # A tibble: 1 x 5
##   statistic p.value parameter method       alternative
##       <dbl>   <dbl>     <dbl> <chr>        <chr>      
## 1      20.2  0.0271        10 White's Test greater
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

B Xem đồ thị

plot(hoiquy1)

C, Khác phục

1. Khắc phục Box-Cox transformation

library(caret)
## Warning: package 'caret' was built under R version 4.0.5
## Loading required package: lattice
## Loading required package: ggplot2
head(solieu)
## # A tibble: 6 x 9
##     STT QUY    LnGDP LnFGDP LnFEX LnLAB  REER LnOPEN LnFDI
##   <dbl> <chr>  <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>
## 1     1 2000q1  12.3   7.20  19.5  10.6 0.996   22.6  10.3
## 2     2 2000q2  12.6   7.46  19.8  10.6 1.00    22.7  10.6
## 3     3 2000q3  12.5   7.39  19.7  10.6 1.01    22.7  10.5
## 4     4 2000q4  12.7   7.59  19.9  10.6 1.01    22.9  10.7
## 5     5 2001q1  12.4   7.32  19.7  10.6 0.993   22.6  10.5
## 6     6 2001q2  12.6   7.55  20.0  10.6 0.999   22.8  10.7
bienchon <-solieu[,3]
bieny <-data.frame(bienchon)


preProcess(bieny, method=c("BoxCox")) -> biendoi
biendoi
## Created from 80 samples and 1 variables
## 
## Pre-processing:
##   - Box-Cox transformation (1)
##   - ignored (0)
## 
## Lambda estimates for Box-Cox transformation:
## -0.3
bienphuthuoc <- predict(biendoi,bieny) # thực hiện box-cox dữ liệu
head(bienphuthuoc)
##      LnGDP
## 1 1.764175
## 2 1.773697
## 3 1.771170
## 4 1.778657
## 5 1.766982
## 6 1.775728
solieu2 <-cbind(solieu,bienphuthuoc)
head(solieu2)
##   STT    QUY    LnGDP   LnFGDP    LnFEX    LnLAB      REER   LnOPEN    LnFDI
## 1   1 2000q1 12.32272 7.204922 19.51234 10.55482 0.9962832 22.62871 10.34393
## 2   2 2000q2 12.57529 7.457496 19.76492 10.56007 0.9997200 22.73124 10.59650
## 3   3 2000q3 12.50762 7.389821 19.69724 10.56939 1.0071360 22.71304 10.52882
## 4   4 2000q4 12.70953 7.591730 19.89915 10.55959 1.0072360 22.87906 10.73074
## 5   5 2001q1 12.39648 7.320969 19.72526 10.58206 0.9931406 22.57954 10.45481
## 6   6 2001q2 12.63004 7.554526 19.95881 10.58733 0.9989467 22.81070 10.68836
##      LnGDP
## 1 1.764175
## 2 1.773697
## 3 1.771170
## 4 1.778657
## 5 1.766982
## 6 1.775728
library(tidyverse)
## -- Attaching packages ---------------------------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.1     v dplyr   1.0.0
## v tidyr   1.1.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## v purrr   0.3.4
## -- Conflicts ------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## x purrr::lift()   masks caret::lift()
## x dplyr::recode() masks car::recode()
## x purrr::some()   masks car::some()
solieu3 <- solieu2 %>% select(1,2,4,5,6,7,8,9,10 )
head(solieu3)
##   STT    QUY   LnFGDP    LnFEX    LnLAB      REER   LnOPEN    LnFDI    LnGDP
## 1   1 2000q1 7.204922 19.51234 10.55482 0.9962832 22.62871 10.34393 1.764175
## 2   2 2000q2 7.457496 19.76492 10.56007 0.9997200 22.73124 10.59650 1.773697
## 3   3 2000q3 7.389821 19.69724 10.56939 1.0071360 22.71304 10.52882 1.771170
## 4   4 2000q4 7.591730 19.89915 10.55959 1.0072360 22.87906 10.73074 1.778657
## 5   5 2001q1 7.320969 19.72526 10.58206 0.9931406 22.57954 10.45481 1.766982
## 6   6 2001q2 7.554526 19.95881 10.58733 0.9989467 22.81070 10.68836 1.775728
hoiquy3 <-lm(data=solieu3,congthuc1)
summary(hoiquy3)
## 
## Call:
## lm(formula = congthuc1, data = solieu3)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0074671 -0.0019219  0.0001459  0.0014695  0.0086881 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.142708   0.165537  12.944  < 2e-16 ***
## LnFEX        0.014001   0.002269   6.171 3.30e-08 ***
## LnLAB       -0.103910   0.021451  -4.844 6.80e-06 ***
## REER        -0.029255   0.018177  -1.609 0.111785    
## LnOPEN       0.018810   0.002922   6.437 1.08e-08 ***
## LnFDI        0.005002   0.001374   3.640 0.000502 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.003229 on 74 degrees of freedom
## Multiple R-squared:  0.9496, Adjusted R-squared:  0.9462 
## F-statistic: 278.6 on 5 and 74 DF,  p-value: < 2.2e-16
bptest(hoiquy3)
## 
##  studentized Breusch-Pagan test
## 
## data:  hoiquy3
## BP = 10.565, df = 5, p-value = 0.06071
### Cách 2 #################################################################
bienchon2 <- BoxCoxTrans(solieu$LnGDP)
bienchon2
## Box-Cox Transformation
## 
## 80 data points used to estimate Lambda
## 
## Input data summary:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   12.32   12.84   13.13   13.14   13.43   14.01 
## 
## Largest/Smallest: 1.14 
## Sample Skewness: 0.0712 
## 
## Estimated Lambda: -0.3
solieu4 <- cbind(solieu, LnGDP2 = predict(bienchon2, solieu$LnGDP))
head(solieu4)
##   STT    QUY    LnGDP   LnFGDP    LnFEX    LnLAB      REER   LnOPEN    LnFDI
## 1   1 2000q1 12.32272 7.204922 19.51234 10.55482 0.9962832 22.62871 10.34393
## 2   2 2000q2 12.57529 7.457496 19.76492 10.56007 0.9997200 22.73124 10.59650
## 3   3 2000q3 12.50762 7.389821 19.69724 10.56939 1.0071360 22.71304 10.52882
## 4   4 2000q4 12.70953 7.591730 19.89915 10.55959 1.0072360 22.87906 10.73074
## 5   5 2001q1 12.39648 7.320969 19.72526 10.58206 0.9931406 22.57954 10.45481
## 6   6 2001q2 12.63004 7.554526 19.95881 10.58733 0.9989467 22.81070 10.68836
##     LnGDP2
## 1 1.764175
## 2 1.773697
## 3 1.771170
## 4 1.778657
## 5 1.766982
## 6 1.775728
congthuc4 <-LnGDP2 ~ LnFEX + LnLAB + REER + LnOPEN + LnFDI
hoiquy4 <-dynlm(data=solieu4,congthuc4)
summary(hoiquy4)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 80
## 
## Call:
## dynlm(formula = congthuc4, data = solieu4)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0074671 -0.0019219  0.0001459  0.0014695  0.0086881 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.142708   0.165537  12.944  < 2e-16 ***
## LnFEX        0.014001   0.002269   6.171 3.30e-08 ***
## LnLAB       -0.103910   0.021451  -4.844 6.80e-06 ***
## REER        -0.029255   0.018177  -1.609 0.111785    
## LnOPEN       0.018810   0.002922   6.437 1.08e-08 ***
## LnFDI        0.005002   0.001374   3.640 0.000502 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.003229 on 74 degrees of freedom
## Multiple R-squared:  0.9496, Adjusted R-squared:  0.9462 
## F-statistic: 278.6 on 5 and 74 DF,  p-value: < 2.2e-16
bptest(hoiquy4)
## 
##  studentized Breusch-Pagan test
## 
## data:  hoiquy4
## BP = 10.565, df = 5, p-value = 0.06071

2. khắc phục bằng robust

summary(hoiquy1)
## 
## Call:
## lm(formula = congthuc1, data = solieu)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.210940 -0.058072  0.003733  0.039472  0.269841 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 23.35330    4.89950   4.766 9.14e-06 ***
## LnFEX        0.40039    0.06716   5.962 7.86e-08 ***
## LnLAB       -2.96920    0.63490  -4.677 1.28e-05 ***
## REER        -1.00061    0.53801  -1.860  0.06688 .  
## LnOPEN       0.53708    0.08649   6.210 2.81e-08 ***
## LnFDI        0.13661    0.04067   3.359  0.00124 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09556 on 74 degrees of freedom
## Multiple R-squared:  0.9455, Adjusted R-squared:  0.9418 
## F-statistic: 256.6 on 5 and 74 DF,  p-value: < 2.2e-16
summary(hoiquy1, robust=T)
## 
## Call:
## lm(formula = congthuc1, data = solieu)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.210940 -0.058072  0.003733  0.039472  0.269841 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 23.35330    4.89950   4.766 9.14e-06 ***
## LnFEX        0.40039    0.06716   5.962 7.86e-08 ***
## LnLAB       -2.96920    0.63490  -4.677 1.28e-05 ***
## REER        -1.00061    0.53801  -1.860  0.06688 .  
## LnOPEN       0.53708    0.08649   6.210 2.81e-08 ***
## LnFDI        0.13661    0.04067   3.359  0.00124 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09556 on 74 degrees of freedom
## Multiple R-squared:  0.9455, Adjusted R-squared:  0.9418 
## F-statistic: 256.6 on 5 and 74 DF,  p-value: < 2.2e-16
library(car)

cov1 <- hccm(hoiquy1, type="hc1")
cov1
##             (Intercept)        LnFEX       LnLAB         REER       LnOPEN
## (Intercept)  13.7880633 -0.116129774 -1.72876101  0.427427298  0.233685284
## LnFEX        -0.1161298  0.005632093  0.00886418 -0.005583130 -0.002824423
## LnLAB        -1.7287610  0.008864180  0.22706023 -0.075715962 -0.028978684
## REER          0.4274273 -0.005583130 -0.07571596  0.250218844  0.011091491
## LnOPEN        0.2336853 -0.002824423 -0.02897868  0.011091491  0.004576206
## LnFDI         0.1012366 -0.001863764 -0.01086540 -0.001899852  0.001307476
##                    LnFDI
## (Intercept)  0.101236556
## LnFEX       -0.001863764
## LnLAB       -0.010865404
## REER        -0.001899852
## LnOPEN       0.001307476
## LnFDI        0.002163586
LnGDP.HC1 <- coeftest(hoiquy1, vcov.=cov1)
LnGDP.HC1
## 
## t test of coefficients:
## 
##              Estimate Std. Error t value  Pr(>|t|)    
## (Intercept) 23.353300   3.713228  6.2892 2.013e-08 ***
## LnFEX        0.400395   0.075047  5.3352 1.001e-06 ***
## LnLAB       -2.969203   0.476508 -6.2312 2.567e-08 ***
## REER        -1.000614   0.500219 -2.0004  0.049132 *  
## LnOPEN       0.537083   0.067648  7.9394 1.686e-11 ***
## LnFDI        0.136611   0.046514  2.9370  0.004416 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

3. khắc phục bằng sandwich

library(sandwich)
vcovHC(hoiquy1)
##             (Intercept)        LnFEX       LnLAB         REER       LnOPEN
## (Intercept)  15.3632332 -0.134615834 -1.91582601  0.441320957  0.261040666
## LnFEX        -0.1346158  0.006355764  0.01041341 -0.005616570 -0.003244032
## LnLAB        -1.9158260  0.010413415  0.25038317 -0.079780326 -0.032175479
## REER          0.4413210 -0.005616570 -0.07978033  0.274083077  0.011749735
## LnOPEN        0.2610407 -0.003244032 -0.03217548  0.011749735  0.005120680
## LnFDI         0.1141484 -0.002121524 -0.01217130 -0.002780107  0.001475815
##                    LnFDI
## (Intercept)  0.114148447
## LnFEX       -0.002121524
## LnLAB       -0.012171302
## REER        -0.002780107
## LnOPEN       0.001475815
## LnFDI        0.002455086
vcovHC(hoiquy2)
##             (Intercept)        LnFEX       LnLAB         REER       LnOPEN
## (Intercept)  15.3632332 -0.134615834 -1.91582601  0.441320957  0.261040666
## LnFEX        -0.1346158  0.006355764  0.01041341 -0.005616570 -0.003244032
## LnLAB        -1.9158260  0.010413415  0.25038317 -0.079780326 -0.032175479
## REER          0.4413210 -0.005616570 -0.07978033  0.274083077  0.011749735
## LnOPEN        0.2610407 -0.003244032 -0.03217548  0.011749735  0.005120680
## LnFDI         0.1141484 -0.002121524 -0.01217130 -0.002780107  0.001475815
##                    LnFDI
## (Intercept)  0.114148447
## LnFEX       -0.002121524
## LnLAB       -0.012171302
## REER        -0.002780107
## LnOPEN       0.001475815
## LnFDI        0.002455086
coeftest(hoiquy1, vcov = vcovHC(hoiquy1, type = "HC1"))
## 
## t test of coefficients:
## 
##              Estimate Std. Error t value  Pr(>|t|)    
## (Intercept) 23.353300   3.713228  6.2892 2.013e-08 ***
## LnFEX        0.400395   0.075047  5.3352 1.001e-06 ***
## LnLAB       -2.969203   0.476508 -6.2312 2.567e-08 ***
## REER        -1.000614   0.500219 -2.0004  0.049132 *  
## LnOPEN       0.537083   0.067648  7.9394 1.686e-11 ***
## LnFDI        0.136611   0.046514  2.9370  0.004416 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(hoiquy1, vcov = vcovHC(hoiquy1, type = "HC2"))
## 
## t test of coefficients:
## 
##              Estimate Std. Error t value  Pr(>|t|)    
## (Intercept) 23.353300   3.740536  6.2433 2.440e-08 ***
## LnFEX        0.400395   0.075845  5.2791 1.251e-06 ***
## LnLAB       -2.969203   0.478765 -6.2018 2.902e-08 ***
## REER        -1.000614   0.501729 -1.9943  0.049800 *  
## LnOPEN       0.537083   0.068219  7.8729 2.252e-11 ***
## LnFDI        0.136611   0.047074  2.9021  0.004881 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(hoiquy1, vcov = vcovHC(hoiquy1, type = "HC3"))
## 
## t test of coefficients:
## 
##              Estimate Std. Error t value  Pr(>|t|)    
## (Intercept) 23.353300   3.919596  5.9581 7.992e-08 ***
## LnFEX        0.400395   0.079723  5.0223 3.425e-06 ***
## LnLAB       -2.969203   0.500383 -5.9339 8.833e-08 ***
## REER        -1.000614   0.523529 -1.9113  0.059841 .  
## LnOPEN       0.537083   0.071559  7.5055 1.110e-10 ***
## LnFDI        0.136611   0.049549  2.7571  0.007341 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(hoiquy1, vcov = vcovHC(hoiquy1, type = "HC4"))
## 
## t test of coefficients:
## 
##              Estimate Std. Error t value  Pr(>|t|)    
## (Intercept) 23.353300   3.794109  6.1551 3.527e-08 ***
## LnFEX        0.400395   0.077144  5.1903 1.777e-06 ***
## LnLAB       -2.969203   0.484092 -6.1336 3.859e-08 ***
## REER        -1.000614   0.506806 -1.9744  0.052074 .  
## LnOPEN       0.537083   0.069250  7.7557 3.748e-11 ***
## LnFDI        0.136611   0.047979  2.8473  0.005703 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

D, Giải pháp

d1. Robust Standard Error (Heteroskedasticity-consistent standard errors)

vcovHC(hoiquy1, type = 'HC')
##             (Intercept)        LnFEX        LnLAB         REER       LnOPEN
## (Intercept) 12.75395854 -0.107420041 -1.599103936  0.395370250  0.216158887
## LnFEX       -0.10742004  0.005209686  0.008199366 -0.005164395 -0.002612591
## LnLAB       -1.59910394  0.008199366  0.210030711 -0.070037265 -0.026805283
## REER         0.39537025 -0.005164395 -0.070037265  0.231452431  0.010259629
## LnOPEN       0.21615889 -0.002612591 -0.026805283  0.010259629  0.004232990
## LnFDI        0.09364381 -0.001723981 -0.010050499 -0.001757363  0.001209415
##                    LnFDI
## (Intercept)  0.093643814
## LnFEX       -0.001723981
## LnLAB       -0.010050499
## REER        -0.001757363
## LnOPEN       0.001209415
## LnFDI        0.002001317
coeftest(hoiquy1, vcov = vcovHC(hoiquy1, type = "HC1"))
## 
## t test of coefficients:
## 
##              Estimate Std. Error t value  Pr(>|t|)    
## (Intercept) 23.353300   3.713228  6.2892 2.013e-08 ***
## LnFEX        0.400395   0.075047  5.3352 1.001e-06 ***
## LnLAB       -2.969203   0.476508 -6.2312 2.567e-08 ***
## REER        -1.000614   0.500219 -2.0004  0.049132 *  
## LnOPEN       0.537083   0.067648  7.9394 1.686e-11 ***
## LnFDI        0.136611   0.046514  2.9370  0.004416 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

d2. Feasible GLS (FGLS)

fgls <- lm(congthuc1, data  = solieu, weights = 1/hoiquy1$fitted.values^2)
summary(fgls)
## 
## Call:
## lm(formula = congthuc1, data = solieu, weights = 1/hoiquy1$fitted.values^2)
## 
## Weighted Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0162096 -0.0041682  0.0002274  0.0029887  0.0197952 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 23.25310    4.74814   4.897 5.55e-06 ***
## LnFEX        0.40036    0.06634   6.035 5.81e-08 ***
## LnLAB       -2.95468    0.61552  -4.800 8.04e-06 ***
## REER        -0.98182    0.52661  -1.864  0.06623 .  
## LnOPEN       0.53439    0.08402   6.360 1.49e-08 ***
## LnFDI        0.13575    0.04083   3.324  0.00138 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007149 on 74 degrees of freedom
## Multiple R-squared:  0.9475, Adjusted R-squared:  0.944 
## F-statistic: 267.3 on 5 and 74 DF,  p-value: < 2.2e-16
vcov(fgls)
##             (Intercept)        LnFEX        LnLAB         REER        LnOPEN
## (Intercept)  22.5448231 -0.120047962 -2.886118286  0.981459258  0.3761833716
## LnFEX        -0.1200480  0.004400907  0.011272805 -0.009065692 -0.0029335778
## LnLAB        -2.8861183  0.011272805  0.378865846 -0.150377699 -0.0483803847
## REER          0.9814593 -0.009065692 -0.150377699  0.277315613  0.0235673297
## LnOPEN        0.3761834 -0.002933578 -0.048380385  0.023567330  0.0070595694
## LnFDI         0.0811786 -0.001030762 -0.009174869 -0.002570730  0.0009340571
##                     LnFDI
## (Intercept)  0.0811785981
## LnFEX       -0.0010307620
## LnLAB       -0.0091748688
## REER        -0.0025707304
## LnOPEN       0.0009340571
## LnFDI        0.0016673445
bptest(fgls)
## 
##  studentized Breusch-Pagan test
## 
## data:  fgls
## BP = 11.791, df = 5, p-value = 0.03776