interaction_effects_in_regression_analysis
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
interaction_effects_in_regression_analysis [2023/06/12 08:36] – [Analysis again] hkimscil | interaction_effects_in_regression_analysis [2023/06/14 08:54] (current) – [Two continuous variables] hkimscil | ||
---|---|---|---|
Line 379: | Line 379: | ||
- (위의 마지막 식에서) x1:x2 = x1*x2 : 질소량이 1씩 증가할 때 마다, 온도의 영향력은 1.5식 증가한다. 예를 들면 질소량이 0일 경우, 온도와 작물 간의 기울기는 약 2인데, 질소의 양이 1 증가하고 온도가 1 증가하면 기울기는 2 + 1.5 = 3.5가 된다. | - (위의 마지막 식에서) x1:x2 = x1*x2 : 질소량이 1씩 증가할 때 마다, 온도의 영향력은 1.5식 증가한다. 예를 들면 질소량이 0일 경우, 온도와 작물 간의 기울기는 약 2인데, 질소의 양이 1 증가하고 온도가 1 증가하면 기울기는 2 + 1.5 = 3.5가 된다. | ||
- <WRAP box>< | - <WRAP box>< | ||
- | x1=1,x2=1: 0.97 + *3.5 x1 + -1 x2 | + | # 0.97 = 1 로 보면 |
- | x1=2,x2=2: 0.97 + *5.0 x1 + -1 x2 | + | x2=1: 0.97 + *3.5 x1 + -1 (1=x2) |
- | x1=3,x2=3: 0.97 + *6.5 x1 + -1 x2 | + | 0 + 3.5 x1 |
- | x1=4,x2=4: 0.97 + *8.0 x1 + -1 x2 | + | x2=2: 0.97 + *5.0 x1 + -1 (2=x2) |
- | x1=5,x2=5: 0.97 + *9.5 x1 + -1 x2</ | + | -1 + 5.0 x1 |
+ | x2=3: 0.97 + *6.5 x1 + -1 (3=x2) | ||
+ | -2 + 6.5 x1 | ||
+ | x2=4: 0.97 + *8.0 x1 + -1 (4=x2) | ||
+ | -3 + 8.0 x1 | ||
+ | x2=5: 0.97 + *9.5 x1 + -1 (5=x2) | ||
+ | -4 + 9.5 x1 | ||
+ | </ | ||
< | < | ||
*(1.995115 + 1.499595*x2): | *(1.995115 + 1.499595*x2): | ||
Line 669: | Line 676: | ||
s.n.i <- summary(n.i) | s.n.i <- summary(n.i) | ||
- | s.n12i | + | s.n.12i |
# y hat ~ 1048 + -0.003917 x1 + -3.809 x2 + 0.000249 x1 x2 | # y hat ~ 1048 + -0.003917 x1 + -3.809 x2 + 0.000249 x1 x2 | ||
Line 677: | Line 684: | ||
e.mm1 <- mean(expense)-sd(expense) | e.mm1 <- mean(expense)-sd(expense) | ||
e.m0 <- mean(expense) | e.m0 <- mean(expense) | ||
- | e.mp1 <- mean(expxense)+sd(expense) | + | e.mp1 <- mean(expense)+sd(expense) |
e.mp2 <- mean(expense)+(2*sd(expense)) | e.mp2 <- mean(expense)+(2*sd(expense)) | ||
Line 706: | Line 713: | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | > n.1 <- lm(csat~expense) | ||
+ | > n.2 <- lm(csat~percent) | ||
+ | > n.12 <- lm(csat~expense+percent) | ||
+ | > n.12i <- lm(csat~expense*percent) | ||
+ | > n.1i <- lm(csat~expense+expense: | ||
+ | > n.2i <- lm(csat~percent+expense: | ||
+ | > n.2i.temp <- lm(csat~percent+percent: | ||
+ | > n.i <- lm(csat~expense: | ||
+ | > | ||
+ | > s.n.1 <- summary(n.1) | ||
+ | > s.n.2 <- summary(n.2) | ||
+ | > s.n.12 <- summary(n.12) | ||
+ | > s.n.12i <- summary(n.12i) | ||
+ | > s.n.1i <- summary(n.1i) | ||
+ | > s.n.2i <- summary(n.2i) | ||
+ | > s.n.2i.temp <- summary(n.2i.temp) | ||
+ | > s.n.i <- summary(n.i) | ||
+ | > | ||
+ | > s.n.12i | ||
+ | |||
+ | Call: | ||
+ | lm(formula = csat ~ expense * percent) | ||
+ | |||
+ | Residuals: | ||
+ | | ||
+ | -65.36 -19.61 | ||
+ | |||
+ | Coefficients: | ||
+ | | ||
+ | (Intercept) | ||
+ | expense | ||
+ | percent | ||
+ | expense: | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | |||
+ | Residual standard error: 30.8 on 47 degrees of freedom | ||
+ | Multiple R-squared: | ||
+ | F-statistic: | ||
+ | |||
+ | > | ||
+ | > # y hat ~ 1048 + -0.003917 x1 + -3.809 x2 + 0.000249 x1 x2 | ||
+ | > # y hat ~ 1048 + -0.003917 x1 + (-3.809 + 0.000249 x1) x2 | ||
+ | > # x2를 (percent를) 중심으로 보기 | ||
+ | > | ||
+ | > e.mm1 <- mean(expense)-sd(expense) | ||
+ | > e.m0 <- mean(expense) | ||
+ | > e.mp1 <- mean(expense)+sd(expense) | ||
+ | > e.mp2 <- mean(expense)+(2*sd(expense)) | ||
+ | > | ||
+ | > # x1의 case가 4가지 (holding constants) | ||
+ | > k <- c(e.mm1, e.m0, e.mp1, e.mp2) | ||
+ | > ic <- 1048 + (-0.003917*k) | ||
+ | > slp <- -3.809 + (0.000249*k) | ||
+ | > ic | ||
+ | [1] 1033 1027 1022 1017 | ||
+ | > slp | ||
+ | [1] -2.854 -2.505 -2.156 -1.807 | ||
+ | > | ||
+ | > # y hat ~ 1032.979 - 2.85 x2 | ||
+ | > # y hat ~ 1027.491 - 2.51 x2 | ||
+ | > # y hat ~ 1022.002 - 2.16 x2 | ||
+ | > # y hat ~ 1016.514 - 1.81 x2 | ||
+ | > | ||
+ | > interact_plot(n.12i, | ||
+ | + pred = " | ||
+ | + modx = " | ||
+ | + | ||
+ | > # or | ||
+ | > mne <- min(expense) | ||
+ | > mxe <- max(expense) | ||
+ | > kk <- seq(mne, mxe, by = 2000) | ||
+ | > interact_plot(n.12i, | ||
+ | + pred = " | ||
+ | + modx = " | ||
+ | + | ||
+ | > | ||
+ | </ | ||
+ | |||
아래 그림에서처럼 대학지원 퍼센티지가 높아지면 성적이 떨어지는 경향을 보이는데, | 아래 그림에서처럼 대학지원 퍼센티지가 높아지면 성적이 떨어지는 경향을 보이는데, | ||
{{: | {{: | ||
+ | |||
+ | ===== 언제 interaction effect를 분석에 넣는가? ===== | ||
+ | interaction effects가 significant할 때에 넣는다 | ||
+ | significant하지 않을 때에는 additive model을 (+사인 모델) 사용한다. | ||
===== One categorical IV ===== | ===== One categorical IV ===== | ||
Line 816: | Line 908: | ||
[5] " | [5] " | ||
</ | </ | ||
- | + | 아래의 경우 interaction effect는 중요한 의미를 갖는다. additive model에서는 murder가 중요한 역할을 하지 않지만, interactive model에서는 Illiteracy와 결합하여 중요한 역할을 하는 것으로 해석될 수 있다. | |
- | < | + | < |
+ | fit <- lm(Income ~ Illiteracy + Murder, data = as.data.frame(state.x77)) | ||
+ | fiti <- lm(Income ~ Illiteracy * Murder, data = as.data.frame(state.x77)) | ||
+ | summary(fit) | ||
summary(fiti) | summary(fiti) | ||
+ | </ | ||
+ | < | ||
+ | > fit <- lm(Income ~ Illiteracy + Murder, data = as.data.frame(state.x77)) | ||
+ | > fiti <- lm(Income ~ Illiteracy * Murder, data = as.data.frame(state.x77)) | ||
+ | > summary(fit) | ||
+ | |||
+ | Call: | ||
+ | lm(formula = Income ~ Illiteracy + Murder, data = as.data.frame(state.x77)) | ||
+ | |||
+ | Residuals: | ||
+ | | ||
+ | -880.9 -397.3 | ||
+ | |||
+ | Coefficients: | ||
+ | Estimate Std. Error t value Pr(> | ||
+ | (Intercept) | ||
+ | Illiteracy | ||
+ | Murder | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | |||
+ | Residual standard error: 560 on 47 degrees of freedom | ||
+ | Multiple R-squared: | ||
+ | F-statistic: | ||
+ | |||
+ | > summary(fiti) | ||
+ | |||
Call: | Call: | ||
lm(formula = Income ~ Illiteracy * Murder, data = as.data.frame(state.x77)) | lm(formula = Income ~ Illiteracy * Murder, data = as.data.frame(state.x77)) | ||
Residuals: | Residuals: | ||
- | | + | |
- | -955.20 -325.99 10.66 299.96 1892.12 | + | -955.2 -326.0 10.7 300.0 1892.1 |
Coefficients: | Coefficients: | ||
Estimate Std. Error t value Pr(> | Estimate Std. Error t value Pr(> | ||
- | (Intercept) | + | (Intercept) |
- | Illiteracy | + | Illiteracy |
- | Murder | + | Murder |
- | Illiteracy: | + | Illiteracy: |
--- | --- | ||
Signif. codes: | Signif. codes: | ||
- | Residual standard error: 520.1 on 46 degrees of freedom | + | Residual standard error: 520 on 46 degrees of freedom |
- | Multiple R-squared: | + | Multiple R-squared: |
- | F-statistic: | + | F-statistic: |
> | > | ||
</ | </ | ||
- | |||
< | < | ||
Line 848: | Line 969: | ||
{{: | {{: | ||
- | < | ||
- | interact_plot(fitiris, | ||
- | |||
- | {{: | ||
====== Eg. 4 ====== | ====== Eg. 4 ====== |
interaction_effects_in_regression_analysis.1686526572.txt.gz · Last modified: 2023/06/12 08:36 by hkimscil