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
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))) |
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
def sample_required(p1, p_diff, alpha): | |
if p_diff <= 0: | |
raise ValueError("p_diff must be > 0") | |
n = 1 | |
while True: | |
z = z_calc(p1, p1+p_diff, n1=n, n2=n) | |
p = 1 - stats.norm.cdf(z) | |
if p < alpha: | |
break | |
n += 1 |
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
#Map how sample size changes as choice of p1 changes, holding all | |
#else constant. | |
p1s = [x*.01 for x in range(96)] | |
data = [] | |
for p1 in p1s: | |
record = {} | |
record['Probability Difference'] = p_diff | |
record['Sample Size to Detect Difference'] = sample_required(p1=p1, |
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 matplotlib import pyplot | |
fig, ax = pyplot.subplots(figsize=(9, 9)) | |
sns.set(style='darkgrid') | |
plot = sns.pointplot(x='Initial Probability', | |
y='Sample Size to Detect Difference', | |
hue='Confidence Level', ax = ax, | |
data=df) |
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
#Observe probability difference from 2% to 10% | |
p_diffs = [x*.01 for x in range(2,11)] | |
data = [] | |
for p_diff in p_diffs: | |
record = {} | |
record['Probability Difference'] = p_diff * 100 | |
record['Sample Size to Detect Difference'] = sample_required(p1=.5, | |
p_diff=p_diff, | |
alpha=.05) |
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 matplotlib import pyplot | |
fig, ax = pyplot.subplots(figsize=(10, 10)) | |
sns.set(style='darkgrid') | |
plot = sns.pointplot(x='Probability Difference', | |
y='Sample Size to Detect Difference', | |
hue='Confidence Level', ax = ax, | |
data=df) |
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 flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def home(): | |
return 'Hello World!' | |
if __name__ == '__main__': | |
app.run(debug=True) |
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
import os | |
class Config: | |
SECRET_KEY = os.environ.get('SECRET_KEY') or 'secret string' | |
class DevelopmentConfig(Config): | |
DEBUG = True | |
SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') |
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 flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
from config import config | |
db = SQLAlchemy() | |
def create_app(config_name): | |
app = Flask(__name__) | |
app.config.from_object(config[config_name]) |
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 . import db | |
class Name(db.Model): | |
id = db.Column(db.Integer, primary_key=True) | |
name = db.Column(db.String(128), nullable=False) |
OlderNewer