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


Python chi2.sf方法代码示例

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


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

示例1: _p_value

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

        Notes
        -----
        The p-value can be found by comparing the calculated :math:`\chi^2` statistic to a chi-square distribution.
        The degrees of freedom is equal to :math:`k - 1` minus any additional reduction in the degrees of freedom, if
        specified.

        Returns
        -------
        p_value : float
            The p-value of the associated chi-square value and degrees of freedom.

        """
        pval = chi2.sf(self.chi_square, self.degrees_of_freedom)

        return pval 
开发者ID:aschleg,项目名称:hypothetical,代码行数:21,代码来源:normality.py

示例2: visualize_pruning

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def visualize_pruning(w_norm, n_retained,
                      title='Initial model weights vs theoretical for pruning'):
    fig, ax1 = plt.subplots()
    ax1.set_title(title)
    ax1.hist(w_norm, normed=True, bins=200, alpha=0.6, histtype='stepfilled',
             range=[0, n_retained * 5])
    ax1.axvline(x=n_retained, linewidth=1, color='r')
    ax1.set_ylabel('PDF', color='b')

    ax2 = ax1.twinx()
    ax2.set_ylabel('Survival Function', color='r')

    ax1.set_xlabel('w_norm')

    x = np.linspace(chi2.ppf(0.001, n_retained),
                    chi2.ppf(0.999, n_retained), 100)
    ax2.plot(x, chi2.sf(x, n_retained),
             'g-', lw=1, alpha=0.6, label='chi2 pdf')
    ax1.plot(x, chi2.pdf(x, n_retained),
             'r-', lw=1, alpha=0.6, label='chi2 pdf') 
开发者ID:menpo,项目名称:lsfm,代码行数:22,代码来源:visualize.py

示例3: asymptotic_p_value

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def asymptotic_p_value(self, log_likelihood_ratio, dof=None):
        """
        Calculates the p-value corresponding to a given log likelihood ratio and number of degrees of freedom assuming
        the asymptotic approximation.

        Parameters
        ----------
        log_likelihood_ratio : ndarray
            Log likelihood ratio (without the factor -2)

        dof : int or None, optional
            Number of parameters / degrees of freedom. None means the overall number of parameters is used. Default
            value: None.

        Returns
        -------
        p_values : ndarray
            p-values.

        """
        if dof is None:
            dof = self.n_parameters
        q = -2.0 * log_likelihood_ratio
        p_value = chi2.sf(x=q, df=dof)
        return p_value 
开发者ID:diana-hep,项目名称:madminer,代码行数:27,代码来源:asymptotic_limits.py

示例4: _p_value

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def _p_value(self):
        r"""
        Calculates the p-value given the chi-square test statistic and the degrees of freedom.

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

        """
        pval = chi2.sf(self.chi_square, self.degrees_freedom)

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

示例5: _p_value

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

        Returns
        -------
        pval: float
            The p-value of the Friedman test statistic given a chi-square distribution.

        """
        pval = chi2.sf(self.xr2, self.k - 1)

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

示例6: _test_statistic

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def _test_statistic(self):
        r"""
        Returns the Van der Waerden test statistic, :math:`T_1` and the associated p-value.

        Returns
        -------
        t1 : float
            The Van der Waerden test statistic
        p_value : float
            The computed p-value

        Notes
        -----
        The Van der Waerden test statistic, :math:`T_1` is defined as:

        .. math::

            T_1 = \frac{1}{s^2} \sum^k_{i=1} n_i (\bar{A}_i)^2

        References
        ----------
        Conover, W. J. (1999). Practical Nonparameteric Statistics (Third ed.). Wiley.

        Wikipedia contributors. "Van der Waerden test." Wikipedia, The Free Encyclopedia.
            Wikipedia, The Free Encyclopedia, 8 Feb. 2017. Web. 8 Mar. 2020.

        """
        average_scores = np.array([i for _, i in self.average_scores])
        t1 = np.sum(self._group_obs * average_scores ** 2) / self.score_variance

        p_value = chi2.sf(t1, self.k - 1)

        return t1, p_value

    # def _min_significant_difference(self):
    #     mse = self.score_variance * ((self.n - 1 - self.test_statistic) / (self.n - self.k))
    #
    #     msd = t.ppf(1 - self.alpha / 2, self.n - self.k) * np.sqrt(2 * mse / self.k)
    #
    #     return msd 
开发者ID:aschleg,项目名称:hypothetical,代码行数:42,代码来源:nonparametric.py

示例7: pvalues

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def pvalues(self):
        """
        (array) The p-values associated with the z-statistics of the
        coefficients. Note that the coefficients are assumed to have a Normal
        distribution.
        """
        return norm.sf(np.abs(self.zvalues)) * 2 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:mlemodel.py

示例8: _opt_var

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def _opt_var(self, nuisance_mu, pval=False):
        """
        This is the function to be optimized over a nuisance mean parameter
        to determine the likelihood ratio for the variance

        Parameters
        ----------
        nuisance_mu : float
            Value of a nuisance mean parameter

        Returns
        -------
        llr : float
            Log likelihood of a pre-specified variance holding the nuisance
            parameter constant
        """
        endog = self.endog
        nobs = self.nobs
        sig_data = ((endog - nuisance_mu) ** 2 \
                    - self.sig2_0)
        mu_data = (endog - nuisance_mu)
        est_vect = np.column_stack((mu_data, sig_data))
        eta_star = self._modif_newton(np.array([1. / nobs,
                                               1. / nobs]), est_vect,
                                                np.ones(nobs) * (1. / nobs))

        denom = 1 + np.dot(eta_star, est_vect.T)
        self.new_weights = 1. / nobs * 1. / denom
        llr = np.sum(np.log(nobs * self.new_weights))
        if pval:  # Used for contour plotting
            return chi2.sf(-2 * llr, 1)
        return -2 * llr 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:34,代码来源:descriptive.py

示例9: test_mean

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def test_mean(self, mu0, return_weights=False):
        """
        Returns - 2 x log-likelihood ratio, p-value and weights
        for a hypothesis test of the mean.

        Parameters
        ----------
        mu0 : float
            Mean value to be tested

        return_weights : bool
            If return_weights is True the funtion returns
            the weights of the observations under the null hypothesis.
            Default is False

        Returns
        -------
        test_results : tuple
            The log-likelihood ratio and p-value of mu0
        """
        self.mu0 = mu0
        endog = self.endog
        nobs = self.nobs
        eta_min = (1. - (1. / nobs)) / (self.mu0 - max(endog))
        eta_max = (1. - (1. / nobs)) / (self.mu0 - min(endog))
        eta_star = optimize.brentq(self._find_eta, eta_min, eta_max)
        new_weights = (1. / nobs) * 1. / (1. + eta_star * (endog - self.mu0))
        llr = -2 * np.sum(np.log(nobs * new_weights))
        if return_weights:
            return llr, chi2.sf(llr, 1), new_weights
        else:
            return llr, chi2.sf(llr, 1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:34,代码来源:descriptive.py

示例10: test_var

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def test_var(self, sig2_0, return_weights=False):
        """
        Returns  -2 x log-likelihoog ratio and the p-value for the
        hypothesized variance

        Parameters
        ----------
        sig2_0 : float
            Hypothesized variance to be tested

        return_weights : bool
            If True, returns the weights that maximize the
            likelihood of observing sig2_0. Default is False

        Returns
        --------
        test_results : tuple
            The  log-likelihood ratio and the p_value  of sig2_0

        Examples
        --------
        >>> import numpy as np
        >>> import statsmodels.api as sm
        >>> random_numbers = np.random.standard_normal(1000)*100
        >>> el_analysis = sm.emplike.DescStat(random_numbers)
        >>> hyp_test = el_analysis.test_var(9500)
        """
        self.sig2_0 = sig2_0
        mu_max = max(self.endog)
        mu_min = min(self.endog)
        llr = optimize.fminbound(self._opt_var, mu_min, mu_max, \
                                 full_output=1)[1]
        p_val = chi2.sf(llr, 1)
        if return_weights:
            return llr, p_val, self.new_weights.T
        else:
            return  llr, p_val 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:39,代码来源:descriptive.py

示例11: test_kurt

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def test_kurt(self, kurt0, return_weights=False):
        """
        Returns -2 x log-likelihood and the p-value for the hypothesized
        kurtosis.

        Parameters
        ----------
        kurt0 : float
            Kurtosis value to be tested

        return_weights : bool
            If True, function also returns the weights that
            maximize the likelihood ratio. Default is False.

        Returns
        -------
        test_results : tuple
            The log-likelihood ratio and p-value of kurt0
        """
        self.kurt0 = kurt0
        start_nuisance = np.array([self.endog.mean(),
                                       self.endog.var()])

        llr = optimize.fmin_powell(self._opt_kurt, start_nuisance,
                                     full_output=1, disp=0)[1]
        p_val = chi2.sf(llr, 1)
        if return_weights:
            return  llr, p_val, self.new_weights.T
        return llr, p_val 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:31,代码来源:descriptive.py

示例12: test_joint_skew_kurt

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def test_joint_skew_kurt(self, skew0, kurt0, return_weights=False):
        """
        Returns - 2 x log-likelihood and the p-value for the joint
        hypothesis test for skewness and kurtosis

        Parameters
        ----------
        skew0 : float
            Skewness value to be tested
        kurt0 : float
            Kurtosis value to be tested

        return_weights : bool
            If True, function also returns the weights that
            maximize the likelihood ratio. Default is False.

        Returns
        -------
        test_results : tuple
            The log-likelihood ratio and p-value  of the joint hypothesis test.
        """
        self.skew0 = skew0
        self.kurt0 = kurt0
        start_nuisance = np.array([self.endog.mean(),
                                       self.endog.var()])

        llr = optimize.fmin_powell(self._opt_skew_kurt, start_nuisance,
                                     full_output=1, disp=0)[1]
        p_val = chi2.sf(llr, 2)
        if return_weights:
            return llr, p_val, self.new_weights.T
        return llr, p_val 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:34,代码来源:descriptive.py

示例13: mv_test_mean

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def mv_test_mean(self, mu_array, return_weights=False):
        """
        Returns -2 x log likelihood and the p-value
        for a multivariate hypothesis test of the mean

        Parameters
        ----------
        mu_array  : 1d array
            Hypothesized values for the mean.  Must have same number of
            elements as columns in endog

        return_weights : bool
            If True, returns the weights that maximize the
            likelihood of mu_array. Default is False.

        Returns
        -------
        test_results : tuple
            The log-likelihood ratio and p-value for mu_array
        """
        endog = self.endog
        nobs = self.nobs
        if len(mu_array) != endog.shape[1]:
            raise Exception('mu_array must have the same number of \
                           elements as the columns of the data.')
        mu_array = mu_array.reshape(1, endog.shape[1])
        means = np.ones((endog.shape[0], endog.shape[1]))
        means = mu_array * means
        est_vect = endog - means
        start_vals = 1. / nobs * np.ones(endog.shape[1])
        eta_star = self._modif_newton(start_vals, est_vect,
                                      np.ones(nobs) * (1. / nobs))
        denom = 1 + np.dot(eta_star, est_vect.T)
        self.new_weights = 1 / nobs * 1 / denom
        llr = -2 * np.sum(np.log(nobs * self.new_weights))
        p_val = chi2.sf(llr, mu_array.shape[1])
        if return_weights:
            return llr, p_val,  self.new_weights.T
        else:
            return llr, p_val 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:42,代码来源:descriptive.py

示例14: test_corr

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def test_corr(self, corr0, return_weights=0):
        """
        Returns -2 x log-likelihood ratio and  p-value for the
        correlation coefficient between 2 variables

        Parameters
        ----------
        corr0 : float
            Hypothesized value to be tested

        return_weights : bool
            If true, returns the weights that maximize
            the log-likelihood at the hypothesized value
        """
        nobs = self.nobs
        endog = self.endog
        if endog.shape[1] != 2:
            raise Exception('Correlation matrix not yet implemented')
        nuis0 = np.array([endog[:, 0].mean(),
                              endog[:, 0].var(),
                              endog[:, 1].mean(),
                              endog[:, 1].var()])

        x0 = np.zeros(5)
        weights0 = np.array([1. / nobs] * int(nobs))
        args = (corr0, endog, nobs, x0, weights0)
        llr = optimize.fmin(self._opt_correl, nuis0, args=args,
                                     full_output=1, disp=0)[1]
        p_val = chi2.sf(llr, 1)
        if return_weights:
            return llr, p_val, self.new_weights.T
        return llr, p_val 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:34,代码来源:descriptive.py

示例15: p_z_norm

# 需要导入模块: from scipy.stats import chi2 [as 别名]
# 或者: from scipy.stats.chi2 import sf [as 别名]
def p_z_norm(est, se):
    '''Convert estimate and se to Z-score and P-value.'''
    try:
        Z = est / se
    except (FloatingPointError, ZeroDivisionError):
        Z = float('inf')

    P = chi2.sf(Z ** 2, 1, loc=0, scale=1)  # 0 if Z=inf
    return P, Z 
开发者ID:JonJala,项目名称:mtag,代码行数:11,代码来源:regressions.py


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