Skip to content

Instantly share code, notes, and snippets.

@petrushev
Created February 1, 2019 14:39
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 petrushev/d0466c7c700fb416895e5fd0898ad484 to your computer and use it in GitHub Desktop.
Save petrushev/d0466c7c700fb416895e5fd0898ad484 to your computer and use it in GitHub Desktop.
from scipy import stats
import numpy as np
def interval_zscore(alpha=0.95):
"""
Return a zscore corresponding with a confidence interval
(e.g., for alpha=0.95, returns 1.96)
:param: alpha: float, the width of the confidence interval, default is 0.95
"""
return stats.norm.ppf(1 - (1 - alpha) * 0.5)
def quotient_se(mean_a, mean_b, std_a, std_b, n_a, n_b):
"""Returns the standard error of the ratio of two means
"""
sem_a = std_a / np.sqrt(n_a)
sem_b = std_b / np.sqrt(n_b)
q = mean_a / mean_b
std_err_q = q * np.sqrt(
((sem_a**2)/(mean_a**2))+((sem_b**2)/(mean_b**2))
)
return std_err_q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment