Last active
May 31, 2017 13:34
-
-
Save ramhiser/dd8c5f0195a91bcafd771f293ec904bb to your computer and use it in GitHub Desktop.
Confidence Interval for the mean of a Normal distribution using scipy and Pythonn
This file contains 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
from scipy import stats | |
import numpy as np | |
def mean_confidence_interval(x, alpha=0.05): | |
"""Computes two-sided confidence interval for a Normal mean | |
Assumes population variance is unknown. | |
x is assumed to be a list or a 1-d Numpy array | |
""" | |
n = len(x) | |
xbar = np.mean(x) | |
standard_error=stats.sem(x) | |
return stats.t.interval(1 - alpha, | |
n - 1, | |
loc=xbar, | |
scale=standard_error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment