Created
July 9, 2020 12:26
-
-
Save arimitramaiti/9ab9c5bbeb0b827d24b7ff01b0a46539 to your computer and use it in GitHub Desktop.
An example to share population mean estimation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##import required modules | |
import numpy as np | |
import scipy.stats as stats | |
import math | |
sample_size = 30 #known from the sample collected by the manager | |
population_size = 1184 #known in this specific case therefore required for fpc calc | |
sample_std = 4.46 #standard deviation of all sample means | |
point_estmate = 55.45 #as we take more and more samples the sample mean would converge to population mean | |
standard_error = sample_std/ np.sqrt(sample_size) #formula is slightly different relative to population proportion estimation | |
##Finite Population Correction (fpc) | |
fpc = round(np.sqrt((population_size - 30) / (population_size - 1)),2) | |
##fpc is seldom used when population size is unknown and we only have sample mean and sample standard deviations | |
standard_error_fpc = fpc * standard_error #standard error post accounting for fpc effect | |
upper_limit = round(point_estmate + (stats.norm.ppf(0.975) * standard_error_fpc),2) #upper side of the interval | |
lower_limit = round(point_estmate - (stats.norm.ppf(0.975) * standard_error_fpc),2) #lower side of the interval | |
print("We are 95% confident that the average time taken to serve customers in the restaurant who receive orders lies between {}. & {}.".format(lower_limit, upper_limit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment