Skip to content

Instantly share code, notes, and snippets.

@db5023
db5023 / One Sample Z Test Population Proportion.py
Last active January 24, 2018 23:17
Single Sample Z-Test for a Population Proportion
import scipy.stats as stats
import math
def one_sample_ztest_pop_proportion(tail, p, pbar, n, alpha):
#Calculate test stat
sigma = math.sqrt((p*(1-p))/(n))
z = round((pbar - p) / sigma, 2)
if tail == 'lower':
@db5023
db5023 / Single Sample T-Test Using Summary Stats
Created January 24, 2018 02:39
One Sample T-Test Using Only Summary Statistics
import scipy.stats as stats
import math
def one_sample_ttest_pval(tail, mu, x, s, n, alpha):
#Calculate test statistic and p-value. Provide summary stats and specify 1 or 2 tailed test
t = round((x - mu) / (s / math.sqrt(n)),2)
test_stat = round(stats.t.ppf(q=alpha,
df=n-1),3)
if tail == 1: