Exemple #1
0
    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, beta=None, power=None, p=None):
        # There should be a better way.
        # This loop both checks the values for p and caclualtes a value needed
        # for the calculation.
        self._denom = 0
        if isinstance(p, list):
            len_p = len(p)
            self.df = len_p * (len_p - 1) / 2.0
            self._adjustment = 0
            for i in range(len_p - 1):
                if isinstance(p, list):
                    for j in range(i, len_p):
                        is_in_0_1(p[i][j],
                                  'All values of p should be in [0, 1].')
                        is_in_0_1(p[j][i],
                                  'All values of p should be in [0, 1].')
                        self._denom += ((p[i][j] - p[j][i])**2 /
                                        (p[i][j] + p[j][i]))
                else:
                    raise ValueError("Each list in `p` must be a "
                                     "list numerics")
        else:
            raise ValueError("`p` must be a list of lists  of numerics")

        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        # Set remaining variables.
        super(StuartMaxwell, self).__init__(alpha=alpha,
                                            beta=beta,
                                            power=power)
Exemple #3
0
    def __init__(self,
                 n=None,
                 alpha=None,
                 beta=None,
                 power=None,
                 p=None,
                 pi=None):
        self._check_list(p, 'p')

        if pi is None:
            pi = [1 / float(len(p))] * len(p)
        else:
            self._check_list(pi, 'pi')

        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        num = 0
        denom = 0
        for stratum in range(len(p)):
            rowsums = [sum(p[stratum][0]), sum(p[stratum][1])]
            colsums = [
                p[stratum][0][0] + p[stratum][1][0],
                p[stratum][0][1] + p[stratum][1][1]
            ]
            num += pi[stratum] * (p[stratum][0][0] - rowsums[0] * colsums[0])
            denom += (pi[stratum] * rowsums[0] * rowsums[1] * colsums[0] *
                      colsums[1])

        self.delta = num / math.sqrt(denom)
        self.n = n

        # Set remaining variables.
        super(CMH, self).__init__(alpha=alpha, beta=beta, power=power)
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
    def __init__(self,
                 n=None,
                 alpha=None,
                 beta=None,
                 power=None,
                 p_2=None,
                 p_3=None,
                 p_4=None):
        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        is_in_0_1(p_2, 'p_2 should be in [0, 1].')
        is_in_0_1(p_3, 'p_3 should be in [0, 1].')
        is_in_0_1(p_4, 'p_4 should be in [0, 1].')

        self.p_2 = p_2
        self.p_3 = p_3
        self.p_4 = p_4

        # Initialize the remaining arguments through the parent.
        super(OneSample, self).__init__(alpha=alpha,
                                        power=power,
                                        beta=beta,
                                        hypothesis=None)
Exemple #7
0
    def __init__(self,
                 n=None,
                 alpha=None,
                 beta=None,
                 power=None,
                 p=None,
                 p_0=None,
                 margin=None):

        is_in_0_1(p, 'p')
        self.p = p

        is_in_0_1(p_0, 'p_0')
        self.p_0 = p_0

        if margin is not None:
            is_in_0_1(margin + p_0, 'margin + p_0')
            self.margin = margin
            self.p_0 += margin
        else:
            self.margin = 0

        if n is not None:
            is_integer(n, 'n')
        self.n = n

        super(Binomial, self).__init__(alpha=alpha,
                                       power=power,
                                       beta=beta,
                                       hypothesis='equality')
Exemple #8
0
    def __init__(self,
                 n=None,
                 alpha=None,
                 beta=None,
                 power=None,
                 p_0=None,
                 p=None):
        if isinstance(p, list):
            for value in p:
                is_in_0_1(value, 'All values of p should be in (0, 1).')
        else:
            raise ValueError("`p` must be a list of Numerics.")
        self.p = p

        if isinstance(p_0, list):
            for value in p_0:
                is_in_0_1(value, 'All values of p_0 should be in (0, 1).')
        else:
            raise ValueError("`p_0` must be a list of Numerics.")
        self.p_0 = p_0

        if not len(p) == len(p_0):
            raise ValueError("`p_0` and `p` must have the same length.")

        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        # Set remaining variables.
        super(Pearson, self).__init__(alpha=alpha, beta=beta, power=power)
    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)
Exemple #10
0
    def __init__(self,
                 n=None,
                 alpha=None,
                 beta=None,
                 power=None,
                 method=None,
                 dist=None,
                 seed=None,
                 **kwargs):
        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        if dist in dir(stats):
            self.dist = getattr(stats, dist)(**kwargs)

        if seed is None:
            self.seed = self._SEED
        else:
            self.seed = seed

        if method == 'anderson' or method == 'anderson-darling':
            # Need to figure out how to do this right
            raise ValueError('{} is not a valid method'.format(method))
        elif method == 'kolmogorov-smirnov' or method == 'ks':

            def norm_ks(rvs):
                return stats.kstest(rvs, 'norm')

            self.normal_test = norm_ks
        elif method == 'kurt' or method == 'kurtosis':
            self.normal_test = stats.kurtosistest
            self._minN = 20
        elif method == 'martinez-iglewicz':
            raise ValueError('{} is not a valid method'.format(method))
        elif method in ['normaltest', 'omnibus']:
            self.normal_test = stats.normaltest
            self._minN = 20
        elif method == 'range':
            raise ValueError('{} is not a valid method'.format(method))
        elif method in ['shapiro', 'sw', 'shapiro-wilks']:
            self.normal_test = stats.shapiro
        elif method in ['skew', 'skewness']:
            self.normal_test = stats.skewtest
            self._minN = 8
        else:
            raise ValueError('{} is not a valid method'.format(method))

        # Initialize the remaining arguments through the parent.
        super(Normal, self).__init__(alpha=alpha,
                                     power=power,
                                     beta=beta,
                                     hypothesis=None)
Exemple #11
0
    def __init__(self,
                 n=None,
                 alpha=None,
                 beta=None,
                 power=None,
                 method=None,
                 dist=None,
                 compare_dist=None,
                 seed=None,
                 **kwargs):
        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        if dist in dir(stats):
            self.dist = getattr(stats, dist)(**kwargs)
        else:
            raise ValueError('{} is not a valid distribution'.format(dist))

        if compare_dist not in dir(stats):
            raise ValueError(
                '{} is not a valid distribution'.format(compare_dist))

        if seed is None:
            self.seed = self._SEED
        else:
            self.seed = seed

        if method == 'anderson' or method == 'anderson-darling':
            if compare_dist not in [
                    "norm", "expon", "logistic", "gumbel", "gumbel_l",
                    "gumbel_r", "extreme1"
            ]:
                raise ValueError(
                    '{} is not a valid distribution'.format(compare_dist))

            def dist_anderson(rvs):
                return stats.anderson(rvs, dist=compare_dist)

            self.distribution_test = dist_anderson
        elif method == 'kolmogorov-smirnov' or method == 'ks':

            def dist_ks(rvs):
                return stats.kstest(rvs, dist=compare_dist)

            self.distribution_test = dist_ks

        # Initialize the remaining arguments through the parent.
        super(Distribution, self).__init__(alpha=alpha,
                                           power=power,
                                           beta=beta,
                                           hypothesis=None)
Exemple #12
0
    def __init__(self, n=None, alpha=None, beta=None, power=None,
                 p_1=None, p_2=None):
        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        is_in_0_1(p_1, 'p_1 should be in [0, 1].')
        is_in_0_1(p_2, 'p_2 should be in [0, 1].')

        self.p_1 = p_1
        self.p_2 = p_2

        # Initialize the remaining arguments through the parent.
        super(Independance, self).__init__(alpha=alpha, power=power,
                                           beta=beta, hypothesis=None)
Exemple #13
0
    def __init__(self, n=None, alpha=None, beta=None, power=None,
                 p_2=None, p_3=None, p_4=None):
        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        is_in_0_1(p_2, 'p_2 should be in [0, 1].')
        is_in_0_1(p_3, 'p_3 should be in [0, 1].')
        is_in_0_1(p_4, 'p_4 should be in [0, 1].')

        self.p_2 = p_2
        self.p_3 = p_3
        self.p_4 = p_4

        # Initialize the remaining arguments through the parent.
        super(OneSample, self).__init__(alpha=alpha, power=power,
                                        beta=beta, hypothesis=None)
Exemple #14
0
    def __init__(self, n=None, alpha=None, beta=None, power=None, p_01=None,
                 p_10=None):

        is_in_0_1(p_01, 'p_01 should be in [0, 1].')
        is_in_0_1(p_10, 'p_10 should be in [0, 1].')

        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        self.p_01 = p_01
        self.p_10 = p_10
        self.alpha_factor = math.sqrt(p_01 + p_10)
        self.beta_factor = math.sqrt(p_10 + p_01 - (p_01 - p_10)**2)

        # Set remaining variables.
        super(McNemar, self).__init__(alpha=alpha, beta=beta, power=power)
Exemple #15
0
    def __init__(self, n=None, alpha=None, beta=None, power=None, method=None,
                 dist=None, seed=None, **kwargs):
        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        if dist in dir(stats):
            self.dist = getattr(stats, dist)(**kwargs)

        if seed is None:
            self.seed = self._SEED
        else:
            self.seed = seed

        if method == 'anderson' or method == 'anderson-darling':
            # Need to figure out how to do this right
            raise ValueError('{} is not a valid method'.format(method))
        elif method == 'kolmogorov-smirnov' or method == 'ks':
            def norm_ks(rvs):
                return stats.kstest(rvs, 'norm')
            self.normal_test = norm_ks
        elif method == 'kurt' or method == 'kurtosis':
            self.normal_test = stats.kurtosistest
            self._minN = 20
        elif method == 'martinez-iglewicz':
            raise ValueError('{} is not a valid method'.format(method))
        elif method in ['normaltest', 'omnibus']:
            self.normal_test = stats.normaltest
            self._minN = 20
        elif method == 'range':
            raise ValueError('{} is not a valid method'.format(method))
        elif method in ['shapiro', 'sw', 'shapiro-wilks']:
            self.normal_test = stats.shapiro
        elif method in ['skew', 'skewness']:
            self.normal_test = stats.skewtest
            self._minN = 8
        else:
            raise ValueError('{} is not a valid method'.format(method))

        # Initialize the remaining arguments through the parent.
        super(Normal, self).__init__(alpha=alpha, power=power,
                                     beta=beta, hypothesis=None)
    def __init__(self, n=None, alpha=None, beta=None, power=None, p=None):
        # This should be made much better (see CMH)
        if isinstance(p, list):
            for values in p:
                if isinstance(values, list):
                    for value in values:
                        is_in_0_1(value,
                                  'All values of p should be in (0, 1).')
                else:
                    raise ValueError("Each list in `p` must be a list "
                                     "of numerics")
        else:
            raise ValueError("`p` must be a list of lists  of numerics")
        self.p = p

        # needed for degree of freedom calculations
        rows = len(p)
        cols = len(p[0])
        self.df = (rows - 1) * (cols - 1)
        self._denom = 0

        # This will be much improved when I implement this as a matrix!
        colsums = [0] * cols
        for i in range(rows):
            for j in range(cols):
                colsums[j] += p[i][j]

        for i in range(rows):
            rowsum = sum(p[i])
            for j in range(cols):
                self._denom += ((p[i][j] - rowsum * colsums[j])**2 /
                                (rowsum * colsums[j]))

        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        # Set remaining variables.
        super(PearsonIndependance, self).__init__(alpha=alpha,
                                                  beta=beta,
                                                  power=power)
Exemple #17
0
    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)
Exemple #18
0
    def __init__(self, n=None, alpha=None, beta=None, power=None,
                 p=None, p_0=None, margin=None):

        is_in_0_1(p, 'p')
        self.p = p

        is_in_0_1(p_0, 'p_0')
        self.p_0 = p_0

        if margin is not None:
            is_in_0_1(margin + p_0, 'margin + p_0')
            self.margin = margin
            self.p_0 += margin
        else:
            self.margin = 0

        if n is not None:
            is_integer(n, 'n')
        self.n = n

        super(Binomial, self).__init__(alpha=alpha, power=power,
                                       beta=beta, hypothesis='equality')
Exemple #19
0
    def __init__(self,
                 n=None,
                 alpha=None,
                 beta=None,
                 power=None,
                 p_01=None,
                 p_10=None):

        is_in_0_1(p_01, 'p_01 should be in [0, 1].')
        is_in_0_1(p_10, 'p_10 should be in [0, 1].')

        if n is not None:
            is_integer(n, '`n` should be of type Int.')
        self.n = n

        self.p_01 = p_01
        self.p_10 = p_10
        self.alpha_factor = math.sqrt(p_01 + p_10)
        self.beta_factor = math.sqrt(p_10 + p_01 - (p_01 - p_10)**2)

        # Set remaining variables.
        super(McNemar, self).__init__(alpha=alpha, beta=beta, power=power)