#NEWLINE# def sample_size_necessary_under_cph( power , ratio_of_participants , p_exp , p_con , postulated_hazard_ratio , alpha = 0.05 ) : #NEWLINE# #INDENT# '\n    This computes the sample size for needed power to compare two groups under a Cox\n    Proportional Hazard model.\n\n    References:\n        https://cran.r-project.org/web/packages/powerSurvEpi/powerSurvEpi.pdf\n\n    Parameters:\n        power: power to detect the magnitude of the hazard ratio as small as that specified by postulated_hazard_ratio.\n        ratio_of_participants: ratio of participants in experimental group over control group.\n        p_exp: probability of failure in experimental group over period of study.\n        p_con: probability of failure in control group over period of study\n        postulated_hazard_ratio: the postulated hazard ratio\n        alpha: type I error rate\n\n    Returns:\n        n_exp, n_con: the samples sizes need for the experiment and control group, respectively, to achieve desired power\n    ' #NEWLINE# z = ( lambda p : stats . norm . ppf ( p ) ) #NEWLINE# m = ( ( ( 1.0 / n_con ) * ( ( ( ( ratio_of_participants * postulated_hazard_ratio ) + 1.0 ) / ( postulated_hazard_ratio - 1.0 ) ) ** 2 ) ) * ( ( z ( ( 1.0 - ( alpha / 2.0 ) ) ) + z ( power ) ) ** 2 ) ) #NEWLINE# n_exp = ( ( m * ratio_of_participants ) / ( ( ratio_of_participants * p_exp ) + p_con ) ) #NEWLINE# n_con = ( m / ( ( ratio_of_participants * p_exp ) + p_con ) ) #NEWLINE# return ( int ( np . ceil ( n_exp ) ) , int ( np . ceil ( n_con ) ) )