Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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