2- Biến độc lập (mục tiêu xem xét tác động) Có bảo hiểm y tế bổ sung - suppins
3- Các biến số khác có liên quan: age, famsze, educyr
Tổng quan dữ liệu các biến
L2 %>%select(totexp) %>%summary()
totexp
Min. : 0
1st Qu.: 1272
Median : 3134
Mean : 7031
3rd Qu.: 7142
Max. :125610
Lập bảng thống kê
L2 %>%select(totexp, suppins, age) %>%summary()
totexp suppins age
Min. : 0 Min. :0.0000 Min. :65.00
1st Qu.: 1272 1st Qu.:0.0000 1st Qu.:69.00
Median : 3134 Median :1.0000 Median :73.00
Mean : 7031 Mean :0.5813 Mean :74.17
3rd Qu.: 7142 3rd Qu.:1.0000 3rd Qu.:79.00
Max. :125610 Max. :1.0000 Max. :90.00
# Xem mối quan hệ giữa chi tiêu y tế với bảo hiểm bổ sung :Xem tổng quanL2 %>%select(totexp, suppins) %>%group_by(suppins) %>%summarise(mean=mean(totexp),min=min(totexp),max=max(totexp),SD=sd(totexp))
# A tibble: 2 × 5
suppins mean min max SD
<dbl> <dbl> <dbl> <dbl> <dbl>
1 0 6420. 0 104823 11199.
2 1 7471. 0 125610 12287.
totexp suppins age
totexp 1.00 0.04 0.03
suppins 0.04 1.00 -0.11
age 0.03 -0.11 1.00
Linear Regression
Xem xét tác động riêng của bảo hiểm bổ sung tới chi tiêu y tế
M1<-lm(totexp~suppins,L2)
M1 là ta gán tên cho mô hình, các bạn có thể đặt tên khác tùy ý. lm: là lệnh dùng để ước lượng mô hình hồi quy tuyến tính. L2: là tên dữ liệu dùng để ước lượng
summary(M1)
Call:
lm(formula = totexp ~ suppins, data = L2)
Residuals:
Min 1Q Median 3Q Max
-7471 -5692 -3898 130 118139
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6420.1 330.6 19.417 <2e-16 ***
suppins 1050.9 433.7 2.423 0.0154 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 11840 on 3062 degrees of freedom
Multiple R-squared: 0.001914, Adjusted R-squared: 0.001588
F-statistic: 5.871 on 1 and 3062 DF, p-value: 0.01545
Xem xét các mô hình mở rộng các yếu tố kiểm soát
M2 <-lm(totexp ~suppins + age + famsze +educyr+income, data=L2)M3 <-lm(totexp~suppins+ age + famsze +educyr + injury+totchr, data=L2 )
summary(M2)
Call:
lm(formula = totexp ~ suppins + age + famsze + educyr + income,
data = L2)
Residuals:
Min 1Q Median 3Q Max
-8746 -5594 -3849 19 117820
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2275.19 2909.29 0.782 0.4342
suppins 996.74 451.81 2.206 0.0275 *
age 51.20 34.74 1.474 0.1406
famsze -397.68 223.03 -1.783 0.0747 .
educyr 127.28 67.70 1.880 0.0602 .
income -16.07 10.27 -1.566 0.1175
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 11830 on 3058 degrees of freedom
Multiple R-squared: 0.005818, Adjusted R-squared: 0.004192
F-statistic: 3.579 on 5 and 3058 DF, p-value: 0.003139
M3 %>%summary()
Call:
lm(formula = totexp ~ suppins + age + famsze + educyr + injury +
totchr, data = L2)
Residuals:
Min 1Q Median 3Q Max
-16458 -5062 -2528 380 114015
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -64.648 2771.364 -0.023 0.981391
suppins 524.775 429.919 1.221 0.222317
age 8.589 33.126 0.259 0.795433
famsze -165.535 213.617 -0.775 0.438449
educyr 141.159 61.980 2.277 0.022826 *
injury 1851.317 519.655 3.563 0.000373 ***
totchr 2532.904 158.973 15.933 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 11320 on 3057 degrees of freedom
Multiple R-squared: 0.08984, Adjusted R-squared: 0.08805
F-statistic: 50.29 on 6 and 3057 DF, p-value: < 2.2e-16
Tables of output from several regressions
Trình bày: So sánh các mô hình xem kết quả Chúng ta có nhiều cách để trình bày, dưới đây là 2 cách, các cách khác có thể tìm thấy trên google
Goldfeld-Quandt test
data: totexp ~ suppins + age + famsze + educyr
GQ = 243.53, df1 = 1527, df2 = 1527, p-value < 2.2e-16
alternative hypothesis: variance increases from segment 1 to 2
Nếu có Phương sai sai số thay đổi ta nên làm thế nào?
Serial Correlation
Kiểm tra hiện tượng tương quan chuỗi
lmtest::dwtest(totexp ~suppins + age + famsze, data=L2)
Durbin-Watson test
data: totexp ~ suppins + age + famsze
DW = 0.045237, p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0
Trong dữ liệu chéo thì hiện tượng này có quan trọng không? vì sao?
Checking for unsual or influential observations
Kiểm tra các ảnh hưởng đến mô hình do các giá trị outliers (giá trị dị biệt) Xem thống kê các quan sát dị biệt