当前位置: 首页>>代码示例>>Python>>正文


Python chi2.cdf方法代码示例

本文整理汇总了Python中scipy.stats.chi2.cdf方法的典型用法代码示例。如果您正苦于以下问题:Python chi2.cdf方法的具体用法?Python chi2.cdf怎么用?Python chi2.cdf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats.chi2的用法示例。


在下文中一共展示了chi2.cdf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _pvalue

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def _pvalue(self):
        r"""
        Returns the p-value using the computed F-statistic

        Returns
        -------
        p : float
            The computed p-value given the found F-statistic and the group and residual degrees of freedom.

        Notes
        -----
        The :code:`cdf` method from Scipy's :code:`stats.f` class is used to find the p-value.

        References
        ----------
        Rencher, A. (n.d.). Methods of Multivariate Analysis (2nd ed.).
            Brigham Young University: John Wiley & Sons, Inc.

        """
        p = 1 - f.cdf(self.f_statistic,
                      self.group_degrees_of_freedom,
                      self.residual_degrees_of_freedom)

        return p 
开发者ID:aschleg,项目名称:hypothetical,代码行数:26,代码来源:aov.py

示例2: _mcnemar_p_value

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def _mcnemar_p_value(self):
        r"""
        Computes the p-value of the asymptotic McNemar test.

        Returns
        -------
        p : float
            The p-value of the :math:`\chi^2` statistic.

        Notes
        -----
        The McNemar test statistic has a chi-square distribution.

        """
        p = 1 - chi2.cdf(self.mcnemar_x2_statistic, 1)

        return p 
开发者ID:aschleg,项目名称:hypothetical,代码行数:19,代码来源:contingency.py

示例3: _p_val

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def _p_val(self):
        r"""
        Returns the p-value.

        Returns
        -------
        p : float
            The computed p value.

        Notes
        -----
        When sample sizes are large enough (:math:`n > 20`), the distribution of :math:`U` is normally
        distributed.

        """
        p = 1 - norm.cdf(self.z_value)

        return p * 2 
开发者ID:aschleg,项目名称:hypothetical,代码行数:20,代码来源:nonparametric.py

示例4: _logrank_test

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def _logrank_test(x, group_col):
        x['next_metric'] = x.groupby(group_col).metric.shift(-1)
        x['o'] = (x['metric'] - x['next_metric'])
        oj = x.groupby('bins').o.sum()
        nj = x.groupby('bins').metric.sum()
        exp = (oj / nj).rename('exp')
        x = x.join(exp, on='bins')
        x1 = x[x[group_col]]
        x1.index = x1.bins
        up = (x1.o - x1.exp * x1.metric).sum()
        var = ((oj * (x1.metric / nj) * (1 - x1.metric / nj) * (nj - oj)) / (nj - 1)).sum()
        z = up ** 2 / var

        from scipy.stats import chi2
        pval = 1 - chi2.cdf(z, df=1)
        print(f"""
        There is {'' if pval <= 0.05 else 'no '}significant difference
        log-rank chisq: {z}
        P-value: {pval}
        """) 
开发者ID:retentioneering,项目名称:retentioneering-tools,代码行数:22,代码来源:utils.py

示例5: confidence

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def confidence(self, likelihood_stat):
        p_value = chi2.cdf(likelihood_stat, 1)
        return p_value 
开发者ID:mvaz,项目名称:osqf2015,代码行数:5,代码来源:model.py

示例6: power_to_pvalue

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def power_to_pvalue(power, dof):
    """
    Converts a power to a p-value, under the assumption that the power is chi2
    distribution with `dof` degrees of freedom.
    """
    pvalue = 1 - _chi2.cdf(dof * power, dof)

    return pvalue 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:10,代码来源:signal.py

示例7: maxpower_pvalue

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def maxpower_pvalue(maxpower, numpowers, dof):
    """
    The p-value of the test statistic max(lambda_i) where there are `numpowers`
    lambda_i test statistics, and they are i.i.d. as chi2 with `dof` degrees
    of freedom. This approximates the p-value of the largest power in "clickstream"
    power spectrum (generated from `spectrum`), with the DOF given by the number of
    clicks per times.

    """
    pvalue = 1 - _chi2.cdf(maxpower * dof, dof) ** (numpowers - 1)

    return pvalue 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:14,代码来源:signal.py

示例8: sign_test

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def sign_test(data):
    """ Given the results drawn from two algorithms/methods X and Y, the sign test analyses if
    there is a difference between X and Y.

    .. note:: Null Hypothesis: Pr(X<Y)= 0.5

    :param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
    :return p_value: The associated p-value from the binomial distribution.
    :return bstat: Number of successes.
    """

    if type(data) == pd.DataFrame:
        data = data.values

    if data.shape[1] == 2:
        X, Y = data[:, 0], data[:, 1]
        n_perf = data.shape[0]
    else:
        raise ValueError(
            'Initialization ERROR. Incorrect number of dimensions for axis 1')

    # Compute the differences
    Z = X - Y
    # Compute the number of pairs Z<0
    Wminus = sum(Z < 0)
    # If H_0 is true ---> W follows Binomial(n,0.5)
    p_value_minus = 1 - binom.cdf(k=Wminus, p=0.5, n=n_perf)

    # Compute the number of pairs Z>0
    Wplus = sum(Z > 0)
    # If H_0 is true ---> W follows Binomial(n,0.5)
    p_value_plus = 1 - binom.cdf(k=Wplus, p=0.5, n=n_perf)

    p_value = 2 * min([p_value_minus, p_value_plus])

    return pd.DataFrame(data=np.array([Wminus, Wplus, p_value]), index=['Num X<Y', 'Num X>Y', 'p-value'],
                        columns=['Results']) 
开发者ID:jMetal,项目名称:jMetalPy,代码行数:39,代码来源:functions.py

示例9: friedman_test

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def friedman_test(data):
    """ Friedman ranking test.

    ..note:: Null Hypothesis: In a set of k (>=2) treaments (or tested algorithms), all the treatments are equivalent, so their average ranks should be equal.

    :param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
    :return p_value: The associated p-value.
    :return friedman_stat: Friedman's chi-square.
    """

    # Initial Checking
    if type(data) == pd.DataFrame:
        data = data.values

    if data.ndim == 2:
        n_samples, k = data.shape
    else:
        raise ValueError(
            'Initialization ERROR. Incorrect number of array dimensions')
    if k < 2:
        raise ValueError(
            'Initialization Error. Incorrect number of dimensions for axis 1.')

    # Compute ranks.
    datarank = ranks(data)

    # Compute for each algorithm the ranking average.
    avranks = np.mean(datarank, axis=0)

    # Get Friedman statistics
    friedman_stat = (12.0 * n_samples) / (k * (k + 1.0)) * \
                    (np.sum(avranks ** 2) - (k * (k + 1) ** 2) / 4.0)

    # Compute p-value
    p_value = (1.0 - chi2.cdf(friedman_stat, df=(k - 1)))

    return pd.DataFrame(data=np.array([friedman_stat, p_value]), index=['Friedman-statistic', 'p-value'],
                        columns=['Results']) 
开发者ID:jMetal,项目名称:jMetalPy,代码行数:40,代码来源:functions.py

示例10: _p_value

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def _p_value(self):
        r"""
        Computes the p-value of the :math:`H`-statistic approximated by the chi-square distribution.

        Returns
        -------
        p : float
            The computed p-value.

        Notes
        -----
        The :math:`p`-value is approximated by a chi-square distribution with :math:`k - 1` degrees
        of freedom.

        .. math::

            Pr(\chi^2_{k - 1} \geq H)

        References
        ----------
        Wikipedia contributors. (2018, May 21). Kruskal–Wallis one-way analysis of variance.
            In Wikipedia, The Free Encyclopedia. From
            https://en.wikipedia.org/w/index.php?title=Kruskal%E2%80%93Wallis_one-way_analysis_of_variance&oldid=842351945

        """
        p = 1 - chi2.cdf(self.H, self.dof)

        return p 
开发者ID:aschleg,项目名称:hypothetical,代码行数:30,代码来源:nonparametric.py

示例11: _pvalue

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def _pvalue(self):
        r"""
        Calculates the p-value.

        Returns
        -------
        p : float
            The calculated p-value

        Notes
        -----

        References
        ----------
        Siegel, S. (1956). Nonparametric statistics: For the behavioral sciences.
            McGraw-Hill. ISBN 07-057348-4

        """
        p = (1 - norm.cdf(np.abs(self.z)))

        if self.alternative == 'two-sided':
            p *= 2
        elif self.alternative == 'greater':
            p = 1 - p

        if p == 0:
            p = np.finfo(float).eps

        return p 
开发者ID:aschleg,项目名称:hypothetical,代码行数:31,代码来源:nonparametric.py

示例12: _p_value

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def _p_value(self):
        r"""
        Finds the associated p-value of the W test statistic.

        Returns
        -------
        p : float
            The computed p-value of the associated W test statistic.

        """
        p = 1 - f.cdf(self.test_statistic,
                      self.k - 1,
                      self.n - self.k)

        return p 
开发者ID:aschleg,项目名称:hypothetical,代码行数:17,代码来源:aov.py

示例13: ljung_box_test

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def ljung_box_test(residuals, lags=[1,2,3], alpha=0.5):
    from statsmodels.stats.diagnostic import acorr_ljungbox
    from scipy.stats import chi2
    
    stat, pval = acorr_ljungbox(residuals, lags=lags)
    
    rows = []

    for ct, Q in enumerate(stat):
      lag = ct+1
      p_value = 1 - chi2.cdf(Q, df=lag)
      critical_value = chi2.ppf(1 - alpha, df=lag)
      rows.append([lag, Q, p_value, critical_value, 'H0 accepted' if Q > critical_value else 'H0 rejected'])
        
    return pd.DataFrame(rows, columns=['Lag','Statistic','p-Value','Critical Value', 'Result']) 
开发者ID:PYFTS,项目名称:pyFTS,代码行数:17,代码来源:ResidualAnalysis.py

示例14: test_chi2

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def test_chi2(self, t, x_data, species=None, method='matrix', normalize=True):
        '''perform a Pearson's chi-square test. The statistics is computed as: sum_i (O_i - E_i)^2 / E_i, where O_i is the data and E_i is the model predication.

            The data can be either 1. stratified moments: 't' is an array of k distinct time points, 'x_data' is a m-by-k matrix of data, where m is the number of species.
            or 2. raw data: 't' is an array of k time points for k cells, 'x_data' is a m-by-k matrix of data, where m is the number of species. 
            Note that if the method is 'numerical', t has to monotonically increasing.

            If not all species are included in the data, use 'species' to specify the species of interest.

            Returns
            -------
            p: float
            The p-value of a one-tailed chi-square test.

            c2: float
            The chi-square statistics.

            df: integer
            Degree of freedom.
        '''
        if x_data.ndim == 1:
            x_data = x_data[None]

        self.simulator.integrate(t, method=method)
        x_model = self.simulator.x.T
        if species is not None:
            x_model = x_model[species]

        if normalize:
            scale = np.max(x_data, 1)
            x_data_norm = (x_data.T/scale).T
            x_model_norm = (x_model.T/scale).T
        else:
            x_data_norm = x_data
            x_model_norm = x_model
        c2 = np.sum((x_data_norm - x_model_norm)**2 / x_model_norm)
        #df = len(x_data.flatten()) - self.n_params - 1
        df = len(np.unique(t)) - self.n_params - 1
        p = 1 - chi2.cdf(c2, df)
        return p, c2, df 
开发者ID:aristoteleo,项目名称:dynamo-release,代码行数:42,代码来源:estimation_kinetic.py

示例15: filter

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import cdf [as 别名]
def filter(self, data, *args, **kwargs):

        if (len(data) == 4):
            c1 = data[0]
            n1 = data[1]
            c2 = data[2]
            n2 = data[3]
        else:
            c1 = data[0]
            n1 = self.n1
            c2 = data[1]
            n2 = self.n2

        if c1.ndim > 2:
            p = c1.shape[0]
        else:
            p = 1

        lnq = p * ((n1 + n2) * np.log(n1 + n2) - n1 * np.log(n1) - n2 * np.log(n2)) + \
              n1 * np.log(block_det(c1)) + \
              n2 * np.log(block_det(c2)) - \
              (n1 + n2) * np.log(block_det(c1 + c2))

        rho = 1 - (2 * p ** 2 - 1) * (1 / n1 + 1 / n2 - 1 / (n1 + n2)) / (6 * p)

        o_2 = p ** 2 * (p ** 2 - 1) * \
              (1 / n1 ** 2 + 1 / n2 ** 2 - 1 / (n1 + n2) ** 2) / (24 * rho ** 2) - \
              0.25 * p ** 2 * (1 - 1 / rho) ** 2

        lnq *= -2 * rho

        pfa = (1 - o_2) * chi2.cdf(lnq, p ** 2) + o_2 * chi2.cdf(lnq, p ** 2 + 4)

        return (pfa, median_filter(pfa > self.p_thresh, 3, mode='constant', cval=0)) 
开发者ID:birgander2,项目名称:PyRAT,代码行数:36,代码来源:ChangeDet.py


注:本文中的scipy.stats.chi2.cdf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。