User Tools

Site Tools


r: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
r:regression [2025/10/13 07:33] – [3] hkimscilr:regression [2025/10/13 07:57] (current) – [10] hkimscil
Line 294: Line 294:
 </WRAP> </WRAP>
 ===== 4 ===== ===== 4 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > ss.x <- sum((x-mean(x))^2) > ss.x <- sum((x-mean(x))^2)
Line 307: Line 309:
  
 </code> </code>
 +</WRAP> 
 +<WRAP column half> 
 +++++++++++++++++++++ 
 +</WRAP> 
 +</WRAP>
 ===== 5 ===== ===== 5 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > y.pred <- a + b*x > y.pred <- a + b*x
Line 356: Line 364:
  
 </code> </code>
 +</WRAP> 
 +<WRAP column half> 
 +++++++++++++++++++++ 
 +{{:r:pasted:20251013-073857.png}} 
 +</WRAP> 
 +</WRAP>
 ===== 6 ===== ===== 6 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > y.hat <- mod.r$fitted.values > y.hat <- mod.r$fitted.values
Line 520: Line 535:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +아래를 실제로 구해서 
 +  * y.obs 실제 y 값
 +  * y.hat prediction 값
 +  * y.mean y 평균
 +그 다음 residual값, regression값 (explained value), 그리고 ss total에 쓰일 total (분산을 구할 때의 SS) 구한 뒤에
 +  * res = y.obs - y.hat
 +  * reg = y.hat - y.mean
 +  * tot = y.obs - y.mean 
 +각각의 Sum of Square값을 구한다 
 +  * ss.res <- sum(res^2)  
 +  * ss.reg <- sum(reg^2)
 +  * ss.tot <- sum(tot^2)
 +그 후에 각각의 df는 
 +  * df.res <- n - (# of parameters (a and b) = 2) = 36 - 2 = 34
 +  * df.reg <- # of parameters - 1 = 2 - 1 = 1
 +  * df.tot <- # of observation (36) - 1 = 35
  
 +</WRAP>
 +</WRAP>
 ===== 7 ===== ===== 7 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > ms.tot <- ss.tot / df.tot > ms.tot <- ss.tot / df.tot
Line 534: Line 572:
 > >
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +<fc #ff0000>**MS = variance**</fc> 
 +MS total = y의 분산값
 +MS res = residual의 분산값 = 독립변인이 있음에도 불구하고 랜덤하게 나타난 분산
 +MS reg = regression의 분산값 = 독립변인의 영향력으로 생긴 분산
  
 +F 값은 독립변인때문에 생긴 차이값 / 랜덤 차이값 = MS reg / MS res
 +
 +
 +</WRAP>
 +</WRAP>
 ===== 8 ===== ===== 8 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > f.cal <- ms.reg/ms.res > f.cal <- ms.reg/ms.res
Line 573: Line 625:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +</WRAP>
 +</WRAP>
  
 ===== 9 ===== ===== 9 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > se.res <- sqrt(ss.res/(df.res)) # standard deviation of res > se.res <- sqrt(ss.res/(df.res)) # standard deviation of res
Line 583: Line 642:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +residuals의 (잔차들의) standard deviation (표준편차) 
 += <fc #ff0000>sqrt(잔차들의 분산)</fc> 
 +</WRAP>
 +</WRAP>
  
 ===== 10 ===== ===== 10 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > ss.x <- sum((x-mean(x))^2) # ss for x > ss.x <- sum((x-mean(x))^2) # ss for x
Line 622: Line 690:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +  * b에 대한 standard error (standard deviation of b estimation)
 +  * ''sqrt(ms.res/ss.x)''
 +
 +  * b값에 대한 significant test = 
 +  * b값이 (기울기가) y를 설명하는데 기여했는가?
 +  * 기여했다는 가설을 테스트하는 것
 +  * 기여를 하지 않았다면 
 +  * 기울기가 평균값과 같은 역할밖에 하지 못했다는 뜻이므로 
 +  * ''(b - 0)/se.b'' 를 이용해서 테스트. 
 +  * 이 값이 t 값 (t.cal)
 +
 +</WRAP>
 +</WRAP>
 +
  
 ===== 11 ===== ===== 11 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > ################################## > ##################################
Line 649: Line 736:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +</WRAP>
 +</WRAP>
 +
  
 ===== 12 ===== ===== 12 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > # Train the model with scaled features > # Train the model with scaled features
Line 656: Line 751:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +</WRAP>
 +</WRAP>
 +
  
 ===== 13 ===== ===== 13 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > a <- rnorm(1) > a <- rnorm(1)
Line 667: Line 770:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +</WRAP>
 +</WRAP>
 +
  
 ===== 14 ===== ===== 14 =====
 +<WRAP group>
 +<WRAP column half>
 <code> <code>
 > nlen <- 75 > nlen <- 75
Line 709: Line 820:
  
 </code> </code>
 +</WRAP>
 +<WRAP column half>
 +++++++++++++++++++++
 +</WRAP>
 +</WRAP>
 +
  
r/regression.1760308409.txt.gz · Last modified: by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki