Created
March 27, 2018 03:38
-
-
Save chelseatroy/17d490b2aa405402cd48144e8bb34f01 to your computer and use it in GitHub Desktop.
Confidence Intervals
This file contains hidden or 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 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