def __init__(self, n=None, epsilon=None, stdev=None, known_stdev=None, alpha=None, beta=None, power=None, hypothesis=None): if n is not None: is_integer(n, 'N') self.n = n else: self.n = None is_numeric(epsilon, 'epsilon') self.epsilon = epsilon is_positive(stdev, 'stdev') self.stdev = stdev self.theta = self.epsilon / self.stdev if known_stdev is not None: is_boolean(known_stdev, 'known_stdev') else: known_stdev = True self.known_stdev = known_stdev # Initialize the remaining arguments through the parent. super(MeansBase, self).__init__(alpha=alpha, power=power, beta=beta, hypothesis=hypothesis)
def __init__(self, n=None, alpha=None, power=None, beta=None, hypothesis=None, margin=None, hazard_ratio=None, proportion_visible=None, control_proportion=None, treatment_proportion=None): is_positive(hazard_ratio, 'Hazard Ratio') is_in_0_1(treatment_proportion, 'Treatment Proportion') is_in_0_1(control_proportion, 'Control Proportion') is_in_0_1(proportion_visible, 'Proportion Visible') epsilon = math.log(hazard_ratio) stdev = treatment_proportion * control_proportion * proportion_visible stdev = 1 / math.sqrt(stdev) super(Cox, self).__init__(n=n, mu=epsilon, mu_0=0, stdev=stdev, known_stdev=True, alpha=alpha, beta=beta, power=power, margin=margin, hypothesis=hypothesis)
def __init__(self, n=None, mu=None, stdev=None, hypothesis=None, margin=None, alpha=None, beta=None, power=None, known_stdev=None): if n is not None: if isinstance(n, int): self.n = n else: raise ValueError('`n` should be of type Int.') else: self.n = None for value in mu: is_numeric(value, 'value') mu = [float(value) for value in mu] self.mu = mu self.n_groups = len(self.mu) if self.n_groups % 2 == 0: # If the number of groups is even, the Williams design is # equivalent to a n_groups by n_groups crossover design self.k = self.n_groups else: # Otherwise, it is equal to a 2*n_groups by n_groups crossover # design self.k = self.n_groups * 2 is_positive(stdev, 'stdev') self.stdev = stdev if known_stdev is not None: is_boolean(known_stdev, 'known_stdev') else: known_stdev = True self.known_stdev = known_stdev if margin is not None: is_numeric(margin, 'margin') else: margin = 0 self.margin = float(margin) # Initialize the remaining arguments (alpha, beta, power) # through the parent. super(MultiSampleWilliams, self).__init__(alpha=alpha, power=power, beta=beta, hypothesis=hypothesis)
def __init__(self, n=None, mu=None, stdev=None, comparison=None, known_stdev=None, alpha=None, beta=None, power=None): if n is not None: if isinstance(n, int): self.n = n else: raise ValueError('`n` should be of type Int.') else: self.n = None for value in mu: is_numeric(value, 'value') self.mu = mu self.mean_mu = statistics.mean(self.mu) self.n_groups = len(self.mu) # The number of comparisons of interest for pairwise comparisons self.tau = self.n_groups * (self.n_groups - 1) / 2.0 is_positive(stdev, 'stdev') self.stdev = stdev if comparison in ['simultaneous', 'pairwise']: self.comparison = comparison elif comparison is None: self.comparison = 'pairwise' else: raise ValueError(("`comparison` should be in ['simultaneous', " "'pairwise']")) if known_stdev is not None: is_boolean(known_stdev, 'known_stdev') else: known_stdev = True self.known_stdev = known_stdev # Initialize the remaining arguments (alpha, beta, power) # through the parent. super(OneWayAnova, self).__init__(alpha=alpha, power=power, beta=beta, hypothesis='equality')
def __init__(self, n_1=None, n_2=None, ratio=1, alpha=None, power=None, beta=None, hypothesis=None, margin=None, control_hazard=None, treatment_hazard=None, gamma=None, trial_time=None, accrual_time=None): is_positive(accrual_time, 'Accrual Time') is_positive(trial_time, 'Trial Time') if gamma is None: gamma = 1 else: is_non_negative(gamma, 'Gamma') g = gamma t = trial_time t_0 = accrual_time variance = [] is_positive(control_hazard, 'Control Hazard') is_positive(treatment_hazard, 'Treatment Hazard') for hazard in [control_hazard, treatment_hazard]: if g == 0: EVNum = (math.exp(-hazard * t) - math.exp(-hazard * (t - t_0))) EVDenom = hazard * t_0 else: EVNum = (g * math.exp(-1 * hazard * t) * (1 - math.exp( (hazard - g) * t_0))) EVDenom = (hazard - g) * (1 - math.exp(-g * t_0)) EV = 1 + EVNum / EVDenom variance.append(hazard**2 / EV) self.stdev_control = math.sqrt(variance[0]) self.stdev_treatment = math.sqrt(variance[1]) # Initialize the remaining arguments through the parent. super(Exponential, self).__init__( n_1=n_1, n_2=n_2, ratio=ratio, mu_1=control_hazard, mu_2=treatment_hazard, stdev=1, # dummy value known_stdev=True, alpha=alpha, beta=beta, power=power, margin=margin, hypothesis=hypothesis)
def __init__(self, n=None, alpha=None, beta=None, power=None, p_11=None, p_12=None, p_21=None, p_22=None, gamma=None, stdev_1=None, stdev_2=None): if gamma is None: is_in_0_1(p_11, 'p_11 should be in [0, 1].') is_in_0_1(p_12, 'p_12 should be in [0, 1].') is_in_0_1(p_21, 'p_21 should be in [0, 1].') is_in_0_1(p_22, 'p_22 should be in [0, 1].') gamma = (math.log(p_11 / (1 - p_11)) + math.log(p_12 / (1 - p_12)) - math.log(p_21 / (1 - p_21)) - math.log(p_22 / (1 - p_22))) else: is_numeric(gamma, '`gamma` should be a number.') if n is not None: is_integer(n, '`n` should be of type Int.') self.n = n is_positive(stdev_1, 'stdev_1') self.stdev_1 = stdev_1 is_positive(stdev_2, 'stdev_2') self.stdev_2 = stdev_2 self.theta = gamma / math.sqrt(stdev_1**2 + stdev_2**2) # Set remaining variables. super(CarryOverEffect, self).__init__(alpha=alpha, beta=beta, power=power)
def __init__(self, delta=None, stdev_wr=None, stdev_wt=None, stdev_br=None, stdev_bt=None, theta_BE=None, m_plus=None, alpha=None, power=None, beta=None): is_numeric(delta, 'delta') self.delta = delta is_positive(stdev_wr, 'stdev_wr') self.stdev_wr = stdev_wr is_positive(stdev_wt, 'stdev_wt') self.stdev_wt = stdev_wt is_positive(stdev_bt, 'stdev_bt') self.stdev_bt = stdev_bt is_positive(stdev_br, 'stdev') self.stdev_br = stdev_br if theta_BE is None: theta_BE = 1 else: is_positive(theta_BE, 'theta_BE') self.theta_BE = theta_BE if m_plus is None: m_plus = MAX_ITERATIONS else: is_integer(m_plus, 'm_plus') self.m_plus = m_plus # Initialize the remaining arguments through the parent. super(InVitro, self).__init__(hypothesis="equivalence", alpha=alpha, beta=beta, power=power)
def __init__(self, delta=None, stdev_wr=None, stdev_wt=None, stdev_br=None, stdev_bt=None, rho=None, theta_IBE=None, alpha=None, power=None, beta=None): is_numeric(delta, 'delta') self.delta = delta is_positive(stdev_wr, 'stdev_wr') self.stdev_wr = stdev_wr is_positive(stdev_wt, 'stdev_wt') self.stdev_wt = stdev_wt is_positive(stdev_bt, 'stdev_br') self.stdev_br = stdev_br is_positive(stdev_bt, 'stdev_bt') self.stdev_bt = stdev_bt is_in_0_1(rho, 'rho') self.rho = rho var_d = self.stdev_bt**2 + self.stdev_br**2 - 2 * self.rho * self.stdev_bt**2 * self.stdev_bt**2 self.stdev_d = math.sqrt(var_d) if theta_IBE is None: theta_IBE = 1.74 else: is_positive(theta_IBE, 'theta_IBE') self.theta_IBE = theta_IBE # Initialize the remaining arguments through the parent. super(Individual, self).__init__(hypothesis="equivalence", alpha=alpha, beta=beta, power=power)
def __init__(self, n=None, odds_ratio=None, stdev=None, hypothesis=None, margin=None, alpha=None, beta=None, power=None): is_positive(odds_ratio, '`odds_ratio` should be greater than 0') log_odds = math.log(odds_ratio) # Initialize the remaining arguments through the parent. super(RelativeRiskCrossover, self).__init__(n=n, mu_1=log_odds, mu_2=0, stdev=stdev, known_stdev=True, alpha=alpha, beta=beta, power=power, margin=margin, hypothesis=hypothesis)
def __init__(self, delta=None, l=None, stdev_11=None, stdev_tt=None, stdev_tr=None, stdev_bt=None, stdev_br=None, rho=None, theta_PBE=None, alpha=None, power=None, beta=None): if delta is None: delta = 0 else: is_numeric(delta, 'delta') self.delta = delta is_numeric(l, 'l') self.l = l is_positive(stdev_11, 'stdev_11') self.stdev_11 = stdev_11 is_positive(stdev_tt, 'stdev_tt') self.stdev_tt = stdev_tt is_positive(stdev_tr, 'stdev_tr') self.stdev_tr = stdev_tr is_positive(stdev_bt, 'stdev_bt') self.stdev_bt = stdev_bt is_positive(stdev_br, 'stdev') self.stdev_br = stdev_br is_in_0_1(rho, 'rho') self.rho = rho if theta_PBE is None: theta_PBE = 1.74 else: is_positive(theta_PBE, 'theta_PBE') self.theta_PBE = theta_PBE # Initialize the remaining arguments through the parent. super(Population, self).__init__(hypothesis="equivalence", alpha=alpha, beta=beta, power=power)
def __init__(self, n=None, m=None, stdev_1=None, stdev_2=None, similarity_limit=None, hypothesis=None, alpha=None, beta=None, power=None): if n is not None: if isinstance(n, int): self.n = n else: raise ValueError('`n` should be of type Int.') else: self.n = None if m is not None: if isinstance(m, int): self.m = m else: raise ValueError('`m` should be of type Int.') else: raise ValueError('`m` must be provided.') is_positive(stdev_1, 'stdev_1') self.stdev_1 = stdev_1 is_positive(stdev_2, 'stdev_2') self.stdev_2 = stdev_2 # _alpha and _beta are adjusted to be used as cutpoints. # alpha and beta are to be used for display # We use _beta to prevent floating point errors when beta is passed on if hypothesis == 'equality': if alpha is not None: self._alpha = alpha / 2 else: self._alpha = None if power is not None: self._beta = 1 - power elif beta is not None: self._beta = beta else: self._beta = None similarity_limit = 1 sigma_ratio = stdev_2 / stdev_1 elif hypothesis == 'superiority': if alpha is not None: self._alpha = alpha else: self._alpha = None if power is not None: self._beta = 1 - power elif beta is not None: self._beta = beta else: self._beta = None if similarity_limit is None: raise ValueError('A similarity_limit must be provided') sigma_ratio = stdev_2 / (stdev_1 * similarity_limit) elif hypothesis == 'equivalence': if alpha is not None: self._alpha = 1 - alpha else: self._alpha = None if power is not None: self._beta = (power) / 2 elif beta is not None: self._beta = (1 - beta) / 2 else: self._beta = None if similarity_limit is None: raise ValueError('A similarity_limit must be provided') sigma_ratio = stdev_2 / (stdev_1 * similarity_limit) self.similarity_limit = similarity_limit self.sigma_ratio = sigma_ratio # Initialize the remaining arguments through the parent. super(VarianceBase, self).__init__(alpha=alpha, power=power, beta=beta, hypothesis=hypothesis)