#This is an example from Topic 16 # The problem is: # 1) we have a population with an unknown mean # and unknown standard deviation. # 2) we have a null hypothesis that the mean of the # population is 18.6 # 3) we have an alternative hypothesis that the mean # of the population is less than 18.6 # 4) we want to test the null hypothesis against the # alternative hypothesis at the 0.025 level of # significance. # 5) to do this we take a random sample of size 37 # 6) compute the sample mean and standard deviation; # sample mean = 17.21 sample standard deviation=4.8 # ----------------------- # 7) at this point we could use the critical value # approach and find the critical low value for the # sample mean, the value that has probability that a # sample mean will be less than that value = 0.025 # 8) if the sample mean is less than the critical low # value then we reject H0 in favor of H1, if not then # we do not have enough evidence to reject H0 in favor # of H1. # ------- alternatively ----- # 9) we could use the attained significance approach and # determine the probability of getting a sample mean # as low or lower than we jsut got. # 10) if that probability is less than the level of # significance then we reject H0 in favor of H1, # if not the we do not have enough evidence to reject # H0 in favor of H1 ################################################ # for the critical value approach first # find the t value with 0.025 to its left # for 36 degrees of freedom low_t <- qt( 0.025,36 ) low_t # # our critical low will be 18.6 + low_t*4.8/sqrt( 37 ) # remember that low_t is negative # Because our sample mean, 17.21 is not less than the # critical low value we do not reject H0 in favor of H1 # or use the attained significance approach # First normalize the sample mean sor we can use # the pt() function. # standard_t <- (17.21-18.6)/(4.8/sqrt(37)) standard_t # this becomes our test statistic # find the probability of getting that value or lower pt( standard_t, 36 ) # that answer, 0.0433, is not less than our level of # significance, 0.025 so we do not reject H0 # in favor of H1 # # Or we could have just used our # hypoth_test_unknown function to compute both # approaches source("../hypo_unknown.R") # note the -1 to indicate that H1: mean < 18.6 hypoth_test_unknown( 18.6, -1, 0.025, 37, 17.21, 4.8)