Created
March 27, 2018 03:39
-
-
Save chelseatroy/80e3944ac646ebb45cc29b390a53d5ec to your computer and use it in GitHub Desktop.
Confidence Intervals for Descriptive Collections
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_collection(sample_size=[], standard_deviation=[], mean=[], confidence=0.95): | |
degrees_freedom = [count - 1 for count in sample_size] | |
outlier_tails = (1.0 - confidence) / 2.0 | |
confidence_collection = [outlier_tails for _ in sample_size] | |
t_distribution_number = [-1 * t.ppf(tails, df) for tails, df in zip(confidence_collection, degrees_freedom)] | |
step_1 = [std/math.sqrt(count) for std, count in zip(standard_deviation, sample_size)] | |
step_2 = [step * t for step, t in zip(step_1, t_distribution_number)] | |
low_end = [mean_num - step_num for mean_num, step_num in zip(mean, step_2)] | |
high_end = [mean_num + step_num for mean_num, step_num in zip(mean, 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