User Tools

Site Tools


t-test_summary

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
t-test_summary [2026/04/12 04:25] – created hkimscilt-test_summary [2026/04/12 09:47] (current) – [ro.hypothesis.testing] hkimscil
Line 20: Line 20:
  
 ################################ ################################
 +set.seed(1001)
 N.p <- 1000000 N.p <- 1000000
 m.p <- 100 m.p <- 100
Line 34: Line 35:
 means <- rep(NA, iter) means <- rep(NA, iter)
 for (i in 1:iter) { for (i in 1:iter) {
-  # means <- append(means, mean(sample(p1, s.size, replace = T))) 
   s1 <- sample(p1, sz, replace = T)   s1 <- sample(p1, sz, replace = T)
   means[i] <- mean(s1)   means[i] <- mean(s1)
Line 72: Line 72:
 sd(zsdc2) sd(zsdc2)
  
-col1 <- rgb(0, 1, 1, alpha = 0.1)  
-col2 <- rgb(1, 1, 1, alpha = 0.1) 
 curve(dnorm(x), from = -4, to = z.p2+4,  curve(dnorm(x), from = -4, to = z.p2+4, 
-      main = "distribution Curve", +      main = "normalized distribution of sample means from p1 and p2", 
       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)
 curve(dnorm(x-(z.p2)), from = z.p2-3, to = z.p2+3, add = T, curve(dnorm(x-(z.p2)), from = z.p2-3, to = z.p2+3, add = T,
Line 97: Line 95:
 c(lo3,hi3) c(lo3,hi3)
  
-curve(dnorm(x), from = -4, to = z.p2+4,  +curve(dnorm(x), from = -4, to = 2+4,  
-      main = "distribution Curve",  +      main = "normalized distribution of sample means from p1",  
-      ylab = "Density", xlab = "t-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)
 abline(v=c(lo1, hi1, lo2, hi2, lo3, hi3), abline(v=c(lo1, hi1, lo2, hi2, lo3, hi3),
        col=c("red","red", "blue", "blue", "orange", "orange"),         col=c("red","red", "blue", "blue", "orange", "orange"), 
        lwd=2)        lwd=2)
 +text(x=hi1, y=.2, label=paste(round(hi1,3), "(1)", "\n","86%"), pos=4)
 +text(x=hi2, y=.15, label=paste(round(hi2,3),"(2)", "\n","95%"), pos=4)
 +text(x=hi3, y=.1, label=paste(round(hi3,3), "(3)", "\n","99%"), pos=4)
  
 mean.of.sample.a <- mean(sdc)+ 1.5*sd(sdc) mean.of.sample.a <- mean(sdc)+ 1.5*sd(sdc)
Line 117: Line 118:
  
 curve(dnorm(x), from = -4, to = z.p2+4,  curve(dnorm(x), from = -4, to = z.p2+4, 
-      main = "distribution curve", +      main = "normalized distribution of sample means from p1 with z score 1.5", 
       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 137: Line 138:
 # 하면 샘플의 평균과 p1의 평균은 다르다고 판단될 것이다. # 하면 샘플의 평균과 p1의 평균은 다르다고 판단될 것이다.
 # 아래는 그럼에도 불구하고 실패하는 경우이다. # 아래는 그럼에도 불구하고 실패하는 경우이다.
-set.seed(5)+set.seed(111)
 smp <- sample(p2, sz, replace=T) smp <- sample(p2, sz, replace=T)
 m.smp <- mean(smp) m.smp <- mean(smp)
Line 149: Line 150:
  
 curve(dnorm(x), from = -4, to = z.p2+4,  curve(dnorm(x), from = -4, to = z.p2+4, 
-      main = "distribution curve", +      main = "normalized distribution of sample means \n 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 162: Line 163:
  
 # 같은 방법으로 했는데 성공한 경우 # 같은 방법으로 했는데 성공한 경우
-set.seed(111)+set.seed(211)
 smp <- sample(p2,sz,replace=T) smp <- sample(p2,sz,replace=T)
 m.smp <- mean(smp) m.smp <- mean(smp)
Line 175: Line 176:
 z.p2 <- (mean(p2)-mean(p1))/se2 z.p2 <- (mean(p2)-mean(p1))/se2
 z.p2 z.p2
-curve(dnorm(x), from = -4.7, to = z.p2+4,  +curve(dnorm(x), from = -5, to = z.p2+5,  
-      main = "Distribution Curve", +      main = "normalized distribution of sample means \n testing with a sample from p2 (succeeded)", 
       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, 
-      main = "Distribution Curve",  
-      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 z.cal1
Line 234: Line 232:
 # one sample t-test # one sample t-test
 ############################ ############################
 +set.seed(99)
 sz <- 20 sz <- 20
 smp <- sample(p2, sz, replace = T) smp <- sample(p2, sz, replace = T)
Line 248: Line 247:
 m.smp+lo2*se.z m.smp+lo2*se.z
  
-curve(dt(x, df.smp), from = -4, to = 6,  +curve(dt(x, df.smp), from = -6, to = 7,  
-      main = "Distribution Curve", +      main = "distribution", 
       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)
 abline(v=0, col="black", lwd=2) abline(v=0, col="black", lwd=2)
Line 268: Line 267:
 t.test(smp, mu=mean(p1)) t.test(smp, mu=mean(p1))
  
 +#################################
 # t-test 2 group  # t-test 2 group 
-set.seed(1996+################################# 
-sz.a <- 16 +set.seed(169
-sz.b <- 16+sz.a <- 25 
 +sz.b <- 25
 group.a <- sample(p1, sz.a) group.a <- sample(p1, sz.a)
 group.b <- sample(p2, sz.b) group.b <- sample(p2, sz.b)
-group.a 
-group.b 
 m.a <- mean(group.a) m.a <- mean(group.a)
 m.b <- mean(group.b) m.b <- mean(group.b)
Line 335: Line 334:
 # 4번째 케이스 t-test # 4번째 케이스 t-test
 ###################### ######################
-set.seed(3)+set.seed(37)
 sz <- 40 sz <- 40
 time.a <- sample(p1,sz) time.a <- sample(p1,sz)
Line 367: Line 366:
 hi3 <- -lo3 hi3 <- -lo3
  
-curve(dt(x, df=sz-1), from = -5, to = 7,  +curve(dt(x, df=sz-1), from = -6, to = 7,  
-      main = "t distribution curve", +      main = "t distribution", 
       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)
  
Line 380: Line 379:
  
 cat(t.cal, sz-1, prob) cat(t.cal, sz-1, prob)
 +
 </code> </code>
 <tabbox ro.hypothesis.testing> <tabbox ro.hypothesis.testing>
 <code> <code>
- 
  
 > rm(list=ls()) > rm(list=ls())
Line 403: Line 402:
  
 > ################################ > ################################
 +> set.seed(1001)
 > N.p <- 1000000 > N.p <- 1000000
 > m.p <- 100 > m.p <- 100
Line 417: Line 417:
 > means <- rep(NA, iter) > means <- rep(NA, iter)
 > for (i in 1:iter) { > for (i in 1:iter) {
-+   # means <- append(means, mean(sample(p1, s.size, replace = T))) 
 +   s1 <- sample(p1, sz, replace = T) +   s1 <- sample(p1, sz, replace = T)
 +   means[i] <- mean(s1) +   means[i] <- mean(s1)
 + } + }
 > mean(means) > mean(means)
-[1] 99.98864+[1] 99.9946
 > var(means) > var(means)
-[1] 9.964541+[1] 9.95743
 > sd(means) > sd(means)
-[1] 3.156666+[1] 3.15554
  
 > # CLT에 의하면 위이 값은 > # CLT에 의하면 위이 값은
Line 455: Line 454:
 > sd.zsdc <- sd(zsdc) > sd.zsdc <- sd(zsdc)
 > m.zsdc > m.zsdc
-[1] -5.276736e-18+[1] -2.40102e-17
 > ms.zsdc > ms.zsdc
      [,1]      [,1]
Line 471: Line 470:
 [1] 1 [1] 1
  
-> col1 <- rgb(0, 1, 1, alpha = 0.1)  
-> col2 <- rgb(1, 1, 1, alpha = 0.1) 
 > curve(dnorm(x), from = -4, to = z.p2+4,  > curve(dnorm(x), from = -4, to = z.p2+4, 
-+       main = "distribution Curve", ++       main = "normalized distribution of sample means from p1 and p2", 
 +       ylab = "Density", xlab = "t-value", col = "black", lwd = 2) +       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)
 > curve(dnorm(x-(z.p2)), from = z.p2-3, to = z.p2+3, add = T, > curve(dnorm(x-(z.p2)), from = z.p2-3, to = z.p2+3, add = T,
Line 486: Line 483:
 > text(x=mean(zsdc2), y=.1, label=paste(round(mean(zsdc2),4)), pos=4) > text(x=mean(zsdc2), y=.1, label=paste(round(mean(zsdc2),4)), pos=4)
  
 +</code>
 +{{pasted:20260412-063549.png}}
 +<code>
 > #  > # 
 > lo1 <- qnorm(.32/2) > lo1 <- qnorm(.32/2)
Line 500: Line 500:
 [1] -2.575829  2.575829 [1] -2.575829  2.575829
  
-> curve(dnorm(x), from = -4, to = z.p2+4,  +> curve(dnorm(x), from = -4, to = 2+4,  
-+       main = "distribution Curve",  ++       main = "normalized distribution of sample means from p1",  
-+       ylab = "Density", xlab = "t-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)
 > abline(v=c(lo1, hi1, lo2, hi2, lo3, hi3), > abline(v=c(lo1, hi1, lo2, hi2, lo3, hi3),
 +        col=c("red","red", "blue", "blue", "orange", "orange"),  +        col=c("red","red", "blue", "blue", "orange", "orange"), 
 +        lwd=2) +        lwd=2)
 +> text(x=hi1, y=.2, label=paste(round(hi1,3), "(1)", "\n","86%"), pos=4)
 +> text(x=hi2, y=.15, label=paste(round(hi2,3),"(2)", "\n","95%"), pos=4)
 +> text(x=hi3, y=.1, label=paste(round(hi3,3), "(3)", "\n","99%"), pos=4)
  
 +</code>
 +{{pasted:20260412-063531.png}}
 +
 +<code>
 > mean.of.sample.a <- mean(sdc)+ 1.5*sd(sdc) > mean.of.sample.a <- mean(sdc)+ 1.5*sd(sdc)
 > mean.of.sample.a > mean.of.sample.a
Line 525: Line 532:
  
 > curve(dnorm(x), from = -4, to = z.p2+4,  > curve(dnorm(x), from = -4, to = z.p2+4, 
-+       main = "distribution curve", ++       main = "normalized distribution of sample means from p1 with z score 1.5", 
 +       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 535: Line 542:
 +                    "\n", "pnorm(-z.score)*2 =", round(prob,5)),  +                    "\n", "pnorm(-z.score)*2 =", round(prob,5)), 
 +      pos=4, col='red') +      pos=4, col='red')
-+
 +</code> 
 +{{pasted:20260412-063608.png}} 
 + 
 +<code
 > # 새로운 UI로 게임을 하도록 한 후 > # 새로운 UI로 게임을 하도록 한 후
 > # UI점수를 10명에게 구했다고 가정하고 > # UI점수를 10명에게 구했다고 가정하고
Line 545: Line 556:
 > # 하면 샘플의 평균과 p1의 평균은 다르다고 판단될 것이다. > # 하면 샘플의 평균과 p1의 평균은 다르다고 판단될 것이다.
 > # 아래는 그럼에도 불구하고 실패하는 경우이다. > # 아래는 그럼에도 불구하고 실패하는 경우이다.
-> set.seed(5)+> set.seed(111)
 > 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.5279+[1] 104.4742
 > diff <- m.smp - mean(p1) > diff <- m.smp - mean(p1)
 > se.z <- sqrt(var(p1)/sz) > se.z <- sqrt(var(p1)/sz)
Line 555: Line 566:
 > 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.4318575 10.0000000  0.1521846+[1]  1.4148817 10.0000000  0.1571032
 > z.test(smp, mean(p1), sd(p1)) > z.test(smp, mean(p1), sd(p1))
- z value: 1.43186  + z value: 1.41488  
- p value: 0.1521846  + p value: 0.1571032  
- diff:    104.5279 - 100 = 4.527931 + diff:    104.4742 - 100 = 4.474249 
  se:      3.162278   se:      3.162278 
  95% CI:  93.80205 106.198>   95% CI:  93.80205 106.198> 
 > curve(dnorm(x), from = -4, to = z.p2+4,  > curve(dnorm(x), from = -4, to = z.p2+4, 
-+       main = "distribution curve", ++       main = "normalized distribution of sample means \n 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 574: Line 585:
 +      pos=4, col='red') +      pos=4, col='red')
  
-+</code> 
 +{{pasted:20260412-063636.png}} 
 + 
 +<code
 > # 같은 방법으로 했는데 성공한 경우 > # 같은 방법으로 했는데 성공한 경우
-> set.seed(111)+> set.seed(211)
 > 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] 110.0083+[1] 110.1154
 > diff <- m.smp - mean(p1) > diff <- m.smp - mean(p1)
 > se.z <- sqrt(var(p1)/sz) > se.z <- sqrt(var(p1)/sz)
Line 586: Line 600:
 > 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.16488922 10.00000000  0.00155142+[1]  3.198763975 10.000000000  0.001380181
 > z.test(smp, mean(p1), sd(p1)) > z.test(smp, mean(p1), sd(p1))
- z value: 3.16489  + z value: 3.19876  
- p value: 0.00155142  + p value: 0.00138018  
- diff:    110.0083 - 100 = 10.00826 + diff:    110.1154 - 100 = 10.11538 
  se:      3.162278   se:      3.162278 
  95% CI:  93.80205 106.198>   95% CI:  93.80205 106.198> 
Line 596: Line 610:
 > z.p2 > z.p2
 [1] 1.897367 [1] 1.897367
-> curve(dnorm(x), from = -4.7, to = z.p2+4,  +> curve(dnorm(x), from = -5, to = z.p2+5,  
-+       main = "Distribution Curve", ++       main = "normalized distribution of sample means \n testing with a sample from p2 (succeeded)", 
 +       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, 
-+       main = "Distribution Curve",  
-+       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 > z.cal1
          [,1]          [,1]
-[1,] 1.431858+[1,] 1.414882
 > z.cal2 > z.cal2
          [,1]          [,1]
-[1,] 3.164889+[1,] 3.198764
 > two <- qnorm(.05/2) > two <- qnorm(.05/2)
 > two > two
Line 622: Line 633:
 +      col="darkgreen", cex=1, pos=2) +      col="darkgreen", cex=1, pos=2)
  
-+</code> 
 +{{pasted:20260412-063652.png}} 
 + 
 +<code
 > # type i and type ii error > # type i and type ii error
 > z.p2 <- (mean(p2)-mean(p1))/se2 > z.p2 <- (mean(p2)-mean(p1))/se2
Line 636: Line 650:
 > z.cal1 > z.cal1
          [,1]          [,1]
-[1,] 1.431858+[1,] 1.414882
 > z.cal2 > z.cal2
          [,1]          [,1]
-[1,] 3.164889+[1,] 3.198764
 > two <- qnorm(.05/2) > two <- qnorm(.05/2)
 > two > two
Line 662: Line 676:
 +      col="darkgreen", cex=1, pos=2) +      col="darkgreen", cex=1, pos=2)
  
 +</code>
 +{{pasted:20260412-063709.png}}
 +
 +<code>
  
 > ############################ > ############################
 > # one sample t-test > # one sample t-test
 > ############################ > ############################
 +> set.seed(99)
 > sz <- 20 > sz <- 20
 > smp <- sample(p2, sz, replace = T) > smp <- sample(p2, sz, replace = T)
Line 675: Line 694:
 > prob <- pt(t.cal, df.smp, lower.tail = F)*2 > prob <- pt(t.cal, df.smp, lower.tail = F)*2
 > se.z > se.z
-[1] 2.58698+[1] 1.809134
 > qt(.05/2, df.smp) > qt(.05/2, df.smp)
 [1] -2.093024 [1] -2.093024
Line 681: Line 700:
 > hi2 <- -lo2 > hi2 <- -lo2
 > m.smp+lo2*se.z > m.smp+lo2*se.z
-[1] 99.55202+[1] 102.5239
  
-> curve(dt(x, df.smp), from = -4, to = 6,  +> curve(dt(x, df.smp), from = -6, to = 7,  
-+       main = "Distribution Curve", ++       main = "distribution", 
 +       ylab = "Density", xlab = "t-value", col = "black", lwd = 2) +       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)
 > abline(v=0, col="black", lwd=2) > abline(v=0, col="black", lwd=2)
Line 695: Line 714:
 +      pos = 4, col="red", cex=1) +      pos = 4, col="red", cex=1)
  
 +</code>
 +{{pasted:20260412-063722.png}}
 +
 +<code>
 > prob > prob
-[1] 0.07001806+[1] 0.002460977
  
 > print(c(t.cal, df.smp, prob)) > print(c(t.cal, df.smp, prob))
-[1]  1.91985655 19.00000000  0.07001806+[1]  3.488086575 19.000000000  0.002460977
 > 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]  99.55202 110.38124+[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 = 1.919857 , df = 19 , p-value = 0.07001806  +t = 3.488087 , df = 19 , p-value = 0.002460977  
- 95% confidence interval = 99.55202 110.3812> t.test(smp, mu=mean(p1))+ 95% confidence interval = 102.5239 110.097> t.test(smp, mu=mean(p1))
  
  One Sample t-test  One Sample t-test
  
 data:  smp data:  smp
-t = 1.9199, df = 19, p-value = 0.07002+t = 3.4881, df = 19, p-value = 0.002461
 alternative hypothesis: true mean is not equal to 100 alternative hypothesis: true mean is not equal to 100
 95 percent confidence interval: 95 percent confidence interval:
-  99.55202 110.38124+ 102.5239 110.0970
 sample estimates: sample estimates:
 mean of x  mean of x 
- 104.9666 + 106.3104 
  
  
 +> #################################
 > # t-test 2 group  > # t-test 2 group 
-> set.seed(1996+> ################################# 
-> sz.a <- 16 +> set.seed(169
-> sz.b <- 16+> sz.a <- 25 
 +> sz.b <- 25
 > group.a <- sample(p1, sz.a) > group.a <- sample(p1, sz.a)
 > group.b <- sample(p2, sz.b) > group.b <- sample(p2, sz.b)
-> group.a 
- [1]  80.00299 100.04410  98.51054 101.75280 113.84859  89.37281  97.89621  96.86679  89.22647 116.71786  84.21395 
-[12] 109.43833 131.00954  99.24167 106.13687 110.95142 
-> group.b 
- [1] 102.63422 118.82094 101.30780 104.73424 107.63392 121.28520  90.89126  99.90229 116.67483  97.65544  87.06784 
-[12] 102.34730  99.68162 120.60669 125.69868  98.76048 
 > m.a <- mean(group.a) > m.a <- mean(group.a)
 > m.b <- mean(group.b) > m.b <- mean(group.b)
Line 739: Line 758:
 > df <- df.a+df.b > df <- df.a+df.b
 > ss.a > ss.a
-[1] 2537.948+[1] 2225.751
 > ss.b  > ss.b 
-[1] 1950.16+[1] 2783.816
 > df.a > df.a
-[1] 15+[1] 24
 > df.b > df.b
-[1] 15+[1] 24
  
 > pooled.v <- (ss.a+ss.b)/(df.a+df.b) > pooled.v <- (ss.a+ss.b)/(df.a+df.b)
 > pooled.v > pooled.v
-[1] 149.6036+[1] 104.366
 > se.s <- sqrt(pooled.v/sz.a+pooled.v/sz.b) > se.s <- sqrt(pooled.v/sz.a+pooled.v/sz.b)
 > se.s > se.s
-[1] 4.324401+[1] 2.889512
 > diff <- m.a-m.b > diff <- m.a-m.b
 > t.cal <- diff/se.s > t.cal <- diff/se.s
 > t.cal > t.cal
-[1] -1.01852+[1] -3.070212
  
 > prob <- pt(abs(t.cal), df=df, lower.tail = F)*2  > prob <- pt(abs(t.cal), df=df, lower.tail = F)*2 
  
 > t.cal > t.cal
-[1] -1.01852+[1] -3.070212
 > df > df
-[1] 30+[1] 48
 > prob > prob
-[1] 0.3165751+[1] 0.003515457
  
 > t.test(group.a, group.b, var.equal = T) > t.test(group.a, group.b, var.equal = T)
Line 772: Line 791:
  
 data:  group.a and group.b data:  group.a and group.b
-t = -1.0185, df = 30, p-value = 0.3166+t = -3.0702, df = 48, p-value = 0.003515
 alternative hypothesis: true difference in means is not equal to 0 alternative hypothesis: true difference in means is not equal to 0
 95 percent confidence interval: 95 percent confidence interval:
- -13.236094   4.427118+ -14.681167  -3.061661
 sample estimates: sample estimates:
 mean of x mean of y  mean of x mean of y 
- 101.5769  105.9814 + 101.0286  109.9000 
  
  
Line 784: Line 803:
 > hi2 <- -lo2  > hi2 <- -lo2 
 > c(lo2, hi2) > c(lo2, hi2)
-[1] -2.042272  2.042272+[1] -2.010635  2.010635
  
 > curve(dt(x, df=df), from = -6, to = 6,  > curve(dt(x, df=df), from = -6, to = 6, 
Line 799: Line 818:
 +      pos=4, col='red') +      pos=4, col='red')
  
 +</code>
 +{{pasted:20260412-063739.png}}
 +
 +<code>
 > print(paste(t.cal, df, prob)) > print(paste(t.cal, df, prob))
-[1] "-1.01851970325833 30 0.316575072953383"+[1] "-3.07021182079817 48 0.00351545738746208"
 > t.test(group.a, group.b, var.equal = T) > t.test(group.a, group.b, var.equal = T)
  
Line 806: Line 829:
  
 data:  group.a and group.b data:  group.a and group.b
-t = -1.0185, df = 30, p-value = 0.3166+t = -3.0702, df = 48, p-value = 0.003515
 alternative hypothesis: true difference in means is not equal to 0 alternative hypothesis: true difference in means is not equal to 0
 95 percent confidence interval: 95 percent confidence interval:
- -13.236094   4.427118+ -14.681167  -3.061661
 sample estimates: sample estimates:
 mean of x mean of y  mean of x mean of y 
- 101.5769  105.9814 + 101.0286  109.9000 
  
 > t.cal > t.cal
-[1] -1.01852+[1] -3.070212
 > # t.cal=diff/se > # t.cal=diff/se
 > t.cal * se.s > t.cal * se.s
-[1] -4.404488+[1] -8.871414
 > diff > diff
-[1] -4.404488+[1] -8.871414
 > diff+lo2*se.s > diff+lo2*se.s
-[1] -13.23609+[1] -14.68117
 > diff+hi2*se.s > diff+hi2*se.s
-[1] 4.427118+[1] -3.061661
 > (t.cal+lo2)*se.s > (t.cal+lo2)*se.s
-[1] -13.23609+[1] -14.68117
 > (t.cal+hi2)*se.s > (t.cal+hi2)*se.s
-[1] 4.427118+[1] -3.061661
  
 > ###################### > ######################
 > # 4번째 케이스 t-test > # 4번째 케이스 t-test
 > ###################### > ######################
-> set.seed(3)+> set.seed(37)
 > sz <- 40 > sz <- 40
 > time.a <- sample(p1,sz) > time.a <- sample(p1,sz)
Line 842: Line 865:
 > diff <- m.a-m.b > diff <- m.a-m.b
 > diff > diff
-[1] -6.116895+[1] -8.674375
 > se.s <- sd(diff.time)/sqrt(sz) > se.s <- sd(diff.time)/sqrt(sz)
 > t.cal <- diff/se.s > t.cal <- diff/se.s
Line 848: Line 871:
 > prob <- pt(abs(t.cal), df=sz-1, lower.tail = F)*2 > prob <- pt(abs(t.cal), df=sz-1, lower.tail = F)*2
 > t.cal > t.cal
-[1] -2.672942+[1] -3.88213
 > df > df
 [1] 39 [1] 39
 > prob > prob
-[1] 0.01092088+[1] 0.0003888961
 > diff > diff
-[1] -6.116895+[1] -8.674375
  
 > m.diff.time <- mean(diff.time) > m.diff.time <- mean(diff.time)
 > se.s > se.s
-[1] 2.28845+[1] 2.234437
  
 > t.test(time.a, time.b, paired=T) > t.test(time.a, time.b, paired=T)
Line 865: Line 888:
  
 data:  time.a and time.b data:  time.a and time.b
-t = -2.6729, df = 39, p-value = 0.01092+t = -3.8821, df = 39, p-value = 0.0003889
 alternative hypothesis: true mean difference is not equal to 0 alternative hypothesis: true mean difference is not equal to 0
 95 percent confidence interval: 95 percent confidence interval:
- -10.745721  -1.488068+ -13.193950  -4.154799
 sample estimates: sample estimates:
 mean difference  mean difference 
-      -6.116895 +      -8.674375 
  
  
 > m.diff.time  > m.diff.time 
-[1] -6.116895+[1] -8.674375
 > se.s > se.s
-[1] 2.28845+[1] 2.234437
 > lo1 <- qt(0.32/2,sz-1) > lo1 <- qt(0.32/2,sz-1)
 > hi1 <- -lo1 > hi1 <- -lo1
Line 885: Line 908:
 > hi3 <- -lo3 > hi3 <- -lo3
  
-> curve(dt(x, df=sz-1), from = -5, to = 7,  +> curve(dt(x, df=sz-1), from = -6, to = 7,  
-+       main = "t distribution curve", ++       main = "t distribution", 
 +       ylab = "Density", xlab = "t-value", col = "black", lwd = 2) +       ylab = "Density", xlab = "t-value", col = "black", lwd = 2)
  
Line 896: Line 919:
 +      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)
-+</code> 
 +{{pasted:20260412-063758.png}} 
 + 
 +<code
 > cat(t.cal, sz-1, prob) > cat(t.cal, sz-1, prob)
--2.672942 39 0.01092088 +-3.88213 39 0.0003888961 
- + 
-+
 </code> </code>
 +
 </tabbox> </tabbox>
t-test_summary.1775967937.txt.gz · Last modified: by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki