Skip to content

Instantly share code, notes, and snippets.

@ramhiser
Last active May 31, 2017 13:34
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 ramhiser/dd8c5f0195a91bcafd771f293ec904bb to your computer and use it in GitHub Desktop.
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
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