#This is a script for Topic 15 # Know sigma = 9.43. H0 is mean = 138. # we have H1 is mean < 138 # we are taking a sample of size 39 # We will do the test at the 0.05 level of significance # Critical value approach # For a N(0,1) find z such that P( X < z ) = 0.05 qnorm( 0.05 ) # then use that to find the critical low value 138 + -1.645*9.43/sqrt(39) # now use the attained significance approach pnorm( 135.4, mean=138, sd=9.43/sqrt(39) ) # # use the function to solve the problem source("../hypo_known.R") hypoth_test_known(138, 9.43, -1, 0.05, 39, 135.4) # Next example # sigma = 3.94, H0: mean=15.4 H1: mean > 15.4 # sample size =27 do test a 0.02 level of significance # # critical value method # for N(0,1) find z such that P(X > z ) = 0.02 qnorm( 0.02, lower.tail=FALSE) # then use that to find the critical high value 15.4 + 2.053749 * 3.94/sqrt( 27 ) # Take the attained significance approach # sample mean is 16.9 pnorm( 16.9, mean=15.4, sd=3.94/sqrt(27), lower.tail=FALSE) # or just use the function hypoth_test_known(15.4, 3.94, 1, 0.02, 27, 16.9) ###### example ## sigma=17.4 H0: mean=143.2 H1: mean != 143.3 ## sample size = 42 alpha = 0.025 ## mean of sample = 147.1 # # critical value first qnorm(0.025/2) yl <- 143.2 - 2.241403*(17.4/sqrt(42)) yl yh <- 143.2 + 2.241403*(17.4/sqrt(42)) yh # or the attained significance approach pnorm( 149.3, mean=143.2, sd=17.4/sqrt(42), lower.tail=FALSE) # # or we could just use the function hypoth_test_known( 143.2, 17.4, 0, 0.025, 42, 149.3 ) # # Example # know sigma=23.4 H0: mean= 178 H1: mean > 178 # perform the test at the 0.05 level of significance # We take a sample of size 33. The values in the sample # can be generated using gnrnd4 source("../gnrnd4.R") gnrnd4( 1895433204, 23401873) L1 x_bar <- mean(L1) x_bar hypoth_test_known( 178, 23.4, 37, 0.05, 33, x_bar )