# this is a script to accompany the video for # Topic 17 # # We have a large population. H0 is that for some # characteristic the proportion of items in the population # with that characteristic is 0.23, H0: p = 0.23 # and the alternative is that the proportion of items with # that characteristic is less than 0.23, H1: p < 0.23 # We want to run the test at the 0.02 level of significance. # We will take a sample of size 147. # That is less than 5% of the large population. # We need to check n*p and n*(1-p) be be sure both are # greater than 10. 147*0.23 147*(1-0.23) # Both work so we can use the normal approximation # for the distribution of sample proportions. If H0 # is true then that distribution will be # N( 0.23, sqrt(0.23*(1-0.23)/147) ) ###################################### ### The critical value method ###################################### # compute sqrt(0.23*(1-0.23)/147) sqrt(0.23*(1-0.23)/147) # Then the critical low value will be qnorm( 0.02, mean=0.23, sd=0.0347 ) # # We take our sample and we find that there are 22 # items in the sample with the desired characteristic. # So, our sample proportion is p_hat <- 22/147 p_hat # That is less than our critical low value. Therefore, # we reject H0 in favor of H1 at the 0.02 level # of significance. ###################################### ### The attained significance method ###################################### # We took our sample and found 22 items with the # characteristic. So, p_hat is p_hat <- 22/147 p_hat # Assuming H0 is true, then how "strange" is it to # get a sample proportion that low or lower? pnorm( 22/147, mean=0.23, sd=sqrt( 0.23*(1-0.23)/147 ) ) # That attained significance is less than our 0.02 # stated level of significance so we reject H0 in # favor of H1. ############################## # Or we could just use our hypoth_test_prop() function # to compute both approaches source("../hypo_prop.R") # we will use -3 to indicate that H1 is "<" hypoth_test_prop( 0.23, 22, 147, -3, 0.02)