Skip to content

Instantly share code, notes, and snippets.

@wfaria
Created March 10, 2019 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wfaria/2c6956cbe971913199c4a89bdeb2afaa to your computer and use it in GitHub Desktop.
Save wfaria/2c6956cbe971913199c4a89bdeb2afaa to your computer and use it in GitHub Desktop.
Election Poll - margin of error method
def get_margin_of_error_interval(sample_size, number_of_std_dvt):
day_sample = get_n_samples_from_distribution(
samples_number = 1,
sample_size = sample_size)
sample_mean = np.mean(day_sample)
sample_std_dvt = np.std(day_sample)
estimated_std_dvt = sample_std_dvt / math.sqrt(sample_size)
margin_of_error = number_of_std_dvt * estimated_std_dvt
return { "error": margin_of_error, "mean": sample_mean }
get_margin_of_error_interval(100, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment