User Tools

Site Tools


regression

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
regression [2019/05/09 12:17] hkimscilregression [2019/05/20 08:50] – [e.g. Simple Regression] hkimscil
Line 187: Line 187:
  
 ^  __ prediction for y values with__ $\overline{Y}$  ^^^  ^  __ prediction for y values with__ $\overline{Y}$  ^^^ 
-| bankaccount   | error   | error<sup>2</sup>  |  +| bankaccount   | prediction  | error   | error<sup>2</sup>  |  
-| 6   | -2   | 4  |  +| 6   | 8  | -2   | 4  |  
-| 5   | -3   | 9  |  +| 5   | 8  | -3   | 9  |  
-| 7   | -1   | 1  |  +| 7   | 8  | -1   | 1  |  
-| 7   | -1   | 1  |  +| 7   | 8  | -1   | 1  |  
-| 8   | 0   | 0  |  +| 8   | 8  | 0   | 0  |  
-| 10   | 2   | 4  |  +| 10   | 8  | 2   | 4  |  
-| 8   | 0   | 0  |  +| 8   | 8  | 0   | 0  |  
-| 11   | 3   | 9  |  +| 11   | 8  | 3   | 9  |  
-| 9   | 1   | 1  |  +| 9   | 8  | 1   | 1  |  
-| 9   | 1   | 1  |  +| 9   | 8  | 1   | 1  |  
-|  $\overline{Y}=8$      |  $SS_{total} = 30$   +|  $\overline{Y}=8$     |   |  $SS_{total} = 30$   
 <WRAP clear /> <WRAP clear />
 위에서 제곱한 값의 합은? 30이다. 이는 사실, SS (Sum of Square)값이 30이라는 이야기이다. 그리고, 위에서 설명한 것처럼, 이 값은 $ SS_{total} $ 이라고 할 수 있으며 __전체에러__ 변량이라고 할 수 있겠다. 위에서 제곱한 값의 합은? 30이다. 이는 사실, SS (Sum of Square)값이 30이라는 이야기이다. 그리고, 위에서 설명한 것처럼, 이 값은 $ SS_{total} $ 이라고 할 수 있으며 __전체에러__ 변량이라고 할 수 있겠다.
Line 204: Line 204:
 __SS<sub>res</sub> , Residual error__ __SS<sub>res</sub> , Residual error__
 <code> <code>
 +> head(datavar)
 +. . . . 
 +> mod <- lm(bankaccount ~ income, data = datavar)
 +> summary(mod)
 +
 Residuals: Residuals:
     Min      1Q  Median      3Q     Max      Min      1Q  Median      3Q     Max 
Line 346: Line 351:
  
  
-====== E.g., 2. Simple regression ======+====== E.g., Simple regression ======
 data:  data: 
 {{:acidity.sav}} \\ {{:acidity.sav}} \\
Line 583: Line 588:
  SS<sub>total</sub> = 87.733  SS<sub>total</sub> = 87.733
  r<sup>2</sup> = SS<sub>reg</sub> / SS<sub>total</sub> = 42.462 / 87.733 = .484.  r<sup>2</sup> = SS<sub>reg</sub> / SS<sub>total</sub> = 42.462 / 87.733 = .484.
 +
 +====== e.g. Simple Regression ======
 +{{:AllenMursau.data.csv}}
 +
 +<code>datavar <- read.csv("http://commres.net/wiki/_media/allenmursau.data.csv")
 +</code>
 +
 +<code>> mod <- lm(Y ~ X, data=datavar)
 +> summary(mod)
 +
 +Call:
 +lm(formula = Y ~ X, data = datavar)
 +
 +Residuals:
 +    Min      1Q  Median      3Q     Max 
 +-250.22 -132.28   33.09  165.53  187.78 
 +
 +Coefficients:
 +            Estimate Std. Error t value Pr(>|t|)   
 +(Intercept)  300.976    229.754   1.310    0.219   
 +X             10.312      3.124   3.301    0.008 **
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 170.5 on 10 degrees of freedom
 +Multiple R-squared:  0.5214, Adjusted R-squared:  0.4736 
 +F-statistic:  10.9 on 1 and 10 DF,  p-value: 0.008002
 +
 +</code>
 +<code>> anova(mod)
 +Analysis of Variance Table
 +
 +Response: Y
 +          Df Sum Sq Mean Sq F value   Pr(>F)   
 +X          1 316874  316874  10.896 0.008002 **
 +Residuals 10 290824   29082                    
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +> </code>
 +
 +<code>
 +> ss_total <- var(datavar$Y)*11
 +> round(ss_total)
 +[1] 607698
 +> 316874 + 290824  # 위의 아웃풋에서 Sum Sq for X와 Residuals를 더한 값
 +[1] 607698
 +</code>
 +<WRAP box help>위의 anova 아웃풋 박스에서 R square value를 구할 수 있는가?
 +
 +
 +</WRAP>
 +
  
 ====== E.g., 3. Simple regression: Adjusted R squared & Slope test ====== ====== E.g., 3. Simple regression: Adjusted R squared & Slope test ======
regression.txt · Last modified: 2023/05/24 08:53 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki