suppressor_in_multiple_regression
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| suppressor_in_multiple_regression [2023/10/23 11:10] – hkimscil | suppressor_in_multiple_regression [2025/11/11 01:09] (current) – hkimscil | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| < | < | ||
| - | # 개인과제와 관련된 코드입니다. | ||
| # Carseats 데이터 분석입니다. 새로 시작하면 | # Carseats 데이터 분석입니다. 새로 시작하면 | ||
| - | # 만약에 ISLR이 install도 안되어 | + | # 만약에 ISLR이 install도 안되어 있으면 |
| - | # 있으면 | + | # install.packages(" |
| - | install.packages(" | + | |
| library(ISLR) | library(ISLR) | ||
| Line 472: | Line 470: | ||
| > | > | ||
| </ | </ | ||
| + | ====== 도식화 ====== | ||
| + | {{pasted: | ||
| + | < | ||
| + | lm.y.x2 <- lm(y ~ x2) | ||
| + | summary(lm.y.x2)$r.squared = 0 | ||
| + | lm.y.x1 <- lm(y ~ x1) | ||
| + | summary(lm.y.x1)$r.squared = a, p > .05 (may be not significant) | ||
| + | # 그러나 아래처럼 x2가 포함됨으로써 | ||
| + | # x1 내의 x2와 관련된 부분이 제거되어 | ||
| + | # 분석됨으로 significant하게 됨 | ||
| + | lm.y.x1x2 <- lm(y ~ x1 + x2) | ||
| + | summary(lm.y.x1)$r.squared = a | ||
| + | </ | ||
| + | < | ||
| + | > cor(cs.dat) | ||
| + | Sales CompPrice | ||
| + | Sales 1.00000000 0.06407873 -0.4449507 | ||
| + | CompPrice | ||
| + | Price | ||
| + | |||
| + | > lm.y.x1 <- lm(Sales~Price, | ||
| + | > lm.y.x2 <- lm(Sales~CompPrice, | ||
| + | > lm.y.x1x2 <- lm(Sales~Price+CompPrice, | ||
| + | > summary(lm.y.x1)$r.squared | ||
| + | [1] 0.1979812 | ||
| + | > summary(lm.y.x1x2)$r.squared | ||
| + | [1] 0.3578332 | ||
| + | > summary(lm.y.x1x2)$r.squared - summary(lm.y.x1)$r.squared | ||
| + | [1] 0.159852 | ||
| + | > | ||
| + | > summary(lm.y.x2)$r.squared | ||
| + | [1] 0.004106084 | ||
| + | > lm.x1.x2 <- lm(Price~CompPrice, | ||
| + | > res.x1x2 <- lm.x1.x2$residuals | ||
| + | > lm.y.onlyx1< | ||
| + | > summary(lm.y.onlyx1)$r.squared | ||
| + | [1] 0.3537271 | ||
| + | > summary(lm.y.x1x2)$r.squared | ||
| + | [1] 0.3578332 | ||
| + | > | ||
| + | > summary(lm.y.x1x2)$r.squared - summary(lm.y.onlyx1)$r.squared | ||
| + | [1] 0.004106084 | ||
| + | > | ||
| + | > | ||
| + | > summary(lm.y.x1)$r.squared | ||
| + | [1] 0.1979812 | ||
| + | > | ||
| + | > summary(lm.y.x1)$r.squared | ||
| + | [1] 0.1979812 | ||
| + | > pcor.test(Sales, | ||
| + | estimate | ||
| + | 1 -0.5959744 9.95161e-40 -14.78787 400 1 pearson | ||
| + | > pcor.test(Sales, | ||
| + | [1] 0.3551855 | ||
| + | > summary(lm.y.x2)$r.squared | ||
| + | [1] 0.004106084 | ||
| + | > | ||
| + | </ | ||
suppressor_in_multiple_regression.1698059456.txt.gz · Last modified: by hkimscil
