in spotify_confidence/analysis/frequentist/confidence_computers/sample_size_computer.py [0:0]
def _optimal_kappa(row: Series, is_binary_column) -> float:
def _binary_variance(p: float) -> float:
return p * (1 - p)
if row[is_binary_column]:
if is_non_inferiority(row[NIM]):
return 1.0
else:
if row[POINT_ESTIMATE] == 0.0:
# variance will be 0 as well in this case. This if-branch is important to avoid divide by zero problems
return 1.0
else:
hypothetical_effect = row[ALTERNATIVE_HYPOTHESIS] - row[NULL_HYPOTHESIS]
return np.sqrt(
_binary_variance(row[POINT_ESTIMATE]) / _binary_variance(row[POINT_ESTIMATE] + hypothetical_effect)
)
else:
return 1.0