suppressMessages(library(tidyverse))
suppressMessages(library(fpp2))
suppressMessages(library(psych))
suppressMessages(library(BMA))
suppressMessages(library(GGally))

setwd("C:/Users/DellPC/Desktop")


df <- read.csv("a.csv") %>% select (-1)

Phan tich thong ke mo ta

describe(df)
##        vars  n  mean   sd median trimmed  mad   min   max range  skew kurtosis
## Ln_FDI    1 30  7.98 1.27   7.95    7.93 1.10  5.54 11.02  5.48  0.32    -0.08
## Ln_GDP    2 30 11.68 1.40  11.64   11.64 1.54  9.48 14.82  5.34  0.20    -0.67
## Ln_Tr     3 30 23.56 1.52  23.27   23.45 1.91 21.48 26.71  5.24  0.43    -0.89
## Ln_Pc     4 30  6.88 0.82   7.20    6.92 0.84  4.80  8.23  3.43 -0.55    -0.43
## Ln_Wgr    5 30  3.84 0.44   3.92    3.89 0.31  2.66  4.44  1.78 -1.05     0.37
## Opn       6 30  0.72 0.41   0.59    0.68 0.35  0.11  2.08  1.97  1.21     1.68
##          se
## Ln_FDI 0.23
## Ln_GDP 0.26
## Ln_Tr  0.28
## Ln_Pc  0.15
## Ln_Wgr 0.08
## Opn    0.08

Correlation giua cac bien

ggpairs(df)

Hoi quy tuyen tinh

model <-  lm(Ln_FDI ~ Ln_GDP  + Ln_Pc + Ln_Tr+ Ln_Wgr + Opn, data = df)

summary(model)
## 
## Call:
## lm(formula = Ln_FDI ~ Ln_GDP + Ln_Pc + Ln_Tr + Ln_Wgr + Opn, 
##     data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.4933 -0.3918  0.1294  0.4723  1.1476 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -2.98254    2.53819  -1.175  0.25149   
## Ln_GDP       0.77235    0.22623   3.414  0.00228 **
## Ln_Pc        0.31268    0.24699   1.266  0.21768   
## Ln_Tr        0.03367    0.18208   0.185  0.85483   
## Ln_Wgr      -0.46473    0.44079  -1.054  0.30223   
## Opn          1.07810    0.42439   2.540  0.01796 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7095 on 24 degrees of freedom
## Multiple R-squared:  0.7427, Adjusted R-squared:  0.6891 
## F-statistic: 13.86 on 5 and 24 DF,  p-value: 2.031e-06

Kiem tra gia thuyet cua mo hinh

checkresiduals(model)

## 
##  Breusch-Godfrey test for serial correlation of order up to 9
## 
## data:  Residuals
## LM test = 4.5722, df = 9, p-value = 0.8699

Sau khi chay mo hinh thi mo hinh chi co 2 bien thoa man duoc dieu kien cua hoi quy tuyen tinh

Chon mo hinh dua vao chi so BIC (Bayensian Information Criteria)

xvars <- df[,-1]
y= df[,1]

md <- bicreg(xvars, y, strict = FALSE, OR=20)

summary(md)
## 
## Call:
## bicreg(x = xvars, y = y, strict = FALSE, OR = 20)
## 
## 
##   5  models were selected
##  Best  5  models (cumulative posterior probability =  1 ): 
## 
##            p!=0    EV       SD       model 1    model 2    model 3    model 4  
## Intercept  100.0  -2.98006  1.57458   -2.95565   -3.50264   -2.73312   -2.81323
## Ln_GDP     100.0   0.85452  0.12044    0.85883    0.83642    0.85951    0.87267
## Ln_Tr       10.7  -0.00143  0.05805      .          .          .       -0.01334
## Ln_Pc       19.8   0.03378  0.11323      .        0.12347      .          .    
## Ln_Wgr      16.1  -0.02975  0.17014      .          .       -0.06020      .    
## Opn        100.0   1.23057  0.35552    1.24358    1.18806    1.24495    1.25762
##                                                                                
## nVar                                     2          3          3          3    
## r2                                     0.725      0.731      0.726      0.725  
## BIC                                  -31.93695  -29.16654  -28.58162  -28.54230
## post prob                              0.585      0.146      0.109      0.107  
##            model 5  
## Intercept   -2.64363
## Ln_GDP       0.80870
## Ln_Tr          .    
## Ln_Pc        0.30395
## Ln_Wgr      -0.44869
## Opn          1.11712
##                     
## nVar           4    
## r2           0.742  
## BIC        -27.08097
## post prob    0.052

Chon model 5 la vi BIC lon nhat

model <-  lm(Ln_FDI ~ Ln_GDP  + Ln_Pc + Ln_Wgr + Opn, data = df)

summary(model)
## 
## Call:
## lm(formula = Ln_FDI ~ Ln_GDP + Ln_Pc + Ln_Wgr + Opn, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.4667 -0.4321  0.1216  0.4884  1.1699 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -2.6436     1.7219  -1.535  0.13728    
## Ln_GDP        0.8087     0.1099   7.360 1.04e-07 ***
## Ln_Pc         0.3040     0.2377   1.279  0.21276    
## Ln_Wgr       -0.4487     0.4237  -1.059  0.29977    
## Opn           1.1171     0.3611   3.094  0.00481 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6956 on 25 degrees of freedom
## Multiple R-squared:  0.7424, Adjusted R-squared:  0.7011 
## F-statistic: 18.01 on 4 and 25 DF,  p-value: 4.462e-07