> # Method 1: Repeat 1,200 times the > # experiment of rolling a die once > rbinom(1200, 1, 1/6)The only problem with Method 1 is that we need to count how many ones are rolled with the die. Better: use the R the sum function to add up how many ones are obtained:
> # Better method 1: > sum(rbinom(1200, 1, 1/6))The alternative is to conduct one experiment of flipping 1,200 coins once each:
> # Method 2 > rbinom(1, 1200, 1/6)This method call returns the number of successes (k) obtained in 1,200 (n) trys with probability p of success, where "success" is obtaining a one with a single die roll.
> qnorm(0.025) [1] -1.959964For a 99% confidence interval, the area of the two tails is 100% - 99% = 1% and area in one tail is 1% / 2 = 0.5% = 0.005. Using R:
> qnorm(0.005) [1] -2.575829
> x <- c(78, 83, 68, 72, 88) > t.test(x, mu=70) One Sample t-test data: x t = 2.16, df = 4, p-value = 0.09689 alternative hypothesis: true mean is not equal to 70 95 percent confidence interval: 67.774 87.826 sample estimates: mean of x 77.8Use the R qt function to obtain the 95% confidence interval for the t-statistic:
> qt(0.025, 4) [1] -2.776445
SoleMaterialA | SoleMaterialB |
---|---|
13.2 | 14.0 |
8.2 | 8.8 |
10.9 | 11.2 |
14.3 | 14.2 |
10.7 | 11.8 |
6.6 | 6.4 |
9.5 | 9.8 |
10.8 | 11.3 |
8.8 | 9.3 |
13.3 | 13.6 |
> setwd("c:/it223/sole-material") > df <- read.csv("t-test2.txt") > diff <- df$A - df$B > t.test(diff, mu=0) One Sample t-test data: diff t = -3.3489, df = 9, p-value = 0.008539 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -0.6869539 -0.1330461 sample estimates: mean of x -0.41