c:ms:2025:schedule:week06_t-test_and_anova_note
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
c:ms:2025:schedule:week06_t-test_and_anova_note [2025/04/10 10:16] – hkimscil | c:ms:2025:schedule:week06_t-test_and_anova_note [2025/04/14 08:35] (current) – [t-test, different approach] hkimscil | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Recap ====== | ====== Recap ====== | ||
recap. | recap. | ||
+ | ===== Sampling distribution and z-test ===== | ||
+ | |||
* Sampling distribution (The distribution of sample means) | * Sampling distribution (The distribution of sample means) | ||
* CLT | * CLT | ||
Line 31: | Line 33: | ||
* 파란선 아랫부분이 0.00255513 | * 파란선 아랫부분이 0.00255513 | ||
* 이 둘을 합친 부분이 0.005110261 | * 이 둘을 합친 부분이 0.005110261 | ||
- | * 즉, z-score 2.8 (혹은 -2.8 이) 나올 확률은 약 5/1000 라는 뜻 | + | * 즉, z-score 2.8 (혹은 -2.8 이) 나올 확률은 약 5/1000 라는 뜻 (빨간선 윗부분 + 파란선 아랫부분) |
{{: | {{: | ||
+ | ===== t-test ===== | ||
* 한편, t-test는 샘플의 숫자가 작을 때 (보통 n < ~ 30) z-test대신 하게 되는데 | * 한편, t-test는 샘플의 숫자가 작을 때 (보통 n < ~ 30) z-test대신 하게 되는데 | ||
* z-score를 구하는 방법은 동일하다 (group difference / random error) | * z-score를 구하는 방법은 동일하다 (group difference / random error) | ||
Line 39: | Line 42: | ||
* 보정값은 샘플의 숫자마다 다르게 됨 | * 보정값은 샘플의 숫자마다 다르게 됨 | ||
* < | * < | ||
+ | > # 아래는 샘플사지즈가 16일 경우 | ||
> qt(0.025, df=15) | > qt(0.025, df=15) | ||
[1] -2.13145 | [1] -2.13145 | ||
> qt(0.975, df=15) | > qt(0.975, df=15) | ||
[1] 2.13145 | [1] 2.13145 | ||
+ | > # 아래는 샘플사이즈가 51일 경우 | ||
+ | > qt(0.025, df=50) | ||
+ | [1] -2.008559 | ||
+ | > qt(0.975, df=50) | ||
+ | [1] 2.008559 | ||
> | > | ||
</ | </ | ||
- | * 혹은 | + | * 혹은 |
* < | * < | ||
> pt(2.8, df=15, lower.tail = F) | > pt(2.8, df=15, lower.tail = F) | ||
Line 51: | Line 60: | ||
> pt(-2.8, df=15) | > pt(-2.8, df=15) | ||
[1] 0.006729863 | [1] 0.006729863 | ||
+ | > | ||
+ | > # 이 둘을 더한 값이 양쪽 날개 바깥쪽의 probability | ||
+ | > 2 * pt(2.8, df=15, lower.tail = F) | ||
+ | [1] 0.01345973 | ||
> | > | ||
</ | </ | ||
+ | |||
* 한 편 z-test와 t-test가 있는데 모든 경우 t-test를 함 | * 한 편 z-test와 t-test가 있는데 모든 경우 t-test를 함 | ||
* 이유 | * 이유 | ||
Line 59: | Line 73: | ||
[1] -2.13145 | [1] -2.13145 | ||
> qt(0.025, df=150000000000000) | > qt(0.025, df=150000000000000) | ||
+ | [1] -1.959964 | ||
+ | > # 샘플사이즈가 충분히 크면 qt값과 qnorm값이 동일한 | ||
+ | > # 1.96임을 주의 | ||
+ | > qnorm(0.025) | ||
[1] -1.959964 | [1] -1.959964 | ||
> | > | ||
Line 444: | Line 462: | ||
abline(v = mean.a, lty=2, lwd=3, col=" | abline(v = mean.a, lty=2, lwd=3, col=" | ||
abline(v = mean.b, lty=2, lwd=3, col=" | abline(v = mean.b, lty=2, lwd=3, col=" | ||
+ | |||
+ | # or | ||
+ | hist(A, xlim=c(0, | ||
+ | hist(B, add=T, col=rgb(0, 1, 0, 0.5)) | ||
+ | abline(v=mean(dat), | ||
+ | abline(v=mean(A), | ||
+ | abline(v=mean(B), | ||
</ | </ | ||
Line 519: | Line 544: | ||
f.calculated.pvalue <- 1-pf(f.calculated, | f.calculated.pvalue <- 1-pf(f.calculated, | ||
f.calculated.pvalue | f.calculated.pvalue | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | x <- rf(500000, df1 = df.between, df2 = df.within) | ||
+ | hist(x, | ||
+ | | ||
+ | freq = FALSE, | ||
+ | xlim = c(0, 7), | ||
+ | ylim = c(0, 3), | ||
+ | xlab = "", | ||
+ | main = " | ||
+ | with df1 = 1 and df2 = 30", | ||
+ | | ||
+ | ) | ||
+ | curve(df(x, df1 = df.between, df2 = df.within), | ||
+ | from = 0, to = 8, n = 5000, | ||
+ | col = " | ||
+ | add = T) | ||
+ | abline(v=f.calculated, | ||
+ | |||
+ | f.calculated.pvalue | ||
+ | 1 - f.calculated.pvalue | ||
+ | </ | ||
+ | |||
+ | < | ||
# 한편, | # 한편, | ||
# samples t-test를) 아웃 풋은 | # samples t-test를) 아웃 풋은 | ||
Line 630: | Line 680: | ||
> abline(v = mean.b, lty=2, lwd=3, col=" | > abline(v = mean.b, lty=2, lwd=3, col=" | ||
> | > | ||
+ | > # or | ||
+ | > hist(A, xlim=c(0, | ||
+ | > hist(B, add=T, col=rgb(0, 1, 0, 0.5)) | ||
+ | > abline(v=mean(dat), | ||
+ | > abline(v=mean(A), | ||
+ | > abline(v=mean(B), | ||
</ | </ | ||
+ | |||
{{c: | {{c: | ||
+ | {{: | ||
< | < | ||
> # mean.total 에서 그룹a의 평균까지의 차이를 구한 후 | > # mean.total 에서 그룹a의 평균까지의 차이를 구한 후 |
c/ms/2025/schedule/week06_t-test_and_anova_note.1744247789.txt.gz · Last modified: 2025/04/10 10:16 by hkimscil