User Tools

Site Tools


r:sampling_distribution

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:sampling_distribution [2026/03/22 23:54] hkimscilr:sampling_distribution [2026/03/24 10:17] (current) hkimscil
Line 372: Line 372:
 </WRAP> </WRAP>
 </WRAP> </WRAP>
- 
 ---- ----
 +
 +<code>
 +pnorm(110, 100, 10, lower.tail = F) 
 +pnorm((110-100)/10, lower.tail = F)
 +pnorm(1, lower.tail = F)
 +1-pnorm(1)
 +pnorm(-1)
 +
 +1-(pnorm(-1)*2)
 +</code>
 ===== distribution of sample means ===== ===== distribution of sample means =====
    
Line 469: Line 478:
 <code> <code>
 > mean(means) > mean(means)
-[1] 99.99912+[1] 100.0025
 > sd(means) > sd(means)
-[1] 3.164792+[1] 3.167479
 > var(means) > var(means)
-[1] 10.01591+[1] 10.03292
 </code> </code>
   * 위와 같다. 이 값은 샘플평균들의 평균이 무엇인가와 (mean(means))   * 위와 같다. 이 값은 샘플평균들의 평균이 무엇인가와 (mean(means))
Line 701: Line 710:
 </WRAP> </WRAP>
 </WRAP> </WRAP>
 +
 +===== Hypothesis test =====
  
 <WRAP group> <WRAP group>
Line 781: Line 792:
  
 <code> <code>
-2 * pnorm(m.sample.i.gotmean(p1), sd(means), lower.tail = F) +> (m.sample.i.got mean(p1))/se.z 
-[1] 0.13371 +         [,1] 
-> (m.sample.i.got - mean(p1))/sd(means) +[1,] 1.494165 
-[1] 1.499631 +> z.score <- (m.sample.i.got - mean(p1))/se.z
-> z.score <- (m.sample.i.got - mean(p1))/sd(means)+
 > pnorm(z.score, lower.tail = FALSE) > pnorm(z.score, lower.tail = FALSE)
-[1] 0.06685502+           [,1
 +[1,] 0.06756624
 > 2 * pnorm(z.score, lower.tail = FALSE) > 2 * pnorm(z.score, lower.tail = FALSE)
-[1] 0.13371 +          [,1
-+[1,] 0.1351325
 </code> </code>
   * 위처럼 z score를 구해서 pnorm으로 probability를 보는 것을 z-test 라고 한다.    * 위처럼 z score를 구해서 pnorm으로 probability를 보는 것을 z-test 라고 한다. 
Line 796: Line 807:
 </WRAP> </WRAP>
 ---- ----
-===== Hypothesis test ===== 
  
 <WRAP group> <WRAP group>
Line 880: Line 890:
  
 이 probability level이 어느정도나 작아야 이 샘플이 p1에서 나오지 않고 p2에서 나왔다고 판단할 수 있을까? 관습적으로 5/100를 기준으로 해서 이 범위보다 작게 되면 p1의 모집단에서 나온 샘플이 아닌 것으로 판단하게 된다. 이 논리에 따라서, (평균을 107.9235 값을 갖는)이 샘플은, p1에서 나오기 힘든 샘플이라고 판단 된다.  이 probability level이 어느정도나 작아야 이 샘플이 p1에서 나오지 않고 p2에서 나왔다고 판단할 수 있을까? 관습적으로 5/100를 기준으로 해서 이 범위보다 작게 되면 p1의 모집단에서 나온 샘플이 아닌 것으로 판단하게 된다. 이 논리에 따라서, (평균을 107.9235 값을 갖는)이 샘플은, p1에서 나오기 힘든 샘플이라고 판단 된다. 
 +
 +  * R에는 z-test 펑션이 없다. 현실에서는 전체 모집단의 평균을 알고 있는 경우는 많지만 표준편차까지 알고 있는 경우는 많지 않다. 그래서 많이 쓰이지 않는 편이다. 
 +  * 모집단의 평균과 표준편차를 알고 있다고 하면, 우리는 R에서 z test를 하는 절차는 
 +  * n = n 일 경우의 샘플링분포에서 se 를 구한다
 +    * se = sigma / sqrt(n)
 +  * 테스트할 점수의 z score를 구한다.
 +    * diff = test.score - mean.of.population
 +    * z.score = diff / se 
 +  * z score 보다 큰 점수나 -z score 보다 작은 점수가 나올 확률를 위의 샘플링 분포에 구한다.
 +    * p.value = 2 * pnorm(z.score, lower.tail=F)
 +  * z.score와 p.vallue로 테스트점수가 모집단에서 나왔는지 나올 수 없는지 (나오기 어려운지를) 판단한다.
 {{:r:pasted:20250910-135442.png?400}} {{:r:pasted:20250910-135442.png?400}}
  
Line 946: Line 967:
 <WRAP half column> <WRAP half column>
 [[:t-test]] 중에서 2번째 케이스 [[:t-test]] 중에서 2번째 케이스
 +  * 모집단의 평균은 알지만 표준편차 정보는 없는 경우이다. 
 +  * 똑같은 논리로 생각을 해서 모집단의 샘플링분포를 (distribution of sample means) 머리에 두고
 +  * se값을 구한다. 이 때의 se 값은 
 +    * ''se.cal <- sqrt( s^2/n )''값으로 구한다. 
 +    * sigma 대신에 s를 사용한 것에 주목
 +  * z.score에 해당하는 t.score를 구한다. 
 +    * 테스트점수와 모집단 평균의 차이를 구한 후 (''diff = test.score - mean(p1)'')
 +    * se.cal 값으로 나눠준다. 
 +    * ''t.cal <- diff / se.cal''
 +  * t.cal 값 이상, 반대편 점수의 이하가 나올 확률을 구한다. 
 +    * 이 때, 모집단의 표준편차를 사용해서 z.score를 구하지 않았으므로 
 +    * 그리고, 이 probability는 샘플의 크기 n에 영향을 받으므로 n의 크기에 따라서 변화하는 probability distribution을 사용한다. 
 +      * p.value <- pt(t.score, df=n-1, lower.tail=F) * 2
 +  * t.cal과 p.value로 테스트점수가 나올 가능성을 판단하여 가설을 기각하거나 채택한다 (검증한다). 
 </WRAP> </WRAP>
 </WRAP> </WRAP>
  
 <WRAP group> <WRAP group>
 +[[:types of error]]
 +[[:hypothesis testing]]
 +
 <WRAP half column> <WRAP half column>
 <code> <code>
r/sampling_distribution.1774223684.txt.gz · Last modified: by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki