Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created March 27, 2018 03:38
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 chelseatroy/17d490b2aa405402cd48144e8bb34f01 to your computer and use it in GitHub Desktop.
Save chelseatroy/17d490b2aa405402cd48144e8bb34f01 to your computer and use it in GitHub Desktop.
Confidence Intervals
import math
from scipy.stats import t
import numpy as np
def confidence_interval_for(samples=[], confidence=0.95):
sample_size = len(samples)
degrees_freedom = sample_size - 1
outlier_tails = (1.0 - confidence) / 2.0
t_distribution_number = -1 * t.ppf(outlier_tails, degrees_freedom)
step_1 = np.std(samples)/math.sqrt(sample_size)
step_2 = step_1 * t_distribution_number
low_end = np.mean(samples) - step_2
high_end = np.mean(samples) + step_2
return low_end, high_end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment