# Find the required sample size to force the
# margin of error to be at a desired level.
#
# This applies to cases where we know the
# population standard deviation. (Although,
# if you have at least a rough guess of that,
# perhaps by looking at the standard deviation
# of samples from some earlier work then you could
# adapt this methodology as an approximation even
# if you did not know the standard deviation of
# the population.)
# So, here is a problem. We know that the
# standard deviation in the population is 5.36.
# we want to generate a 97% confidence interval
# for the population mean. What sample size
# would we need to get the margin of error down
# to 1.5 or lower?
# We know that the margin of error is
# MOE =z_alpha_over_2*pop_sigma/sqrt( samp_size)
# and if we solve that equation for samp_size
# we get
# samp_size = (z_alpha_over_2*pop_sigma/MOE)^2
#
# but for our problem, we know all of the
# values on the right
z_alpha_over_2 <- qnorm( (1-0.97)/2)
z_alpha_over_2
#
# so
samp_size <- (z_alpha_over_2*5.36/1.5)^2
samp_size
# but since you can not get fractional
# sample sizes we round up so that the MOE
# is the desired 1.5 or less.
# our sample size would be 61.
#
# Of course we could have used the provided
# function, find_samp_size()
source( "../findsampsize.R") # note missing _'s
find_samp_size( 5.36, 0.97, 1.5)