Skip to content

Instantly share code, notes, and snippets.

@SaraM92
Created September 29, 2020 21:00
Show Gist options
  • Save SaraM92/a5805985b39bac32b191c5eacbca6a8f to your computer and use it in GitHub Desktop.
Save SaraM92/a5805985b39bac32b191c5eacbca6a8f to your computer and use it in GitHub Desktop.
#Import needed libraries
import numpy as np
import scipy.stats
#build a function that calculates the confidence interval
def mean_confidence_interval(data, confidence=0.95):
a = 1.0 * np.array(data)
n = len(a)
m, se = np.mean(a), scipy.stats.sem(a)
h = se * scipy.stats.t.ppf((1 + confidence) / 2., n-1)
return m, m-h, m+h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment