Generation

generate functionFri, 17 Mar 2023

Write a function that will determine the size of the necessary sample for the study if the following parameters are known: - error (delta); - variance (sigsqr); - Confidence level (conf). Round up the answer to a whole number.

# function that determines the size of the necessary sample for the study def sample_size(delta, sigsqr, conf): # confidence level alpha = 1 - conf # standard error stderr = math.sqrt(sigsqr) # margin of error moe = stderr * norm.ppf(1 - alpha / 2) # sample size n = (norm.ppf(1 - alpha / 2) * stderr / delta) ** 2 # rounding up n n = math.ceil(n) return n # calling function sample_size(0.1, 1, 0.95)

Questions about programming?Chat with your personal AI assistant