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 [2021/11/25 20:33] – [개인과제 2] hkimscil | multiple_regression_exercise [2023/12/10 21:41] (current) – old revision restored (2022/11/02 23:41) hkimscil | ||
---|---|---|---|
Line 151: | Line 151: | ||
< | < | ||
+ | # install.packages(" | ||
+ | library(ISLR) | ||
+ | |||
head(Carseats) | head(Carseats) | ||
str(Carseats) | str(Carseats) | ||
Line 389: | Line 392: | ||
아래는 설명을 하지 않고 코드만 적었었는데 이는 아래 둘의 model이 동일한 것임을 보여주기 위한 것입니다. | 아래는 설명을 하지 않고 코드만 적었었는데 이는 아래 둘의 model이 동일한 것임을 보여주기 위한 것입니다. | ||
< | < | ||
- | lm.2 <- lm(Sales ~ Advertising: | + | lm.2 <- lm(Sales ~ Advertising: |
- | lm.1 <- lm(Sales ~ Advertising + Advertising: | + | lm.1 <- lm(Sales ~ Advertising + Advertising: |
</ | </ | ||
Line 469: | Line 472: | ||
Coefficients: | Coefficients: | ||
Estimate Std. Error t value Pr(> | Estimate Std. Error t value Pr(> | ||
- | (Intercept) | + | (Intercept) |
- | ShelveLocGood | + | ShelveLocGood |
- | ShelveLocMedium | + | ShelveLocMedium |
- | ShelveLocBad: | + | ShelveLocBad: |
- | ShelveLocGood: | + | ShelveLocGood: |
- | ShelveLocMedium: | + | ShelveLocMedium: |
--- | --- | ||
Signif. codes: | Signif. codes: | ||
Line 519: | Line 522: | ||
그러니 이렇게 보아도 마찬가지임을 알 수 있죠? | 그러니 이렇게 보아도 마찬가지임을 알 수 있죠? | ||
- | ====== | + | ====== |
{{: | {{: | ||
< | < | ||
Line 721: | Line 724: | ||
# 개인과제와 관련된 코드입니다. | # 개인과제와 관련된 코드입니다. | ||
# Carseats 데이터 분석입니다. 새로 시작하면 | # Carseats 데이터 분석입니다. 새로 시작하면 | ||
- | # 만약에 install도 안되어 있으면 | + | library(ISLR) |
+ | # 만약에 | ||
+ | # 있으면 | ||
# install.packages(" | # install.packages(" | ||
- | library(ISLR) | ||
? | ? | ||
str(Carseats) | str(Carseats) | ||
Line 740: | Line 744: | ||
# 0.3578 (35.78%) 임을 알 수 있습니다. | # 0.3578 (35.78%) 임을 알 수 있습니다. | ||
# 이는 우리가 흔히 쓰는 다이어그램에서 | # 이는 우리가 흔히 쓰는 다이어그램에서 | ||
- | # URL 제시 | + | # |
- | # b ) c + d 에 해당하는 부분입니다. 즉 | + | # http:// |
+ | # | ||
+ | # b + c + d 에 해당하는 부분입니다. 즉 두 변인의 | ||
+ | # 설명력을 보여주는 부분인 lm.c1에서의 | ||
# R 제곱은 b + c + d / a + b + c + d 입니다. | # R 제곱은 b + c + d / a + b + c + d 입니다. | ||
Line 750: | Line 757: | ||
library(ppcor) | library(ppcor) | ||
attach(Carseats) | attach(Carseats) | ||
- | spcor.Price <- spcor.test(Price, | + | spcor.Price <- spcor.test(Sales, Price, CompPrice) |
- | spcor.CompPrice <- spcor.test(CompPrice, | + | spcor.CompPrice <- spcor.test(Sales, CompPrice, Price) |
+ | |||
+ | spcor.Price | ||
+ | spcor.CompPrice | ||
# 위 둘의 아웃풋에서 estimate값은 | # 위 둘의 아웃풋에서 estimate값은 | ||
# semipartial correlation 값이므로 이를 | # semipartial correlation 값이므로 이를 | ||
# 제곱한 값은 각각 b와 d에 해당하는 | # 제곱한 값은 각각 b와 d에 해당하는 | ||
- | # 값입니다 | + | # 값입니다. 이를 더 자세히 이야기하면 |
+ | # b = b / a + b + c + d | ||
+ | # d = d / a + b + c + d | ||
+ | # 라는 이야기입니다. | ||
b <- spcor.Price$estimate^2 | b <- spcor.Price$estimate^2 | ||
d <- spcor.CompPrice$estimate^2 | d <- spcor.CompPrice$estimate^2 | ||
- | # 각 b와 d를 출력합니다. | + | # 각 b와 d를 출력해 봅니다. |
b | b | ||
d | d | ||
- | # 둘을 더해봅니다. | + | |
- | # 이 값은 0.3648334 | + | # 이 둘을 더해봅니다. |
+ | # 이 값은 0.5135791 입니다 | ||
b + d | b + d | ||
# 다시 아까 lm.c1의 R 제곱값은 | # 다시 아까 lm.c1의 R 제곱값은 | ||
summary(lm.c1)$r.squared | summary(lm.c1)$r.squared | ||
- | # 0.3648334 | + | # 0.3578332 |
# 다시 그림을 보면 | # 다시 그림을 보면 | ||
# R 제곱은 b + c + d 에 해당하는 | # R 제곱은 b + c + d 에 해당하는 | ||
# 것이라고 했고 | # 것이라고 했고 | ||
- | # semi-partial 값으로 b와 d를 | + | # semi-partial 값을 각각 구하여 |
- | # 각각 구한 것이 여기까지 | + | # 이를 제곱하여 더한 것이 b와 d입니다. |
- | # 그런데 그림을 보면 b + d > b + c + d 가 | + | # 그런데 그림을 보면 b + d > b + c + d 가 |
- | # 되어서는 안됩니다. 그런데 | + | # 됩니다. |
+ | # 이것은 말이 되지 않습니다. 그런데 | ||
# 계산값을 이를 가르키고 있습니다. | # 계산값을 이를 가르키고 있습니다. | ||
# 이 이유가 뭘까요? | # 이 이유가 뭘까요? | ||
Line 783: | Line 799: | ||
# 여러분의 생각 후에 mediator 분석에 대해서 | # 여러분의 생각 후에 mediator 분석에 대해서 | ||
# 설명을 하도록 하겠습니다. | # 설명을 하도록 하겠습니다. | ||
- | |||
- | |||
- | |||
</ | </ | ||
+ | --> | ||
+ | [[: | ||
====== Making Questionnaire ====== | ====== Making Questionnaire ====== | ||
[[https:// | [[https:// |
multiple_regression_exercise.txt · Last modified: 2023/12/10 21:41 by hkimscil