User Tools

Site Tools


multiple_regression_examples

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
multiple_regression_examples [2019/11/01 13:11] – [Backward elimination] hkimscilmultiple_regression_examples [2023/10/21 13:26] (current) hkimscil
Line 1: Line 1:
-====== Multiple Regression with Two Predictor Variables ======+====== Multiple Regression e.gs. ====== 
 +====== E.g. 1 ====== 
 +{{:d.yyk.csv}} 
 +<code> 
 +d.yyk <- read.csv("http://commres.net/wiki/_media/d.yyk.csv"
 +d.yyk 
 +d.yyk <- subset(d.yyk, select = -c(1)) 
 +d.yyk 
 +</code> 
 +<code> 
 +> d.yyk <- subset(d.yyk, select = -c(1)) 
 +> d.yyk 
 +    bmi stress happiness 
 +1  15.1      2         4 
 +2  15.3      2         4 
 +3  16.4      1         5 
 +4  16.3      2         4 
 +5  17.5      2         3 
 +6  18.8      2         4 
 +7  19.2      2         3 
 +8  20.3      1         4 
 +9  21.3      1         4 
 +10 21.3      2         4 
 +11 22.4      2         5 
 +12 23.5      2         5 
 +13 23.7      2         4 
 +14 24.2      3         3 
 +15 24.3      3         3 
 +16 25.6      2         3 
 +17 26.4      3         3 
 +18 26.4      3         2 
 +19 26.4      3         2 
 +20 27.5      3         3 
 +21 28.6      3         2 
 +22 28.2      4         2 
 +23 31.3      3         2 
 +24 32.1      4         1 
 +25 33.1      4         1 
 +26 33.2      5         1 
 +27 34.4      5         1 
 +28 35.8      5         1 
 +29 36.1      5         1 
 +30 38.1      5         1 
 +</code> 
 +우선 여기에서 종속변인인 (dv) happiness에 bmi와 stress를 리그레션 해본다.  
 +<code> 
 +attach(d.yyk) 
 +lm.happiness.bmistress <- lm(happiness ~ bmi + stress, data=d.yyk) 
 +summary(lm.happiness.bmistress) 
 +anova(lm.happiness.bmistress) 
 +</code> 
 + 
 +<code> 
 +> attach(d.yyk) 
 +> lm.happiness.bmistress <- lm(happiness ~ bmi + stress, data=d.yyk) 
 +> summary(lm.happiness.bmistress) 
 + 
 +Call: 
 +lm(formula = happiness ~ bmi + stress, data = d.yyk) 
 + 
 +Residuals: 
 +     Min       1Q   Median       3Q      Max  
 +-0.89293 -0.40909  0.08816  0.29844  1.46429  
 + 
 +Coefficients: 
 +            Estimate Std. Error t value Pr(>|t|)     
 +(Intercept)  6.29098    0.50779  12.389 1.19e-12 *** 
 +bmi         -0.05954    0.03626  -1.642  0.11222     
 +stress      -0.67809    0.19273  -3.518  0.00156 **  
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 + 
 +Residual standard error: 0.5869 on 27 degrees of freedom 
 +Multiple R-squared:  0.8217, Adjusted R-squared:  0.8085  
 +F-statistic: 62.22 on 2 and 27 DF,  p-value: 7.76e-11 
 +
 +>  
 +> anova(lm.happiness.bmistress) 
 +Analysis of Variance Table 
 + 
 +Response: happiness 
 +          Df Sum Sq Mean Sq F value    Pr(>F)     
 +bmi        1 38.603  38.603 112.070 4.124e-11 *** 
 +stress      4.264   4.264  12.378  0.001558 **  
 +Residuals 27  9.300   0.344                       
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 +>  
 + 
 +</code> 
 + 
 +위의 분석을 보면  
 +R<sup>2</sup> = 0.8217, F (2, 27) = 62.77, p = 7.76e-11 
 + 
 +그러나, coefficient 값을 보면 bmi는 significant 하지 않고, stress는 significant하다. 이는 R제곱에 영향을 주는 것으로 stress가 주이고 bmi의 영향력은 미미하다고 하다는 결론을 내리도록 해준다. 그러나, [[:multiple regression]]에서 언급한 것처럼 독립변인이 두 개 이상일 때에는 무엇이 얼마나 종속변인에 영향을 주는지 그림을 그릴 수 있어야 하므로, 아래와 같이 bmi만을 가지고 regression을 다시 해본다. 
 + 
 +<code> 
 +lm.happiness.bmi <- lm(happiness ~ bmi, data=d.yyk) 
 +summary(lm.happiness.bmi) 
 +anova(lm.happiness.bmi) 
 +</code> 
 + 
 +<code> 
 +> lm.happiness.bmi <- lm(happiness ~ bmi, data=d.yyk) 
 +>  
 +> summary(lm.happiness.bmi) 
 + 
 +Call: 
 +lm(formula = happiness ~ bmi, data = d.yyk) 
 + 
 +Residuals: 
 +     Min       1Q   Median       3Q      Max  
 +-1.20754 -0.49871 -0.03181  0.35669  1.83265  
 + 
 +Coefficients: 
 +            Estimate Std. Error t value Pr(>|t|)     
 +(Intercept)  7.24143    0.50990  14.202 2.54e-14 *** 
 +bmi         -0.17337    0.01942  -8.927 1.11e-09 *** 
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 + 
 +Residual standard error: 0.696 on 28 degrees of freedom 
 +Multiple R-squared:   0.74, Adjusted R-squared:  0.7307  
 +F-statistic: 79.69 on 1 and 28 DF,  p-value: 1.109e-09 
 + 
 +> anova(lm.happiness.bmi) 
 +Analysis of Variance Table 
 + 
 +Response: happiness 
 +          Df Sum Sq Mean Sq F value    Pr(>F)     
 +bmi        1 38.603  38.603  79.687 1.109e-09 *** 
 +Residuals 28 13.564   0.484                       
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 +>  
 +</code> 
 +놀랍게도 bmi 하나만을 가지고 regression을 했더니, R제곱 값이 .74이었다 (F(1,28) = 79.69, p = 1.109e-09). 이런 결과가 나올 수 있는 이유는 독립변인인 bmi와 stress 간의 상관관계가 높아서 처음 분석에서 그 영향력을 (설명력, R제곱에 기여하는 부분을) 하나의 독립변인이 모두 가졌갔기 때문이라고 생각할 수 있다. 이 경우에는 그 독립변인이 stress이다.  
 + 
 +happiness에 stress 만을 regression 해본 결과는 아래와 같다.  
 + 
 +<code> 
 +lm.happiness.stress <- lm(happiness ~ stress, data = d.yyk) 
 +summary(lm.happiness.stress) 
 +anova(lm.happiness.stress) 
 +</code> 
 + 
 +<code> 
 +> lm.happiness.stress <- lm(happiness ~ stress, data = d.yyk) 
 +> summary(lm.happiness.stress) 
 + 
 +Call: 
 +lm(formula = happiness ~ stress, data = d.yyk) 
 + 
 +Residuals: 
 +    Min      1Q  Median      3Q     Max  
 +-0.7449 -0.6657  0.2155  0.3343  1.3343  
 + 
 +Coefficients: 
 +            Estimate Std. Error t value Pr(>|t|)     
 +(Intercept)  5.58651    0.27965   19.98  < 2e-16 *** 
 +stress      -0.96041    0.08964  -10.71 2.05e-11 *** 
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 + 
 +Residual standard error: 0.6044 on 28 degrees of freedom 
 +Multiple R-squared:  0.8039, Adjusted R-squared:  0.7969  
 +F-statistic: 114.8 on 1 and 28 DF,  p-value: 2.053e-11 
 + 
 +> anova(lm.happiness.stress) 
 +Analysis of Variance Table 
 + 
 +Response: happiness 
 +          Df Sum Sq Mean Sq F value    Pr(>F)     
 +stress     1 41.938  41.938   114.8 2.053e-11 *** 
 +Residuals 28 10.229   0.365                       
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 +>  
 +>  
 +</code> 
 +R제곱값은 0.80로 (F(1, 28) = 114.8, 2.053e-11) 스트레스만으로도 significant한 결과를 갖는다.  
 + 
 +그렇다면 stress 와 bmi가 공통으로 기여하는 부분을 뺀 순수 기여분은 어떻게 될까? 즉, 위의 .80 부분 중 bmi와 공통으로 기여하는 부분을 제외한 나머지는 얼마일까? 보통 이와 같은 작업을 bmi의 (다른 독립변인의) 영향력을 제어하고 (control) 순수기여분만을 살펴본다고 이야기 한다.  
 + 
 +===== 방법 1 ===== 
 +이를 위해서 아래를 계획, 수행해본다.  
 + 
 +  - 각각의 독립변인이 고유하게 미치는 영향력은 (설명력은) 무엇인지를 본다.  
 +  - 공통설명력은 얼마나 되는지 본다. 
 + 
 +  - 1을 위해서는 각 독립변인과 종속변인인 happiness의 semi-partial correlation값을 구해서 제곱해보면 되겠다.  
 +  - 2를 위해서는 두 독립변인을 써서 구했던 r 제곱값에서 위의 1에서 구한 제곱값들을 제외한 나머지를 보면 된겠다.  
 + 
 +  * 결론을 내기 위한 계획을 세우고 실행한다.  
 +  * 이는 아래와 같이 정리할 수 있다 
 + 
 +{{:pasted:20201201-170048.png}} 
 + 
 +===== 각각의 독립변인이 고유하게 미치는 영향력은 (설명력은) 무엇인지를 본다 ===== 
 +<code> 
 +> spcor(d.yyk) 
 +$estimate 
 +                 bmi     stress  happiness 
 +bmi        1.0000000  0.2730799 -0.1360657 
 +stress     0.2371411  1.0000000 -0.2532032 
 +happiness -0.1334127 -0.2858909  1.0000000 
 + 
 +$p.value 
 +                bmi    stress happiness 
 +bmi       0.0000000 0.1517715 0.4815643 
 +stress    0.2154821 0.0000000 0.1850784 
 +happiness 0.4902316 0.1327284 0.0000000 
 + 
 +$statistic 
 +                 bmi    stress  happiness 
 +bmi        0.0000000  1.475028 -0.7136552 
 +stress     1.2684024  0.000000 -1.3600004 
 +happiness -0.6994855 -1.550236  0.0000000 
 + 
 +$n 
 +[1] 30 
 + 
 +$gp 
 +[1] 1 
 + 
 +$method 
 +[1] "pearson" 
 + 
 +>  
 +>  
 +</code> 
 +happiness에 영향을 주는 변인을 보는 것이므로  
 +<code> 
 +                 bmi    stress 
 +happiness -0.1334127 -0.2858909   
 +</code> 
 +를 본다. 그리고 이 값의 제곱값이 각 독립변인의 고유 설명력이다.  
 +<code> 
 +> (-0.1334127)^2  
 +[1] 0.01779895 
 +> (-0.2858909)^2 
 +[1] 0.08173361 
 +>  
 +</code> 
 +즉, '' stress: 8.1% '' 와 '' bmi: 1.78% '' 만이 독립변인의 고유영향력이고 이를 제외한 '' 82.17 - (9.88) = 72.29 '' 가 공통영향력이라고 하겠다. 
 + 
 +이를 파티션을 하면서 직접 살펴보려면  
 +  * 우선 $\frac{b}{a+b+c+d}$ 를 보려고 한다.  
 +  * 그림에서 m.bmi <- lm((a+b+c+d)~(b+e)) 와 같이 한후에 r제곱값을 보고, sqrt 하면 r값을 알 수 있다.  
 +  * b+e를 구하려면 lm(bmi~stress)를 한후, 그 residual을 보면 된다. 
 +  * a+b+c+d 는 happiness 그 자체이다.  
 + 
 +<code> 
 +m.bmi <- lm(bmi ~ stress) 
 +mod <- lm(happiness ~ resid(m.bmi)) 
 +summary(mod) 
 +</code> 
 +<code> 
 +> m.bmi <- lm(bmi ~ stress) 
 +> mod <- lm(happiness ~ resid(m.bmi)) 
 +> summary(mod) 
 + 
 +Call: 
 +lm(formula = happiness ~ resid(m.bmi)) 
 + 
 +Residuals: 
 +     Min       1Q   Median       3Q      Max  
 +-1.97283 -0.94440  0.05897  0.97961  2.29664  
 + 
 +Coefficients: 
 +             Estimate Std. Error t value Pr(>|t|)     
 +(Intercept)   2.83333    0.24698  11.472 4.27e-12 *** 
 +resid(m.bmi) -0.05954    0.08358  -0.712    0.482     
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 + 
 +Residual standard error: 1.353 on 28 degrees of freedom 
 +Multiple R-squared:  0.0178, Adjusted R-squared:  -0.01728  
 +F-statistic: 0.5074 on 1 and 28 DF,  p-value: 0.4822 
 +</code> 
 + 
 +위의 분석에서 R-square 값인 0.0178 이 bmi의 고유의 설명력이다. r값은 sqrt(0.0178)이다. 그리고, 위의 모델은 significant하지 않음을 주목한다.  
 + 
 +다음으로 $\frac {d}{a+b+c+d}$을 구해서 stress 고유설명력을 본다. 이제는  
 +<code> 
 +m.stress <- lm(stress ~ bmi) 
 +mod2 <- lm(happiness ~ resid(m.stress)) 
 +sumary(mod2) 
 +</code> 
 + 
 +<code> 
 +> m.stress <- lm(stress ~ bmi) 
 +> mod2 <- lm(happiness ~ resid(m.stress)) 
 +> summary(mod2) 
 + 
 +Call: 
 +lm(formula = happiness ~ resid(m.stress)) 
 + 
 +Residuals: 
 +    Min      1Q  Median      3Q     Max  
 +-1.9383 -1.2297  0.2170  0.9804  1.9284  
 + 
 +Coefficients: 
 +                Estimate Std. Error t value Pr(>|t|)     
 +(Intercept)       2.8333     0.2388  11.865 1.95e-12 *** 
 +resid(m.stress)  -0.6781     0.4295  -1.579    0.126     
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 + 
 +Residual standard error: 1.308 on 28 degrees of freedom 
 +Multiple R-squared:  0.08173, Adjusted R-squared:  0.04894  
 +F-statistic: 2.492 on 1 and 28 DF,  p-value: 0.1256 
 + 
 +>  
 +</code> 
 +Multiple R-squared 인 0.08173 이 고유 설명력이고, 이 또한 significant 하지 않다.  
 +0.08173 값과 0.0178을 더한 값을 제외한 lm(happiness~bmi+stress) 에서의 R-squared 값이 공통설명력이 된다. 아래의 분석 결과에서 Multiple R-squared:  0.8217 이 두 변인을 모두 합한 설명력이다.  
 + 
 +<code> 
 +m.both <- lm(happiness~bmi+stress) 
 +summary(m.both) 
 +</code> 
 +<code> 
 +> m.both <- lm(happiness~bmi+stress) 
 +> summary(m.both) 
 + 
 +Call: 
 +lm(formula = happiness ~ bmi + stress) 
 + 
 +Residuals: 
 +     Min       1Q   Median       3Q      Max  
 +-0.89293 -0.40909  0.08816  0.29844  1.46429  
 + 
 +Coefficients: 
 +            Estimate Std. Error t value Pr(>|t|)     
 +(Intercept)  6.29098    0.50779  12.389 1.19e-12 *** 
 +bmi         -0.05954    0.03626  -1.642  0.11222     
 +stress      -0.67809    0.19273  -3.518  0.00156 **  
 +--- 
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 + 
 +Residual standard error: 0.5869 on 27 degrees of freedom 
 +Multiple R-squared:  0.8217, Adjusted R-squared:  0.8085  
 +F-statistic: 62.22 on 2 and 27 DF,  p-value: 7.76e-11 
 +</code> 
 + 
 +이 값은 0.72217 이다.  
 +<code> 
 +> 0.8217- (0.08173 + 0.0178) 
 +[1] 0.72217 
 +>  
 +</code> 
 + 
 +bmi나 stress 중 하나를 IV로 취하는 것이 좋다는 결론을 내린다. 
 + 
 + 
 +====== with Two Predictor Variables ======
 data file: {{:mlt06.sav}} from http://www.psychstat.missouristate.edu/multibook/mlt06.htm \\ data file: {{:mlt06.sav}} from http://www.psychstat.missouristate.edu/multibook/mlt06.htm \\
  
Line 1140: Line 1496:
  
 <code> <code>
-drop1(update(lm.full, ~. - Population -Urban -Age), test="F")+drop1(update(lm.full, ~. - Population -Urban -Education), test="F")
 </code> </code>
  
 <code> <code>
-> drop1(update(lm.full, ~. - Population -Urban -Age), test="F")+> drop1(update(lm.full, ~. - Population -Urban -Education), test="F")
 Single term deletions Single term deletions
  
 Model: Model:
 Sales ~ CompPrice + Income + Advertising + Price + ShelveLoc +  Sales ~ CompPrice + Income + Advertising + Price + ShelveLoc + 
-    Education + US +    Age + US 
-            Df Sum of Sq     RSS    AIC  F value    Pr(>F)     +            Df Sum of Sq     RSS    AIC   F value Pr(>F)     
-<none>                    621.91 194.53                        +<none>                    405.76  23.72                      
-CompPrice    1    564.18 1186.09 450.78 354.7079 2.2e-16 *** +CompPrice    1    525.25  931.00 353.92  506.1421 <2e-16 *** 
-Income           79.50  701.41 240.65  49.9855 7.173e-12 *** +Income           77.87  483.62  91.94   75.0336 <2e-16 *** 
-Advertising  1    153.44  775.35 280.74  96.4697 2.2e-16 *** +Advertising  1    145.30  551.06 144.15  140.0181 <2e-16 *** 
-Price        1   1269.23 1891.14 637.39 797.9785 2.2e-16 *** +Price        1   1322.83 1728.58 601.44 1274.7123 <2e-16 *** 
-ShelveLoc    2   1044.29 1666.20 584.73 328.2785 2.2e-16 *** +ShelveLoc    2   1056.88 1462.64 532.61  509.2202 <2e-16 *** 
-Education    1      1.82  623.73 193.70   1.1441    0.2854     +Age             217.97  623.73 193.70  210.0409 <2e-16 *** 
-US                3.10  625.01 194.52   1.9520    0.1632    +US                1.63  407.39  23.32    1.5693 0.2111    
 --- ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  
-</code>+</code>
  
 <code> <code>
-drop1(update(lm.full, ~. - Population -Urban -Age -Education), test="F")+drop1(update(lm.full, ~. - Population -Urban -Education -US), test="F")
 </code> </code>
  
-<code>> drop1(update(lm.full, ~. - Population -Urban -Age -Education), test="F")+<code> 
 +> drop1(update(lm.full, ~. - Population -Urban -Education -US), test="F")
 Single term deletions Single term deletions
  
 Model: Model:
 Sales ~ CompPrice + Income + Advertising + Price + ShelveLoc +  Sales ~ CompPrice + Income + Advertising + Price + ShelveLoc + 
-    US+    Age
             Df Sum of Sq     RSS    AIC  F value    Pr(>F)                 Df Sum of Sq     RSS    AIC  F value    Pr(>F)    
-<none>                    623.73 193.70                        +<none>                    407.39  23.32                        
-CompPrice    1    563.11 1186.84 449.03 353.9060 < 2.2e-16 *** +CompPrice    1    523.83  931.22 352.01  504.047 < 2.2e-16 *** 
-Income           80.89  704.61 240.47  50.8352  4.87e-12 *** +Income           76.68  484.07  90.30   73.784 < 2.2e-16 *** 
-Advertising  1    152.60  776.32 279.24  95.9043 < 2.2e-16 *** +Advertising  1    234.03  641.42 202.89  225.192 < 2.2e-16 *** 
-Price        1   1269.21 1892.94 635.77 797.6724 < 2.2e-16 *** +Price        1   1324.42 1731.81 600.18 1274.400 < 2.2e-16 *** 
-ShelveLoc    2   1047.48 1671.20 583.93 329.1585 < 2.2e-16 *** +ShelveLoc    2   1055.51 1462.90 530.68  507.822 < 2.2e-16 *** 
-US                2.78  626.51 193.48   1.7498    0.1867    +Age             219.12  626.51 193.48  210.848 < 2.2e-16 ***
 --- ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 > </code> > </code>
  
-<code>drop1(update(lm.full, ~. - Population -Urban -Age -Education -US), test="F")</code> 
  
-<code>> drop1(update(lm.full, ~. - Population -Urban -Age -Education -US)test="F"+<WRAP group> 
-Single term deletions+<WRAP half column> 
 +<code>lm.fit.be <lm(Sales ~  
 +            CompPrice + Income +  
 +            Advertising + Price +  
 +            ShelveLoc + Age, data Carseats
 +             
 +summary(lm.fit.be) 
 +</code>
  
-Model+<code> 
-Sales ~ CompPrice + Income + Advertising + Price + ShelveLoc +> lm.fit.be <- lm(Sales ~ CompPrice +  
-            Df Sum of Sq     RSS    AIC F value    Pr(>F)     +        Income + Advertising +  
-<none>                    626.51 193.48                       +        Price + ShelveLoc +  
-CompPrice       561.07 1187.58 447.28 351.948 2.2e-16 *** +        Age, data = Carseats) 
-Income       1     79.20  705.72 239.10  49.683 8.164e-12 *** +> summary(lm.fit.be) 
-Advertising     235.25  861.76 319.01 147.570 2.2e-16 *** + 
-Price          1270.95 1897.46 634.72 797.246 2.2e-16 *** +Call
-ShelveLoc      1045.39 1671.90 582.10 327.877 2.2e-16 ***+lm(formula = Sales ~ CompPrice + Income + Advertising + Price +  
 +    ShelveLoc + Age, data = Carseats) 
 + 
 +Residuals: 
 +    Min      1Q  Median      3Q     Max  
 +-2.7728 -0.6954  0.0282  0.6732  3.3292  
 + 
 +Coefficients: 
 +                 Estimate Std. Error t value Pr(>|t|)     
 +(Intercept)      5.475226   0.505005   10.84   <2e-16 *** 
 +CompPrice        0.092571   0.004123   22.45   <2e-16 *** 
 +Income           0.015785   0.001838    8.59   <2e-16 *** 
 +Advertising      0.115903   0.007724   15.01   <2e-16 *** 
 +Price           -0.095319   0.002670  -35.70   <2e-16 *** 
 +ShelveLocGood    4.835675   0.152499   31.71   <2e-16 *** 
 +ShelveLocMedium  1.951993   0.125375   15.57   <2e-16 *** 
 +Age             -0.046128   0.003177  -14.52   <2e-16 ***
 --- ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
- 
-> </code> 
  
-<code>lm.fit.be <lm(Sales ~ CompPrice + Income + Advertising + Price + ShelveLocdata = Carseats)</code>+Residual standard error: 1.019 on 392 degrees of freedom 
 +Multiple R-squared:  0.872, Adjusted R-squared:  0.8697  
 +F-statistic: 381.4 on 7 and 392 DF p-value: 2.2e-16
  
-cf.+>  
 +</code> 
 +</WRAP> 
 + 
 +<WRAP half column>
 <code> <code>
-lm.fit.01 <- lm(Sales ~ CompPrice + Income + Advertising + Price + ShelveLoc + Age, data = Carseats)+lm.fit.01 <- lm(formula = Sales ~  
 +                 CompPrice + Income +  
 +                 Advertising + Price +  
 +                 ShelveLoc + Age,  
 +                 data = Carseats
 +summary(lm.fit.01)
 </code> </code>
  
 <code> <code>
-> lm.fit.be <- lm(Sales ~ CompPrice + Income + Advertising + Price + ShelveLoc, data=Carseats) +> lm.fit.01 <- lm(formula = Sales ~ CompPrice +  
-> summary(lm.fit.be)+         Income + Advertising + Price +  
 +         ShelveLoc + Age, data = Carseats) 
 +> summary(lm.fit.01)
  
 Call: Call:
 lm(formula = Sales ~ CompPrice + Income + Advertising + Price +  lm(formula = Sales ~ CompPrice + Income + Advertising + Price + 
-    ShelveLoc, data = Carseats)+    ShelveLoc + Age, data = Carseats)
  
 Residuals: Residuals:
     Min      1Q  Median      3Q     Max      Min      1Q  Median      3Q     Max 
--3.7962 -0.9251  0.0043  0.8457  4.4179 +-2.7728 -0.6954  0.0282  0.6732  3.3292 
  
 Coefficients: Coefficients:
                  Estimate Std. Error t value Pr(>|t|)                      Estimate Std. Error t value Pr(>|t|)    
-(Intercept)      2.431262   0.569032   4.273 2.43e-05 *** +(Intercept)      5.475226   0.505005   10.84   <2e-16 *** 
-CompPrice        0.095676   0.005100  18.760  < 2e-16 *** +CompPrice        0.092571   0.004123   22.45   <2e-16 *** 
-Income           0.016042   0.002276   7.049 8.16e-12 *** +Income           0.015785   0.001838    8.59   <2e-16 *** 
-Advertising      0.116205   0.009566  12.148  < 2e-16 *** +Advertising      0.115903   0.007724   15.01   <2e-16 *** 
-Price           -0.093241   0.003302 -28.236  < 2e-16 *** +Price           -0.095319   0.002670  -35.70   <2e-16 *** 
-ShelveLocGood    4.797696   0.188847  25.405  < 2e-16 *** +ShelveLocGood    4.835675   0.152499   31.71   <2e-16 *** 
-ShelveLocMedium  1.849895   0.155037  11.932  < 2e-16 ***+ShelveLocMedium  1.951993   0.125375   15.57   <2e-16 *** 
 +Age             -0.046128   0.003177  -14.52   <2e-16 ***
 --- ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  
-Residual standard error: 1.263 on 393 degrees of freedom +Residual standard error: 1.019 on 392 degrees of freedom 
-Multiple R-squared:  0.8031, Adjusted R-squared:  0.8001  +Multiple R-squared:  0.872, Adjusted R-squared:  0.8697  
-F-statistic: 267.on and 393 DF,  p-value: < 2.2e-16+F-statistic: 381.on and 392 DF,  p-value: < 2.2e-16
  
- 
 </code> </code>
 +</WRAP>
 +</WRAP>
 +
 +
 +
multiple_regression_examples.1572581488.txt.gz · Last modified: 2019/11/01 13:11 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki