multiple_regression_exercise
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| multiple_regression_exercise [2025/10/30 12:28] – [추가설명] hkimscil | multiple_regression_exercise [2025/10/30 13:28] (current) – [추가설명] hkimscil | ||
|---|---|---|---|
| Line 310: | Line 310: | ||
| 아래는 Advertising을 없애질 않고 ShelveLoc을 없앤것이라서 약간 다르게 보이지만 요지는 같습니다. | 아래는 Advertising을 없애질 않고 ShelveLoc을 없앤것이라서 약간 다르게 보이지만 요지는 같습니다. | ||
| < | < | ||
| - | > | ||
| > lm.1 <- lm(Sales ~ Advertising + Advertising: | > lm.1 <- lm(Sales ~ Advertising + Advertising: | ||
| - | > lm.1 | + | > summary(lm.1) |
| Call: | Call: | ||
| lm(formula = Sales ~ Advertising + Advertising: | lm(formula = Sales ~ Advertising + Advertising: | ||
| + | |||
| + | Residuals: | ||
| + | Min 1Q Median | ||
| + | -6.7650 -1.7351 -0.1523 | ||
| Coefficients: | Coefficients: | ||
| - | | + | Estimate Std. Error t value Pr(> |
| - | 6.76500 -0.05412 | + | (Intercept) |
| + | Advertising | ||
| + | Advertising: | ||
| + | Advertising: | ||
| + | --- | ||
| + | Signif. codes: | ||
| + | |||
| + | Residual standard error: 2.476 on 396 degrees of freedom | ||
| + | Multiple R-squared: | ||
| + | F-statistic: | ||
| + | |||
| + | > | ||
| </ | </ | ||
| 위에서 prediction model 식을 완성한다고 하면 | 위에서 prediction model 식을 완성한다고 하면 | ||
| - | Sales hat = 6.76500 - 0.05412 * Advertising | + | * **Sales hat = 6.76500 - 0.05412 * Advertising** |
| - | Sales hat = 6.76500 | + | |
| - | Sales hat = 6.76500 - (0.05412 + 0.35597) * Advertising | + | |
| + | * Sales hat = 6.76500 + (-0.05412 + 0.35597) * Advertising | ||
| + | * **Sales hat = 6.76500 - (0.30185)*Advertising** | ||
| 라고 하겠습니다. | 라고 하겠습니다. | ||
| Line 423: | Line 439: | ||
| </ | </ | ||
| - | 1) ShelveLoc Good일 | + | 1) Bad 인 경우는 |
| - | Sales hat = Intercept + Advertising: | + | * **Sales hat = 6.76500 + -0.05412*Advertising** 이 됩니다. |
| - | Sales hat = 6.76500 + 0.30185 * Advertising | + | |
| - | 2) ShelveLoc | + | 2) ShelveLoc |
| - | Sales hat = 6.76500 + 0.09510 * Advertising 이 됩니다 | + | * Sales hat = Intercept + Advertising: |
| + | * **Sales hat = 6.76500 + 0.30185*Advertising** | ||
| + | * 위의 <fc # | ||
| + | * Advertising: | ||
| + | * Ad coefficient (0.30185) * SelfveLocGood (1) | ||
| - | 3) Bad 인 경우는 | + | 3) ShelveLoc Medium일 |
| - | Sales hat = 6.76500 + -0.05412 * Advertising 이 됩니다. | + | * **Sales hat = 6.76500 + 0.09510 * Advertising** 이 됩니다 |
| 위는 결국 lm.1 과 같은 모델이라는 뜻입니다. | 위는 결국 lm.1 과 같은 모델이라는 뜻입니다. | ||
| - | < | ||
| - | > summary(lm.1) | ||
| - | |||
| - | Call: | ||
| - | lm(formula = Sales ~ Advertising + Advertising: | ||
| - | |||
| - | Residuals: | ||
| - | Min 1Q Median | ||
| - | -6.7650 -1.7351 -0.1523 | ||
| - | |||
| - | Coefficients: | ||
| - | Estimate Std. Error t value Pr(> | ||
| - | (Intercept) | ||
| - | Advertising | ||
| - | Advertising: | ||
| - | Advertising: | ||
| - | --- | ||
| - | Signif. codes: | ||
| - | |||
| - | Residual standard error: 2.476 on 396 degrees of freedom | ||
| - | Multiple R-squared: | ||
| - | F-statistic: | ||
| - | |||
| - | > | ||
| - | |||
| - | |||
| - | </ | ||
| Line 487: | Line 479: | ||
| Coefficients: | Coefficients: | ||
| Estimate Std. Error t value Pr(> | Estimate Std. Error t value Pr(> | ||
| - | (Intercept) | + | (Intercept) |
| - | Advertising | + | Advertising |
| - | ShelveLocGood | + | ShelveLocGood |
| - | ShelveLocMedium | + | ShelveLocMedium |
| - | Advertising: | + | Advertising: |
| - | Advertising: | + | Advertising: |
| --- | --- | ||
| Signif. codes: | Signif. codes: | ||
| Line 500: | Line 492: | ||
| F-statistic: | F-statistic: | ||
| </ | </ | ||
| + | |||
| + | ShelveLocBad case | ||
| + | * (1) = intercept, 5.01234 | ||
| + | * (2) = Advertising, | ||
| + | * (3) = 0 | ||
| + | * (4) = 0 | ||
| + | * (5) = Advertising * 0 | ||
| + | * (6) = Advertising * 0 | ||
| + | * y.hat = 5.01234 + (0.08210)*advertising | ||
| + | |||
| + | Good case | ||
| + | * (1) = intercept, 5.01234 | ||
| + | * (2) = Advertising, | ||
| + | * (3) = 4.43573 | ||
| + | * (4) = 0 | ||
| + | * (5) = Advertising * 1 = 0.02206 | ||
| + | * (6) = Advertising * 0 = 0 | ||
| + | * y.hat = 5.01234 + (0.08210)*Advertising + 4.43573 + (0.02206)*Advertising | ||
| + | * y.hat = 9.44807 + 0.10416*Advertising | ||
| + | |||
| + | Med case | ||
| + | * (1) = intercept, 5.01234 | ||
| + | * (2) = Advertising, | ||
| + | * (3) = 0 | ||
| + | * (4) = 1.59511 | ||
| + | * (5) = Advertising * 0 = 0 | ||
| + | * (6) = Advertising * 0.02482 = 0.02482*Advertising | ||
| + | * y.hat = 5.01234 + (0.08210)*Advertising + 1.59511 + (0.02482)*Advertising | ||
| + | * y.hat = 6.60745 + 0.10692*Advertising | ||
| < | < | ||
| Line 529: | Line 550: | ||
| 위의 결과를 보면 (번호 (1)에서 (6)까지) | 위의 결과를 보면 (번호 (1)에서 (6)까지) | ||
| + | (1) = 5.01234 | ||
| + | (2) = 0 | ||
| + | (3) = 0 | ||
| + | (4) = 0.08210 * (1 = location bad case) * Advertising | ||
| + | (5) = 0.10417 * (0 = location good case) * Advertising = 0 | ||
| + | (6) = 0.10692 * (0 = location med case) * Advertising = 0 | ||
| - | Sales hat = 5.01234 + 0.08210 | + | 따라서, |
| + | Sales hat = 5.01234 + 0.08210 | ||
| 이 첫번째 경우가 | 이 첫번째 경우가 | ||
| * ShelveBad일 경우 intercept만 남고 (5.01234) | * ShelveBad일 경우 intercept만 남고 (5.01234) | ||
| * ShelveBad 가 1이고 나머지는 (Medium 과 Good) 0으로 보는 것이기에 | * ShelveBad 가 1이고 나머지는 (Medium 과 Good) 0으로 보는 것이기에 | ||
| * ShelveLocBad: | * ShelveLocBad: | ||
| - | * (1)에다 (4)의 | + | * (1)에다 (4)의 |
| - | * 그냥 Bad와 (5.01234) | + | * y.hat = 5.01234 + 0.08210*Advertising |
| - | * Advertising이 섞인 Bad (5.01234 + 0.08210) 이 됩니다. | + | |
| - | 두번째 Medium일 경우는 | + | |
| + | 두번째 Good일 경우는 | ||
| + | * Sales hat = (5.01234 + 4.43573) 이고 여기에 Advertising의 interaction을 고려하면 | ||
| + | * Sales hat = (5.01234 + 4.43573) + 0.10417 * Advertising 이 됩니다. | ||
| + | * y.hat = 9.44807 + 0.10417 * Advertising | ||
| + | |||
| + | 세번째 Medium일 경우는 | ||
| * 5.01234에 (1) 1.59511을 (3) 더한 것이 ShleveLoc Medium 의 효과로 | * 5.01234에 (1) 1.59511을 (3) 더한 것이 ShleveLoc Medium 의 효과로 | ||
| * Sales hat = (5.01234 + 1.59511) 이고 여기에 Advertising의 interaction을 고려하면 여기에 (6)을 고려해서 | * Sales hat = (5.01234 + 1.59511) 이고 여기에 Advertising의 interaction을 고려하면 여기에 (6)을 고려해서 | ||
| - | * Sales hat = (5.01234 + 1.59511) + 0.10692 이 되겠습니다. | + | * Sales hat = (5.01234 + 1.59511) + 0.10692 |
| + | * y.hat = 6.60745 + 0.10692*Advertising | ||
| - | 세번째 Good일 경우는 | ||
| - | * Sales hat = (5.01234 + 4.43573) 이고 여기에 Advertising의 interaction을 고려하면 | ||
| - | * Sales hat = (5.01234 + 4.43573) + 0.10417 이 됩니다. | ||
| 그런데 Advertising 과의 상호작용 때문에 증가하는 양이 비슷비슷합니다. 이것을 그래프로 그리면 | 그런데 Advertising 과의 상호작용 때문에 증가하는 양이 비슷비슷합니다. 이것을 그래프로 그리면 | ||
| + | |||
| < | < | ||
| > plot(ShelveLoc, | > plot(ShelveLoc, | ||
multiple_regression_exercise.1761794932.txt.gz · Last modified: by hkimscil
