2023年度 経済データ分析演習B2
2023-11-25
Responは講義終了までに登録してください
Respon
735 886 207
これまで欠席された方は、以下の登録をお願いします
クラスコード
oyhqpgl
ダミー変数:あるグループであれば1をとり、そうでなければ0をとる、質的情報を表す
基準グループ(reference group):ダミー変数が0をとるグループ
\[ \begin{equation} y_i = \alpha + \beta x_{i} + u_i \end{equation} \]
ダミー変数を含む重回帰モデル:女性ダミー変数は\(D_i\)
\[ \begin{equation} y_i = \alpha + \beta_1 x_{i} + \beta_2 D_{i} + u_i \end{equation} \]
\[ \begin{equation} y_i = \alpha + \beta_1 x_{i} + \beta_2 \times 0 + u_i \end{equation} \]
\[ \begin{equation} y_i = \alpha + \beta_1 x_{i} + \beta_2 \times 1 + u_i \end{equation} \]
\[ \begin{equation} y_i = (\alpha + \beta_2 \times 1) + \beta_1 x_{i} + u_i \end{equation} \]
Call:
lm(formula = con_expend ~ con_income + factor(dum_female), data = df)
Residuals:
Min 1Q Median 3Q Max
-10.693 -1.966 -0.396 1.460 16.104
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.9144 0.4010 2.280 0.0234 *
con_income 0.4259 0.0379 11.240 <2e-16 ***
factor(dum_female)1 1.0704 0.4367 2.451 0.0149 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.353 on 258 degrees of freedom
(55 observations deleted due to missingness)
Multiple R-squared: 0.3397, Adjusted R-squared: 0.3346
F-statistic: 66.37 on 2 and 258 DF, p-value: < 2.2e-16
\[ \begin{equation} y_i = \alpha + \beta_1 x_{i} + \beta_2 D_{1i} + \beta_3 D_{2i} + u_i \end{equation} \]
女性以外&アルバイト無し(\(D_1 = 0 \& D_2 = 0\))
女性&アルバイト無し(\(D_1 = 1 \& D_2 = 0\))
女性以外&アルバイト有り(\(D_1 = 0 \& D_2 = 1\))
女性&アルバイト有り(\(D_1 = 1 \& D_2 = 1\))
Call:
lm(formula = con_expend ~ con_income + factor(dum_female) + factor(dum_partjob),
data = df)
Residuals:
Min 1Q Median 3Q Max
-10.9442 -2.0163 -0.3831 1.5346 16.6070
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.01629 0.50672 3.979 9e-05 ***
con_income 0.45560 0.03811 11.955 < 2e-16 ***
factor(dum_female)1 1.11681 0.42797 2.610 0.009598 **
factor(dum_partjob)1 -1.74011 0.50545 -3.443 0.000672 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.285 on 257 degrees of freedom
(55 observations deleted due to missingness)
Multiple R-squared: 0.3688, Adjusted R-squared: 0.3615
F-statistic: 50.06 on 3 and 257 DF, p-value: < 2.2e-16
カテゴリー変数:複数のグループが存在する質的情報を表す変数
\[ \begin{equation} y_i = \alpha + \beta_1 x_{i} + \beta_2 D_{1i} + \beta_3 D_{2i} + \sum_{k}^{k=4} \gamma_k K_{ki} + u_i \end{equation} \]
Call:
lm(formula = con_expend ~ con_income + factor(dum_female) + factor(dum_partjob) +
factor(cat5_health), data = df)
Residuals:
Min 1Q Median 3Q Max
-11.1979 -1.9904 -0.4405 1.5528 16.8554
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.05974 0.57527 3.581 0.000411 ***
con_income 0.45005 0.03888 11.576 < 2e-16 ***
factor(dum_female)1 1.14364 0.43342 2.639 0.008840 **
factor(dum_partjob)1 -1.71923 0.50843 -3.381 0.000835 ***
factor(cat5_health)2 -0.33952 0.50379 -0.674 0.500971
factor(cat5_health)3 0.35596 0.56370 0.631 0.528306
factor(cat5_health)4 0.17703 0.76719 0.231 0.817691
factor(cat5_health)5 -0.92430 3.34139 -0.277 0.782296
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.299 on 253 degrees of freedom
(55 observations deleted due to missingness)
Multiple R-squared: 0.3733, Adjusted R-squared: 0.356
F-statistic: 21.53 on 7 and 253 DF, p-value: < 2.2e-16
# 被説明変数yに"con_expend"
# 説明変数xに"con_income"
# ダミー変数Dに"dum_female"と"dum_partjob"
# カテゴリー変数に"cat5_health" <- reference groupを5に
result <- lm(con_expend ~ con_income + factor(dum_female) + factor(dum_partjob) + factor(cat5_health), data = df %>% mutate(cat5_health = relevel(as.factor(cat5_health), ref = "5"))) # 回帰分析の結果をresultというオブジェクトに代入
summary(result) # 結果が格納されたオブジェクトを表示
Call:
lm(formula = con_expend ~ con_income + factor(dum_female) + factor(dum_partjob) +
factor(cat5_health), data = df %>% mutate(cat5_health = relevel(as.factor(cat5_health),
ref = "5")))
Residuals:
Min 1Q Median 3Q Max
-11.1979 -1.9904 -0.4405 1.5528 16.8554
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.13544 3.36217 0.338 0.735861
con_income 0.45005 0.03888 11.576 < 2e-16 ***
factor(dum_female)1 1.14364 0.43342 2.639 0.008840 **
factor(dum_partjob)1 -1.71923 0.50843 -3.381 0.000835 ***
factor(cat5_health)1 0.92430 3.34139 0.277 0.782296
factor(cat5_health)2 0.58479 3.33480 0.175 0.860938
factor(cat5_health)3 1.28026 3.34891 0.382 0.702566
factor(cat5_health)4 1.10134 3.38696 0.325 0.745321
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.299 on 253 degrees of freedom
(55 observations deleted due to missingness)
Multiple R-squared: 0.3733, Adjusted R-squared: 0.356
F-statistic: 21.53 on 7 and 253 DF, p-value: < 2.2e-16
交差項:2つの説明変数をかけ合わせた変数
\[ \begin{equation} y_i = \alpha + \beta_1 x_{i} + \beta_2 D_{1i} + \beta_3 D_{2i} + \beta_4 (x_i \times D_{1i}) + \sum_{k}^{k=4} \gamma_k K_{ki} + u_i \end{equation} \]
Call:
lm(formula = con_expend ~ con_income + con_income * factor(dum_female) +
factor(dum_partjob) + factor(cat5_health), data = df)
Residuals:
Min 1Q Median 3Q Max
-7.8766 -2.0041 -0.2612 1.3873 17.9999
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.08809 0.60072 5.141 5.50e-07 ***
con_income 0.27371 0.05445 5.027 9.45e-07 ***
factor(dum_female)1 -1.64222 0.75080 -2.187 0.0296 *
factor(dum_partjob)1 -1.11770 0.50855 -2.198 0.0289 *
factor(cat5_health)2 -0.32802 0.48592 -0.675 0.5003
factor(cat5_health)3 0.26940 0.54404 0.495 0.6209
factor(cat5_health)4 -0.24618 0.74601 -0.330 0.7417
factor(cat5_health)5 -0.28210 3.22605 -0.087 0.9304
con_income:factor(dum_female)1 0.33689 0.07542 4.467 1.20e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.182 on 252 degrees of freedom
(55 observations deleted due to missingness)
Multiple R-squared: 0.4193, Adjusted R-squared: 0.4009
F-statistic: 22.75 on 8 and 252 DF, p-value: < 2.2e-16
\[ \begin{equation} y_i = \alpha + \beta_1 x_{i} + \beta_2 D_{1i} + \beta_3 D_{2i} + \beta_4 (x_i \times D_{1i}) + \beta_5 (x_i \times D_{2i}) + \sum_{k}^{k=4} \gamma_k K_{ki} + u_i \end{equation} \]
# 被説明変数yに"con_expend"
# 説明変数xに"con_income"
# ダミー変数Dに"dum_female"と"dum_partjob"
# カテゴリー変数に"cat5_health"
result <- lm(con_expend ~ con_income + con_income*factor(dum_female) + con_income*factor(dum_partjob) + factor(cat5_health), data = df) # 回帰分析の結果をresultというオブジェクトに代入
summary(result) # 結果が格納されたオブジェクトを表示
Call:
lm(formula = con_expend ~ con_income + con_income * factor(dum_female) +
con_income * factor(dum_partjob) + factor(cat5_health), data = df)
Residuals:
Min 1Q Median 3Q Max
-8.5569 -1.8224 -0.3197 1.4526 17.0151
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.174042 0.651536 3.337 0.000976 ***
con_income 0.445585 0.074712 5.964 8.32e-09 ***
factor(dum_female)1 -1.393574 0.740449 -1.882 0.060984 .
factor(dum_partjob)1 0.590457 0.720030 0.820 0.412969
factor(cat5_health)2 -0.386068 0.477044 -0.809 0.419113
factor(cat5_health)3 0.199045 0.534167 0.373 0.709741
factor(cat5_health)4 -0.009007 0.735419 -0.012 0.990238
factor(cat5_health)5 -0.890949 3.170344 -0.281 0.778922
con_income:factor(dum_female)1 0.280882 0.075922 3.700 0.000265 ***
con_income:factor(dum_partjob)1 -0.251459 0.076426 -3.290 0.001145 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.121 on 251 degrees of freedom
(55 observations deleted due to missingness)
Multiple R-squared: 0.4433, Adjusted R-squared: 0.4234
F-statistic: 22.21 on 9 and 251 DF, p-value: < 2.2e-16