Skip to content

Instantly share code, notes, and snippets.

@marknagelberg
Last active July 22, 2018 17:36
Show Gist options
  • Save marknagelberg/b6bfe3e2141f8eeaeb0f2537ccbed81f to your computer and use it in GitHub Desktop.
Save marknagelberg/b6bfe3e2141f8eeaeb0f2537ccbed81f to your computer and use it in GitHub Desktop.
Function to calculate sample size
import math
import numpy as np
from scipy import stats
import pandas as pd
import seaborn as sns
def z_calc(p1, p2, n1, n2):
p_star = (p1*n1 + p2*n2) / (n1 + n2)
return (p2 - p1) / math.sqrt(p_star*(1 - p_star)*((1.0 / n1) + (1.0 / n2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment