User Tools

Site Tools


t-test_summary

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
t-test_summary [2026/04/12 23:19] – [ro.hypothesis.testing] hkimscilt-test_summary [2026/04/16 01:27] (current) hkimscil
Line 120: Line 120:
  
 # 새로운 UI로 게임을 하도록 한 후 # 새로운 UI로 게임을 하도록 한 후
-# UI점수를 10명에게 구했다고 가정하고+# UI점수를 sz 명에게 구했다고 가정하고
 # 새로운 UI점수가 기존의 p1 paramter와 # 새로운 UI점수가 기존의 p1 paramter와
 # 다른지 테스트 해보라  # 다른지 테스트 해보라 
Line 443: Line 443:
  
 </code> </code>
-{{pasted:20260412-231954.png}}+{{pasted:20260412-232126.png}}
  
 <code> <code>
Line 517: Line 517:
 > # 하면 샘플의 평균과 p1의 평균은 다르다고 판단될 것이다. > # 하면 샘플의 평균과 p1의 평균은 다르다고 판단될 것이다.
 > # 아래는 그럼에도 불구하고 실패하는 경우이다. > # 아래는 그럼에도 불구하고 실패하는 경우이다.
-> set.seed(111)+> set.seed(110)
 > smp <- sample(p2, sz, replace=T) > smp <- sample(p2, sz, replace=T)
 > m.smp <- mean(smp) > m.smp <- mean(smp)
 > m.smp > m.smp
-[1] 104.4742+[1] 104.5958
 > diff <- m.smp - mean(p1) > diff <- m.smp - mean(p1)
 > se.z <- sqrt(var(p1)/sz) > se.z <- sqrt(var(p1)/sz)
Line 527: Line 527:
 > prob1 <- pnorm(abs(z.cal1), lower.tail = F)*2 > prob1 <- pnorm(abs(z.cal1), lower.tail = F)*2
 > print(c(z.cal1, sz, prob1)) > print(c(z.cal1, sz, prob1))
-[1]  1.4148817 10.0000000  0.1571032+[1]  2.906626913 40.000000000  0.003653487
 > z.test(smp, mean(p1), sd(p1)) > z.test(smp, mean(p1), sd(p1))
- z value: 1.41488  + z value: 2.90663  
- p value: 0.1571032  + p value: 0.00365349  
- diff:    104.4742 - 100 = 4.474249  + diff:    104.5958 - 100 = 4.595781  
- se:      3.162278  + se:      1.581139  
- 95% CI:  93.80205 106.198+ 95% CI:  96.90102 103.099
 > curve(dnorm(x), from = -4, to = z.p2+4,  > curve(dnorm(x), from = -4, to = z.p2+4, 
-+       main = "normalized distribution of sample means \n testing with a sample from p2 (failed)", ++       main = "normalized distribution of sample means  
 ++       testing with a sample from p2 (failed)", 
 +       ylab = "Density", xlab = "z-value", col = "black", lwd = 2) +       ylab = "Density", xlab = "z-value", col = "black", lwd = 2)
 > abline(v=0, col="black", lwd=2) > abline(v=0, col="black", lwd=2)
Line 545: Line 546:
 +                    "\n", "pnorm(-z.cal1)*2 =", round(prob1,4)),  +                    "\n", "pnorm(-z.cal1)*2 =", round(prob1,4)), 
 +      pos=4, col='red') +      pos=4, col='red')
 +
  
 </code> </code>
-{{pasted:20260412-063636.png}}+{{pasted:20260412-233253.png}}
  
-<code> +<code>
 > # 같은 방법으로 했는데 성공한 경우 > # 같은 방법으로 했는데 성공한 경우
 > set.seed(211) > set.seed(211)
Line 555: Line 557:
 > m.smp <- mean(smp) > m.smp <- mean(smp)
 > m.smp > m.smp
-[1] 110.1154+[1] 107.6795
 > diff <- m.smp - mean(p1) > diff <- m.smp - mean(p1)
 > se.z <- sqrt(var(p1)/sz) > se.z <- sqrt(var(p1)/sz)
Line 561: Line 563:
 > prob2 <- pnorm(abs(z.cal2), lower.tail = F)*2 > prob2 <- pnorm(abs(z.cal2), lower.tail = F)*2
 > print(c(z.cal2, sz, prob2)) > print(c(z.cal2, sz, prob2))
-[1]  3.198763975 10.000000000  0.001380181+[1] 4.856940e+00 4.000000e+01 1.192138e-06
 > z.test(smp, mean(p1), sd(p1)) > z.test(smp, mean(p1), sd(p1))
- z value: 3.19876  + z value: 4.85694  
- p value: 0.00138018  + p value: 1.19e-06  
- diff:    110.1154 - 100 = 10.11538  + diff:    107.6795 - 100 = 7.679496  
- se:      3.162278  + se:      1.581139  
- 95% CI:  93.80205 106.198>  + 95% CI:  96.90102 103.099>  
-> z.p2 <- (mean(p2)-mean(p1))/se2+> z.p2 <- (mean(p2)-mean(p1))/se.z
 > z.p2 > z.p2
-[1] 1.897367+         [,1] 
 +[1,] 3.794733
 > curve(dnorm(x), from = -5, to = z.p2+5,  > curve(dnorm(x), from = -5, to = z.p2+5, 
 +       main = "normalized distribution of sample means \n testing with a sample from p2 (succeeded)",  +       main = "normalized distribution of sample means \n testing with a sample from p2 (succeeded)", 
Line 577: Line 580:
 > z.cal1 > z.cal1
          [,1]          [,1]
-[1,] 1.414882+[1,] 2.906627
 > z.cal2 > z.cal2
-         [,1] +        [,1] 
-[1,] 3.198764+[1,] 4.85694
 > two <- qnorm(.05/2) > two <- qnorm(.05/2)
 > two > two
Line 593: Line 596:
 +      label=paste(round(-z.cal2,4)), +      label=paste(round(-z.cal2,4)),
 +      col="darkgreen", cex=1, pos=2) +      col="darkgreen", cex=1, pos=2)
 +
  
 </code> </code>
-{{pasted:20260412-063652.png}}+{{pasted:20260412-233208.png}}
  
 <code>  <code> 
 > # type i and type ii error > # type i and type ii error
-z.p2 <- (mean(p2)-mean(p1))/se2 +two <- qnorm(.05/2
-z.p2 +two 
-[1] 1.897367+[1] -1.959964 
 +
 > curve(dnorm(x), from = -4.7, to = z.p2+4,  > curve(dnorm(x), from = -4.7, to = z.p2+4, 
 +       main = "Distribution Curve",  +       main = "Distribution Curve", 
 +       ylab = "Density", xlab = "z-value", col = "black", lwd = 2) +       ylab = "Density", xlab = "z-value", col = "black", lwd = 2)
-> curve(dnorm(x-(z.p2)), from = z.p2-3, to = z.p2+3, add = T,+> curve(dnorm(x-c(z.p2)), from = z.p2-3, to = z.p2+3, add = T,
 +       main = "Distribution Curve",  +       main = "Distribution Curve", 
 +       ylab = "Density", xlab = "z-value", col = "blue", lwd = 2, lty=2) +       ylab = "Density", xlab = "z-value", col = "blue", lwd = 2, lty=2)
 > abline(v=0, col='black', lwd=2) > abline(v=0, col='black', lwd=2)
-> z.cal1 
-         [,1] 
-[1,] 1.414882 
-> z.cal2 
-         [,1] 
-[1,] 3.198764 
-> two <- qnorm(.05/2) 
-> two 
-[1] -1.959964 
 > abline(v=c(two, -two), col='black', lwd=2) > abline(v=c(two, -two), col='black', lwd=2)
 > abline(v=c(-z.cal1, z.cal1), col='red', lwd=2) > abline(v=c(-z.cal1, z.cal1), col='red', lwd=2)
Line 636: Line 632:
 +      label=paste(round(-z.cal2,4)), +      label=paste(round(-z.cal2,4)),
 +      col="darkgreen", cex=1, pos=2) +      col="darkgreen", cex=1, pos=2)
 +
  
 </code> </code>
-{{pasted:20260412-063709.png}}+{{pasted:20260412-233411.png}}
  
 <code> <code>
- 
 > ############################ > ############################
 > # one sample t-test > # one sample t-test
Line 686: Line 682:
 > print(c(m.smp+lo2*se.z, m.smp+hi2*se.z)) > print(c(m.smp+lo2*se.z, m.smp+hi2*se.z))
 [1] 102.5239 110.0970 [1] 102.5239 110.0970
-> cat("t =", t.cal, ", df =", round(df.smp,0), ", p-value =", prob, +> cat(" t =", t.cal, ", df =", round(df.smp,0), ", p-value =", prob, 
 + "\n", "95% confidence interval =", m.smp+lo2*se.z, m.smp+hi2*se.z) + "\n", "95% confidence interval =", m.smp+lo2*se.z, m.smp+hi2*se.z)
-t = 3.488087 , df = 19 , p-value = 0.002460977 + t = 3.488087 , df = 19 , p-value = 0.002460977 
  95% confidence interval = 102.5239 110.097> t.test(smp, mu=mean(p1))  95% confidence interval = 102.5239 110.097> t.test(smp, mu=mean(p1))
  
Line 701: Line 697:
 mean of x  mean of x 
  106.3104   106.3104 
- 
  
 > ################################# > #################################
Line 779: Line 774:
 +      pos=4, col='red') +      pos=4, col='red')
  
 +
 </code> </code>
 {{pasted:20260412-063739.png}} {{pasted:20260412-063739.png}}
Line 800: Line 796:
 > t.cal > t.cal
 [1] -3.070212 [1] -3.070212
-> # t.cal=diff/se 
-> t.cal * se.s 
-[1] -8.871414 
-> diff 
-[1] -8.871414 
-> diff+lo2*se.s 
-[1] -14.68117 
-> diff+hi2*se.s 
-[1] -3.061661 
-> (t.cal+lo2)*se.s 
-[1] -14.68117 
-> (t.cal+hi2)*se.s 
-[1] -3.061661 
  
 > ###################### > ######################
Line 880: Line 863:
 +      col="red", pos=4) +      col="red", pos=4)
 > text(x=t.cal, y=.2, label=c(round(t.cal,3)), col="red", pos=2) > text(x=t.cal, y=.2, label=c(round(t.cal,3)), col="red", pos=2)
 +
 +> cat(t.cal, sz-1, prob)
 +-3.88213 39 0.0003888961
 +
 </code> </code>
 {{pasted:20260412-063758.png}} {{pasted:20260412-063758.png}}
t-test_summary.1776035996.txt.gz · Last modified: by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki