User Tools

Site Tools


multiple_regression_exercise

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
multiple_regression_exercise [2021/11/25 20:35] – [개인과제 2] hkimscilmultiple_regression_exercise [2022/11/02 23:41] – [예] hkimscil
Line 151: Line 151:
  
 <code> <code>
 +# install.packages("ISLR")
 +library(ISLR)
 +
 head(Carseats) head(Carseats)
 str(Carseats) str(Carseats)
Line 389: Line 392:
 아래는 설명을 하지 않고 코드만 적었었는데 이는 아래 둘의 model이 동일한 것임을 보여주기 위한 것입니다. 아래는 설명을 하지 않고 코드만 적었었는데 이는 아래 둘의 model이 동일한 것임을 보여주기 위한 것입니다.
 <code> <code>
-lm.2 <- lm(Sales ~ Advertising:ShelveLoc, data = Carseats) ------- (1)   +lm.2 <- lm(Sales ~ Advertising:ShelveLoc, data = Carseats) ------- (1)   
-lm.1 <- lm(Sales ~ Advertising + Advertising:ShelveLoc, data = Carseats) ------- (2)  +lm.1 <- lm(Sales ~ Advertising + Advertising:ShelveLoc, data = Carseats) ------- (2)  
 </code> </code>
  
Line 469: Line 472:
 Coefficients: Coefficients:
                             Estimate Std. Error t value Pr(>|t|)                                 Estimate Std. Error t value Pr(>|t|)    
-(Intercept)                  5.01234    0.31932  15.697  < 2e-16 ***       (1) +(Intercept)                  5.01234    0.31932  15.697  < 2e-16 ***    # (1) 
-ShelveLocGood                4.43573    0.48146   9.213  < 2e-16 ***       (2) +ShelveLocGood                4.43573    0.48146   9.213  < 2e-16 ***    # (2) 
-ShelveLocMedium              1.59511    0.38378   4.156 3.97e-05 ***       (3) +ShelveLocMedium              1.59511    0.38378   4.156 3.97e-05 ***    # (3) 
-ShelveLocBad:Advertising     0.08210    0.03570   2.300  0.02198 *         (4) +ShelveLocBad:Advertising     0.08210    0.03570   2.300  0.02198 *      # (4) 
-ShelveLocGood:Advertising    0.10417    0.03607   2.888  0.00409 **        (5) +ShelveLocGood:Advertising    0.10417    0.03607   2.888  0.00409 **     # (5) 
-ShelveLocMedium:Advertising  0.10692    0.02280   4.689 3.78e-06 ***       (6)+ShelveLocMedium:Advertising  0.10692    0.02280   4.689 3.78e-06 ***    # (6)
 --- ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Line 519: Line 522:
  
 그러니 이렇게 보아도 마찬가지임을 알 수 있죠? 그러니 이렇게 보아도 마찬가지임을 알 수 있죠?
-====== Discussion 3 ======+====== 개인과제 1 ======
 {{:d.yyk.csv}} {{:d.yyk.csv}}
 <code> <code>
Line 744: Line 747:
 # http://commres.net/wiki/_detail/pasted/20201201-170048.png?id=multiple_regression_exercise # http://commres.net/wiki/_detail/pasted/20201201-170048.png?id=multiple_regression_exercise
 # #
-# b + c + d 에 해당하는 부분입니다. 즉+# b + c + d 에 해당하는 부분입니다. 즉 두 변인의 
 +# 설명력을 보여주는 부분인 lm.c1에서의 
 # R 제곱은 b + c + d / a + b + c + d 입니다.  # R 제곱은 b + c + d / a + b + c + d 입니다. 
  
Line 753: Line 757:
 library(ppcor) library(ppcor)
 attach(Carseats) attach(Carseats)
-spcor.Price <- spcor.test(Price, Sales, CompPrice) +spcor.Price <- spcor.test(Sales, Price, CompPrice) 
-spcor.CompPrice <- spcor.test(CompPrice, Sales, Price)+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 786: Line 799:
 # 여러분의 생각 후에 mediator 분석에 대해서 # 여러분의 생각 후에 mediator 분석에 대해서
 # 설명을 하도록 하겠습니다.  # 설명을 하도록 하겠습니다. 
- 
- 
- 
    
 </code> </code>
    
 +--> 
 +[[:Suppressor in Multiple Regression]]
 ====== Making Questionnaire ====== ====== Making Questionnaire ======
 [[https://eclass2.ajou.ac.kr/webapps/discussionboard/do/forum?action=list_threads&course_id=_47711_1&nav=discussion_board_entry&conf_id=_52871_1&forum_id=_55560_1|Questions]] you submit at the ajoubb. [[https://eclass2.ajou.ac.kr/webapps/discussionboard/do/forum?action=list_threads&course_id=_47711_1&nav=discussion_board_entry&conf_id=_52871_1&forum_id=_55560_1|Questions]] you submit at the ajoubb.
multiple_regression_exercise.txt · Last modified: 2023/12/10 21:41 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki