research0626

####################################################
## 1. 載入套件與讀取資料
####################################################

# 第一次使用才需要安裝
# install.packages("readxl")

library(readxl)

# 讀取 Excel
data <- read_excel("research0626.xlsx")

# 查看欄位名稱
names(data)
 [1] "Country"             "Year"                "Political stability"
 [4] "FSI(100-FSI)"      "Democracy"           "Post2022"           
 [7] "SCS"                 "Trade China"         "Sec us"             
[10] "Strategic Ambiguity" "Dis unga idealpoint"
# 查看資料型態
str(data)
tibble [80 × 11] (S3: tbl_df/tbl/data.frame)
 $ Country            : chr [1:80] "Philippines" "Philippines" "Philippines" "Philippines" ...
 $ Year               : num [1:80] 2014 2015 2016 2017 2018 ...
 $ Political stability: num [1:80] 52.1 50.1 41.4 44 47.7 ...
 $ FSI(100-FSI)     : num [1:80] 14.7 13.8 15.3 15.6 14.5 16.9 19 17.6 19.5 22.2 ...
 $ Democracy          : num [1:80] 6.77 6.84 6.94 6.71 6.71 6.64 7.02 6.62 5.93 6.37 ...
 $ Post2022           : num [1:80] 0 0 0 0 0 0 0 0 1 1 ...
 $ SCS                : num [1:80] 1 1 1 1 1 1 1 1 1 1 ...
 $ Trade China        : num [1:80] 0.0616 0.0583 0.0694 0.0807 0.0902 ...
 $ Sec us             : num [1:80] 0.74 0.818 0.851 0.766 0.634 0.716 0.825 0.886 0.649 0.742 ...
 $ Strategic Ambiguity: chr [1:80] "NA" "NA" "NA" "NA" ...
 $ Dis unga idealpoint: num [1:80] 2.64 3.03 2.54 2.9 2.72 ...
# 查看摘要統計
summary(data)
   Country               Year      Political stability FSI(100-FSI) 
 Length:80          Min.   :2014   Min.   :41.43       Min.   :11.50  
 Class :character   1st Qu.:2016   1st Qu.:55.73       1st Qu.:19.48  
 Mode  :character   Median :2018   Median :65.30       Median :27.20  
                    Mean   :2018   Mean   :64.52       Mean   :30.96  
                    3rd Qu.:2021   3rd Qu.:70.21       3rd Qu.:34.45  
                    Max.   :2023   Max.   :89.57       Max.   :74.50  
   Democracy        Post2022        SCS       Trade China         Sec us      
 Min.   :1.770   Min.   :0.0   Min.   :0.0   Min.   :0.0511   Min.   :0.0700  
 1st Qu.:3.160   1st Qu.:0.0   1st Qu.:0.0   1st Qu.:0.1014   1st Qu.:0.5373  
 Median :6.160   Median :0.0   Median :0.5   Median :0.2074   Median :0.6495  
 Mean   :5.135   Mean   :0.2   Mean   :0.5   Mean   :0.2176   Mean   :0.6316  
 3rd Qu.:6.647   3rd Qu.:0.0   3rd Qu.:1.0   3rd Qu.:0.2843   3rd Qu.:0.7370  
 Max.   :7.300   Max.   :1.0   Max.   :1.0   Max.   :0.4523   Max.   :0.8940  
 Strategic Ambiguity Dis unga idealpoint
 Length:80           Min.   :1.038      
 Class :character    1st Qu.:2.397      
 Mode  :character    Median :2.832      
                     Mean   :2.683      
                     3rd Qu.:3.154      
                     Max.   :3.492      
####################################################
## 2. 資料整理
####################################################

# 將文字 NA 轉成真正的 NA
data[data == "NA"] <- NA
data[data == ""] <- NA

# 將需要的欄位轉成數值
data$Year <- as.numeric(data$Year)

data$`Political stability` <- as.numeric(data$`Political stability`)
data$`FSI(100-FSI)` <- as.numeric(data$`FSI(100-FSI)`)
data$Democracy <- as.numeric(data$Democracy)

data$Post2022 <- as.numeric(data$Post2022)
data$SCS <- as.numeric(data$SCS)

data$`Trade China` <- as.numeric(data$`Trade China`)
data$`Sec us` <- as.numeric(data$`Sec us`)

data$`Strategic Ambiguity` <- as.numeric(data$`Strategic Ambiguity`)
data$`Dis unga idealpoint` <- as.numeric(data$`Dis unga idealpoint`)

# 再確認一次
str(data)
tibble [80 × 11] (S3: tbl_df/tbl/data.frame)
 $ Country            : chr [1:80] "Philippines" "Philippines" "Philippines" "Philippines" ...
 $ Year               : num [1:80] 2014 2015 2016 2017 2018 ...
 $ Political stability: num [1:80] 52.1 50.1 41.4 44 47.7 ...
 $ FSI(100-FSI)     : num [1:80] 14.7 13.8 15.3 15.6 14.5 16.9 19 17.6 19.5 22.2 ...
 $ Democracy          : num [1:80] 6.77 6.84 6.94 6.71 6.71 6.64 7.02 6.62 5.93 6.37 ...
 $ Post2022           : num [1:80] 0 0 0 0 0 0 0 0 1 1 ...
 $ SCS                : num [1:80] 1 1 1 1 1 1 1 1 1 1 ...
 $ Trade China        : num [1:80] 0.0616 0.0583 0.0694 0.0807 0.0902 ...
 $ Sec us             : num [1:80] 0.74 0.818 0.851 0.766 0.634 0.716 0.825 0.886 0.649 0.742 ...
 $ Strategic Ambiguity: num [1:80] NA NA NA NA NA ...
 $ Dis unga idealpoint: num [1:80] 2.64 3.03 2.54 2.9 2.72 ...
summary(data)
   Country               Year      Political stability FSI(100-FSI) 
 Length:80          Min.   :2014   Min.   :41.43       Min.   :11.50  
 Class :character   1st Qu.:2016   1st Qu.:55.73       1st Qu.:19.48  
 Mode  :character   Median :2018   Median :65.30       Median :27.20  
                    Mean   :2018   Mean   :64.52       Mean   :30.96  
                    3rd Qu.:2021   3rd Qu.:70.21       3rd Qu.:34.45  
                    Max.   :2023   Max.   :89.57       Max.   :74.50  
                                                                      
   Democracy        Post2022        SCS       Trade China         Sec us      
 Min.   :1.770   Min.   :0.0   Min.   :0.0   Min.   :0.0511   Min.   :0.0700  
 1st Qu.:3.160   1st Qu.:0.0   1st Qu.:0.0   1st Qu.:0.1014   1st Qu.:0.5373  
 Median :6.160   Median :0.0   Median :0.5   Median :0.2074   Median :0.6495  
 Mean   :5.135   Mean   :0.2   Mean   :0.5   Mean   :0.2176   Mean   :0.6316  
 3rd Qu.:6.647   3rd Qu.:0.0   3rd Qu.:1.0   3rd Qu.:0.2843   3rd Qu.:0.7370  
 Max.   :7.300   Max.   :1.0   Max.   :1.0   Max.   :0.4523   Max.   :0.8940  
                                                                              
 Strategic Ambiguity Dis unga idealpoint
 Min.   :26.80       Min.   :1.038      
 1st Qu.:44.20       1st Qu.:2.397      
 Median :77.60       Median :2.832      
 Mean   :67.62       Mean   :2.683      
 3rd Qu.:88.65       3rd Qu.:3.154      
 Max.   :96.00       Max.   :3.492      
 NA's   :40                             
####################################################
## 3. Regression Analysis
####################################################

#########################
## Model 1
#########################

model_unga <- lm(

`Dis unga idealpoint` ~

Democracy +
Post2022 +
SCS +

`Political stability` +
`FSI(100-FSI)` +
`Trade China` +
`Sec us`,

data = data

)

summary(model_unga)

Call:
lm(formula = `Dis unga idealpoint` ~ Democracy + Post2022 + SCS + 
    `Political stability` + `FSI(100-FSI)` + `Trade China` + 
    `Sec us`, data = data)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.07942 -0.25982  0.02215  0.21699  0.71498 

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)            2.828934   0.479241   5.903 1.08e-07 ***
Democracy             -0.084478   0.032768  -2.578   0.0120 *  
Post2022              -1.165356   0.095427 -12.212  < 2e-16 ***
SCS                    0.205679   0.086026   2.391   0.0194 *  
`Political stability`  0.007634   0.006340   1.204   0.2324    
`FSI(100-FSI)`      -0.006109   0.004570  -1.337   0.1855    
`Trade China`         -0.001305   0.412716  -0.003   0.9975    
`Sec us`               0.181308   0.296237   0.612   0.5424    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.3286 on 72 degrees of freedom
Multiple R-squared:  0.7275,    Adjusted R-squared:  0.701 
F-statistic: 27.46 on 7 and 72 DF,  p-value: < 2.2e-16
#########################
## Model 2
#########################

model_sa <- lm(

`Strategic Ambiguity` ~

Democracy +
Post2022 +
SCS +

`Political stability` +
`FSI(100-FSI)` +
`Trade China` +
`Sec us`,

data = data

)

summary(model_sa)

Call:
lm(formula = `Strategic Ambiguity` ~ Democracy + Post2022 + SCS + 
    `Political stability` + `FSI(100-FSI)` + `Trade China` + 
    `Sec us`, data = data)

Residuals:
   Min     1Q Median     3Q    Max 
-43.05 -11.65   3.21  10.16  34.85 

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)  
(Intercept)             9.55195   48.92342   0.195   0.8464  
Democracy               7.26603    3.47952   2.088   0.0448 *
Post2022                9.19763    6.83639   1.345   0.1880  
SCS                   -17.79026    8.65478  -2.056   0.0481 *
`Political stability`   0.11770    0.74422   0.158   0.8753  
`FSI(100-FSI)`       -0.02064    0.53026  -0.039   0.9692  
`Trade China`          17.09603   36.37006   0.470   0.6415  
`Sec us`               24.36829   27.06405   0.900   0.3746  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 20.67 on 32 degrees of freedom
  (40 observations deleted due to missingness)
Multiple R-squared:  0.3808,    Adjusted R-squared:  0.2454 
F-statistic: 2.811 on 7 and 32 DF,  p-value: 0.02121
plot(model_unga, which=1)

plot(model_unga, which=2)

plot(model_unga, which=3)

plot(model_unga, which=5)

plot(model_sa, which=1)

plot(model_sa, which=2)

plot(model_sa, which=3)

plot(model_sa, which=5)