library(sjPlot)
data_path <- "C:/Users/v106K/OneDrive/桌面/國政經參考資料/R data"
data <- read.csv(
file.path(data_path, "FDI_GPR_simple_analysis.csv"),
fileEncoding = "UTF-8-BOM",
check.names = FALSE
)
data$company <- factor(data$company)
data$industry_position <- factor(data$industry_position)
data$invest <- as.numeric(data$invest)
data$global_gpr_lag1 <- as.numeric(data$global_gpr_lag1)
data$host_gpr_lag1 <- as.numeric(data$host_gpr_lag1)
data$host_gpr_high <- as.factor(data$host_gpr_high)
# H1:公司年度資料,避免公司年度重複
company_year_simple <- data[!duplicated(data[c("company", "year")]), ]
model_h1 <- lm(
fdi_total_billion ~ global_gpr_lag1 + company,
data = company_year_simple
)
summary(model_h1)
Call:
lm(formula = fdi_total_billion ~ global_gpr_lag1 + company, data = company_year_simple)
Residuals:
Min 1Q Median 3Q Max
-169.91 -65.51 -13.28 20.79 426.00
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -156.148 119.278 -1.309 0.205
global_gpr_lag1 1.430 1.014 1.409 0.174
companyMTK 11.551 64.176 0.180 0.859
companyTSM 133.846 64.176 2.086 0.050 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 128.4 on 20 degrees of freedom
Multiple R-squared: 0.2682, Adjusted R-squared: 0.1584
F-statistic: 2.443 on 3 and 20 DF, p-value: 0.09398
tab_model(
model_h1,
show.se = TRUE,
show.r2 = TRUE,
p.style = "stars",
digits = 3,
digits.p = 3,
dv.labels = "H1:Global GPR 對 FDI 總額之影響"
)
| |
H1:Global GPR 對 FDI 總額之影響 |
| Predictors |
Estimates |
std. Error |
CI |
| (Intercept) |
-156.148 |
119.278 |
-404.957 – 92.661 |
| global gpr lag1 |
1.430 |
1.014 |
-0.686 – 3.545 |
| company [MTK] |
11.551 |
64.176 |
-122.318 – 145.420 |
| company [TSM] |
133.846 |
64.176 |
-0.023 – 267.715 |
| Observations |
24 |
| R2 / R2 adjusted |
0.268 / 0.158 |
| * p<0.05 ** p<0.01 *** p<0.001 |
# H2:卡方檢定
h2_data <- data[!is.na(data$host_gpr_lag1), ]
table_h2 <- table(h2_data$host_gpr_high, h2_data$invest)
table_h2
Pearson's Chi-squared test with Yates' continuity correction
data: table_h2
X-squared = 5.7436, df = 1, p-value = 0.01655
# H2:Logit 迴歸
model_h2 <- glm(
invest ~ host_gpr_lag1 + company,
data = h2_data,
family = binomial
)
summary(model_h2)
Call:
glm(formula = invest ~ host_gpr_lag1 + company, family = binomial,
data = h2_data)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.1217 0.3112 -6.818 9.23e-12 ***
host_gpr_lag1 0.7311 0.1940 3.770 0.000164 ***
companyMTK -0.4295 0.4183 -1.027 0.304528
companyTSM -0.6448 0.4384 -1.471 0.141315
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 235.10 on 311 degrees of freedom
Residual deviance: 219.72 on 308 degrees of freedom
AIC: 227.72
Number of Fisher Scoring iterations: 5
tab_model(
model_h2,
show.se = TRUE,
show.r2 = TRUE,
p.style = "stars",
transform = "exp",
digits = 3,
digits.p = 3,
dv.labels = "H2:Host GPR 對是否投資某國之影響"
)
| |
H2:Host GPR 對是否投資某國之影響 |
| Predictors |
Odds Ratios |
std. Error |
CI |
| (Intercept) |
0.120 *** |
0.037 |
0.063 – 0.214 |
| host gpr lag1 |
2.077 *** |
0.403 |
1.414 – 3.048 |
| company [MTK] |
0.651 |
0.272 |
0.281 – 1.467 |
| company [TSM] |
0.525 |
0.230 |
0.215 – 1.220 |
| Observations |
312 |
| R2 Tjur |
0.056 |
| * p<0.05 ** p<0.01 *** p<0.001 |
# H3:卡方檢定
table_h3 <- table(data$industry_position, data$invest)
table_h3
0 1
IC設計 100 12
封裝測試 95 17
晶圓製造 102 10
Pearson's Chi-squared test
data: table_h3
X-squared = 2.2626, df = 2, p-value = 0.3226
# H3:簡單 Logit
model_h3 <- glm(
invest ~ industry_position,
data = data,
family = binomial
)
summary(model_h3)
Call:
glm(formula = invest ~ industry_position, family = binomial,
data = data)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.1203 0.3055 -6.940 3.92e-12 ***
industry_position封裝測試 0.3996 0.4033 0.991 0.322
industry_position晶圓製造 -0.2021 0.4507 -0.448 0.654
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 241.26 on 335 degrees of freedom
Residual deviance: 239.05 on 333 degrees of freedom
AIC: 245.05
Number of Fisher Scoring iterations: 5
tab_model(
model_h3,
show.se = TRUE,
show.r2 = TRUE,
p.style = "stars",
transform = "exp",
digits = 3,
digits.p = 3,
dv.labels = "H3:產業鏈位置對是否投資某國之影響"
)
| |
H3:產業鏈位置對是否投資某國之影響 |
| Predictors |
Odds Ratios |
std. Error |
CI |
| (Intercept) |
0.120 *** |
0.037 |
0.063 – 0.209 |
| industry position [封裝測試] |
1.491 |
0.601 |
0.681 – 3.358 |
| industry position [晶圓製造] |
0.817 |
0.368 |
0.331 – 1.978 |
| Observations |
336 |
| R2 Tjur |
0.007 |
| * p<0.05 ** p<0.01 *** p<0.001 |
You can add options to executable code like this
The echo: false option disables the printing of code (only output is displayed).