Skip to content

Instantly share code, notes, and snippets.

@arimitramaiti
Created July 9, 2020 08:09
Show Gist options
  • Save arimitramaiti/f757b7f84fac2611e80024b56e3bf08a to your computer and use it in GitHub Desktop.
Save arimitramaiti/f757b7f84fac2611e80024b56e3bf08a to your computer and use it in GitHub Desktop.
An example to share population proportion estimation
##import required modules
import numpy as np
import scipy.stats as stats
import math
sample_size = 40 #known from the sample collected by the manager
sample_success = 25 #known from the sample collected by the manager
proportion = sample_success/sample_size #sample proportion who rated more 6 or more
point_estmate = proportion #similar to proportion of the sample
standard_error = np.sqrt((proportion * (1-proportion))/sample_size) #formula is slightly different relative to population mean estimation
upper_limit = round(point_estmate + (stats.norm.ppf(0.975) * standard_error),3) #upper side of the interval
lower_limit = round(point_estmate - (stats.norm.ppf(0.975) * standard_error),3) #lower side of the interval
print("We are 95% confident that proportion of customers who rated the sandwich 6 & above lies between {}. and {}.".format(lower_limit, upper_limit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment