當前位置: 首頁>>代碼示例>>Python>>正文


Python stats.t方法代碼示例

本文整理匯總了Python中scipy.stats.t方法的典型用法代碼示例。如果您正苦於以下問題:Python stats.t方法的具體用法?Python stats.t怎麽用?Python stats.t使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.stats的用法示例。


在下文中一共展示了stats.t方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def __init__(self, endog, exog=None, **kwargs):
        missing = kwargs.pop('missing', 'none')
        hasconst = kwargs.pop('hasconst', None)
        self.data = self._handle_data(endog, exog, missing, hasconst,
                                      **kwargs)
        self.k_constant = self.data.k_constant
        self.exog = self.data.exog
        self.endog = self.data.endog
        self._data_attr = []
        self._data_attr.extend(['exog', 'endog', 'data.exog', 'data.endog'])
        if 'formula' not in kwargs:  # won't be able to unpickle without these
            self._data_attr.extend(['data.orig_endog', 'data.orig_exog'])
        # store keys for extras if we need to recreate model instance
        # we don't need 'missing', maybe we need 'hasconst'
        self._init_keys = list(kwargs.keys())
        if hasconst is not None:
            self._init_keys.append('hasconst') 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:model.py

示例2: __init__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def __init__(self, predicted_mean, var_pred_mean, var_resid=None,
                 df=None, dist=None, row_labels=None, linpred=None, link=None):
        # TODO: is var_resid used? drop from arguments?
        self.predicted_mean = predicted_mean
        self.var_pred_mean = var_pred_mean
        self.df = df
        self.var_resid = var_resid
        self.row_labels = row_labels
        self.linpred = linpred
        self.link = link

        if dist is None or dist == 'norm':
            self.dist = stats.norm
            self.dist_args = ()
        elif dist == 't':
            self.dist = stats.t
            self.dist_args = (self.df,)
        else:
            self.dist = dist
            self.dist_args = () 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:_prediction.py

示例3: summary_frame

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def summary_frame(self, what='all', alpha=0.05):
        # TODO: finish and cleanup
        import pandas as pd
        from statsmodels.compat.collections import OrderedDict
        #ci_obs = self.conf_int(alpha=alpha, obs=True) # need to split
        ci_mean = self.conf_int(alpha=alpha)
        to_include = OrderedDict()
        to_include['mean'] = self.predicted_mean
        to_include['mean_se'] = self.se_mean
        to_include['mean_ci_lower'] = ci_mean[:, 0]
        to_include['mean_ci_upper'] = ci_mean[:, 1]


        self.table = to_include
        #OrderedDict doesn't work to preserve sequence
        # pandas dict doesn't handle 2d_array
        #data = np.column_stack(list(to_include.values()))
        #names = ....
        res = pd.DataFrame(to_include, index=self.row_labels,
                           columns=to_include.keys())
        return res 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:23,代碼來源:_prediction.py

示例4: gammamomentcond2

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def gammamomentcond2(distfn, params, mom2, quantile=None):
    '''estimate distribution parameters based method of moments (mean,
    variance) for distributions with 1 shape parameter and fixed loc=0.

    Returns
    -------
    difference : array
        difference between theoretical and empirical moments

    Notes
    -----
    first test version, quantile argument not used

    The only difference to previous function is return type.

    '''
    alpha, scale = params
    mom2s = distfn.stats(alpha, 0.,scale)
    return np.array(mom2)-mom2s



######### fsolve doesn't move in small samples, fmin not very accurate 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:estimators.py

示例5: __init__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def __init__(self):
        #super(SkewT_gen,self).__init__(
        distributions.rv_continuous.__init__(self,
            name = 'Skew T distribution', shapes = 'df, alpha',
            extradoc = '''
Skewed T distribution by Azzalini, A. & Capitanio, A. (2003)_

the pdf is given by:
 pdf(x) = 2.0 * t.pdf(x, df) * t.cdf(df+1, alpha*x*np.sqrt((1+df)/(x**2+df)))

with alpha >=0

Note: different from skewed t distribution by Hansen 1999
.._
Azzalini, A. & Capitanio, A. (2003), Distributions generated by perturbation of
symmetry with emphasis on a multivariate skew-t distribution,
appears in J.Roy.Statist.Soc, series B, vol.65, pp.367-389

'''                               ) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:21,代碼來源:extras.py

示例6: __init__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def __init__(self, predicted_mean, var_pred_mean, var_resid,
                 df=None, dist=None, row_labels=None):
        self.predicted_mean = predicted_mean
        self.var_pred_mean = var_pred_mean
        self.df = df
        self.var_resid = var_resid
        self.row_labels = row_labels

        if dist is None or dist == 'norm':
            self.dist = stats.norm
            self.dist_args = ()
        elif dist == 't':
            self.dist = stats.t
            self.dist_args = (self.df,)
        else:
            self.dist = dist
            self.dist_args = () 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:_prediction.py

示例7: summary_frame

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def summary_frame(self, what='all', alpha=0.05):
        # TODO: finish and cleanup
        import pandas as pd
        from statsmodels.compat.collections import OrderedDict
        ci_obs = self.conf_int(alpha=alpha, obs=True) # need to split
        ci_mean = self.conf_int(alpha=alpha, obs=False)
        to_include = OrderedDict()
        to_include['mean'] = self.predicted_mean
        to_include['mean_se'] = self.se_mean
        to_include['mean_ci_lower'] = ci_mean[:, 0]
        to_include['mean_ci_upper'] = ci_mean[:, 1]
        to_include['obs_ci_lower'] = ci_obs[:, 0]
        to_include['obs_ci_upper'] = ci_obs[:, 1]

        self.table = to_include
        #OrderedDict doesn't work to preserve sequence
        # pandas dict doesn't handle 2d_array
        #data = np.column_stack(list(to_include.values()))
        #names = ....
        res = pd.DataFrame(to_include, index=self.row_labels,
                           columns=to_include.keys())
        return res 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:24,代碼來源:_prediction.py

示例8: test_dist_keyword

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def test_dist_keyword(self):
        np.random.seed(12345)
        x = stats.norm.rvs(size=20)
        osm1, osr1 = stats.probplot(x, fit=False, dist='t', sparams=(3,))
        osm2, osr2 = stats.probplot(x, fit=False, dist=stats.t, sparams=(3,))
        assert_allclose(osm1, osm2)
        assert_allclose(osr1, osr2)

        assert_raises(ValueError, stats.probplot, x, dist='wrong-dist-name')
        assert_raises(AttributeError, stats.probplot, x, dist=[])

        class custom_dist(object):
            """Some class that looks just enough like a distribution."""
            def ppf(self, q):
                return stats.norm.ppf(q, loc=2)

        osm1, osr1 = stats.probplot(x, sparams=(2,), fit=False)
        osm2, osr2 = stats.probplot(x, dist=custom_dist(), fit=False)
        assert_allclose(osm1, osm2)
        assert_allclose(osr1, osr2) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:22,代碼來源:test_morestats.py

示例9: test_plot_kwarg

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def test_plot_kwarg(self):
        np.random.seed(7654321)
        fig = plt.figure()
        fig.add_subplot(111)
        x = stats.t.rvs(3, size=100)
        res1, fitres1 = stats.probplot(x, plot=plt)
        plt.close()
        res2, fitres2 = stats.probplot(x, plot=None)
        res3 = stats.probplot(x, fit=False, plot=plt)
        plt.close()
        res4 = stats.probplot(x, fit=False, plot=None)
        # Check that results are consistent between combinations of `fit` and
        # `plot` keywords.
        assert_(len(res1) == len(res2) == len(res3) == len(res4) == 2)
        assert_allclose(res1, res2)
        assert_allclose(res1, res3)
        assert_allclose(res1, res4)
        assert_allclose(fitres1, fitres2)

        # Check that a Matplotlib Axes object is accepted
        fig = plt.figure()
        ax = fig.add_subplot(111)
        stats.probplot(x, fit=False, plot=ax)
        plt.close() 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:26,代碼來源:test_morestats.py

示例10: test_alpha

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def test_alpha(self):
        np.random.seed(1234)
        x = stats.loggamma.rvs(5, size=50) + 5

        # Some regular values for alpha, on a small sample size
        _, _, interval = stats.boxcox(x, alpha=0.75)
        assert_allclose(interval, [4.004485780226041, 5.138756355035744])
        _, _, interval = stats.boxcox(x, alpha=0.05)
        assert_allclose(interval, [1.2138178554857557, 8.209033272375663])

        # Try some extreme values, see we don't hit the N=500 limit
        x = stats.loggamma.rvs(7, size=500) + 15
        _, _, interval = stats.boxcox(x, alpha=0.001)
        assert_allclose(interval, [0.3988867, 11.40553131])
        _, _, interval = stats.boxcox(x, alpha=0.999)
        assert_allclose(interval, [5.83316246, 5.83735292]) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:18,代碼來源:test_morestats.py

示例11: loadQualityModel

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def loadQualityModel(self):
        """Loads the coefficients from the rpy2 model estimated previously"""
        try:
            execPath = os.path.dirname(os.path.realpath(__file__))+'/'
        except:
            execPath = os.getcwd()+'/'
        if os.path.exists(self.qualityModelFn):
            fn = self.qualityModelFn
        elif os.path.exists(execPath+self.qualityModelFn):
            fn = execPath+self.qualityModelFn
        else:
            raise Exception('Quality model coefficients file %s not found' % self.qualityModelFn)
        with open(fn) as f:
            coeffLines = f.read().split('\n')

        for ii, cl in enumerate(coeffLines):
            if 'intercept' in cl.lower():
                coeffLines[ii] = 'intercept\t'+cl.split()[1]
                break
            raise Exception('Quality model %s must include an intercept' % self.qualityModelFn)
        self.qualityModelCoeffs = dict([(cl.split()[0], float(cl.split()[1])) for cl in coeffLines if len(cl.split()) == 2])
        knownCols = ['intercept', 'frechet_dist', 'll_dist_mean', 'll_dist_min', 'll_topol_mean', 'll_topol_min', 'll_distratio_mean', 'll_distratio_min', 'gpsMatchRatio', 'matchGpsRatio']
        if any([cc not in knownCols for cc in self.qualityModelCoeffs]):
            raise Exception('Error in quality model %s. Coefficient name not understood' % self.qualityModelFn) 
開發者ID:amillb,項目名稱:pgMapMatch,代碼行數:26,代碼來源:mapmatcher.py

示例12: _handle_data

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def _handle_data(self, endog, exog, missing, hasconst, **kwargs):
        data = handle_data(endog, exog, missing, hasconst, **kwargs)
        # kwargs arrays could have changed, easier to just attach here
        for key in kwargs:
            if key in ['design_info', 'formula']:  # leave attached to data
                continue
            # pop so we don't start keeping all these twice or references
            try:
                setattr(self, key, data.__dict__.pop(key))
            except KeyError:  # panel already pops keys in data handling
                pass
        return data 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:14,代碼來源:model.py

示例13: fit

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def fit(self, start_params=None, method='nm', maxiter=500, full_output=1,
            disp=1, callback=None, retall=0, **kwargs):
        """
        Fit the model using maximum likelihood.

        The rest of the docstring is from
        statsmodels.LikelihoodModel.fit
        """
        if start_params is None:
            if hasattr(self, 'start_params'):
                start_params = self.start_params
            else:
                start_params = 0.1 * np.ones(self.nparams)

        fit_method = super(GenericLikelihoodModel, self).fit
        mlefit = fit_method(start_params=start_params,
                            method=method, maxiter=maxiter,
                            full_output=full_output,
                            disp=disp, callback=callback, **kwargs)
        genericmlefit = GenericLikelihoodModelResults(self, mlefit)

        # amend param names
        exog_names = [] if (self.exog_names is None) else self.exog_names
        k_miss = len(exog_names) - len(mlefit.params)
        if not k_miss == 0:
            if k_miss < 0:
                self._set_extra_params_names(['par%d' % i
                                              for i in range(-k_miss)])
            else:
                # I don't want to raise after we have already fit()
                import warnings
                warnings.warn('more exog_names than parameters', ValueWarning)

        return genericmlefit
    # fit.__doc__ += LikelihoodModel.fit.__doc__ 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:37,代碼來源:model.py

示例14: tvalues

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def tvalues(self):
        """
        Return the t-statistic for a given parameter estimate.
        """
        return self.params / self.bse 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:7,代碼來源:model.py

示例15: pvalues

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import t [as 別名]
def pvalues(self):
        if self.use_t:
            df_resid = getattr(self, 'df_resid_inference', self.df_resid)
            return stats.t.sf(np.abs(self.tvalues), df_resid) * 2
        else:
            return stats.norm.sf(np.abs(self.tvalues)) * 2 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:8,代碼來源:model.py


注:本文中的scipy.stats.t方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。