本文整理汇总了Python中scipy.stats.t.cdf方法的典型用法代码示例。如果您正苦于以下问题:Python t.cdf方法的具体用法?Python t.cdf怎么用?Python t.cdf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats.t
的用法示例。
在下文中一共展示了t.cdf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_two_sample_students_test
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def test_two_sample_students_test(self):
sal_a = self.data.loc[self.data['discipline'] == 'A']['salary']
sal_b = self.data.loc[self.data['discipline'] == 'B']['salary']
ttest = tTest(y1=sal_a, y2=sal_b, var_equal=True)
test_summary = ttest.test_summary
assert_almost_equal(test_summary['Sample 1 Mean'], np.mean(sal_a))
assert_almost_equal(test_summary['Sample 2 Mean'], np.mean(sal_b))
assert_almost_equal(test_summary['t-statistic'], -3.1485647713976195)
assert_almost_equal(test_summary['p-value'], t.cdf(test_summary['t-statistic'],
test_summary['degrees of freedom']) * 2)
assert test_summary['alternative'] == 'two-sided'
assert test_summary['test description'] == "Two-Sample Student's t-test"
assert len(sal_a) + len(sal_b) - 2 == test_summary['degrees of freedom']
示例2: test_paired_sample_test
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def test_paired_sample_test(self):
sal_a = self.data.loc[self.data['discipline'] == 'A']['salary']
sal_b = self.data.loc[self.data['discipline'] == 'B']['salary']
sal_b2 = sal_b[0:len(sal_a)]
ttest = tTest(y1=sal_a, y2=sal_b2, paired=True)
test_summary = ttest.test_summary
assert_almost_equal(test_summary['Sample Difference Mean'], np.mean(np.array(sal_a) - np.array(sal_b2)))
assert_almost_equal(test_summary['t-statistic'], -2.3158121700626406)
assert_almost_equal(test_summary['p-value'], t.cdf(test_summary['t-statistic'],
test_summary['degrees of freedom']) * 2)
assert test_summary['alternative'] == 'two-sided'
assert test_summary['test description'] == 'Paired t-test'
assert len(sal_a) - 1 == test_summary['degrees of freedom']
示例3: ProbabilityImprovement
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def ProbabilityImprovement(self, tau, mean, std):
"""
Probability of Improvement acquisition function.
Parameters
----------
tau: float
Best observed function evaluation.
mean: float
Point mean of the posterior process.
std: float
Point std of the posterior process.
Returns
-------
float
Probability of improvement.
"""
z = (mean - tau - self.eps) / (std + self.eps)
return norm.cdf(z)
示例4: ExpectedImprovement
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def ExpectedImprovement(self, tau, mean, std):
"""
Expected Improvement acquisition function.
Parameters
----------
tau: float
Best observed function evaluation.
mean: float
Point mean of the posterior process.
std: float
Point std of the posterior process.
Returns
-------
float
Expected improvement.
"""
z = (mean - tau - self.eps) / (std + self.eps)
return (mean - tau) * norm.cdf(z) + std * norm.pdf(z)[0]
示例5: tExpectedImprovement
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def tExpectedImprovement(self, tau, mean, std, nu=3.0):
"""
Expected Improvement acquisition function. Only to be used with `tStudentProcess` surrogate.
Parameters
----------
tau: float
Best observed function evaluation.
mean: float
Point mean of the posterior process.
std: float
Point std of the posterior process.
Returns
-------
float
Expected improvement.
"""
gamma = (mean - tau - self.eps) / (std + self.eps)
return gamma * std * t.cdf(gamma, df=nu) + std * (1 + (gamma ** 2 - 1)/(nu - 1)) * t.pdf(gamma, df=nu)
示例6: summarize_bootstrap
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def summarize_bootstrap(data, save_weights=False):
""" Calculate summary of bootstrap samples
Args:
sample: (Brain_Data) Brain_Data instance of samples
save_weights: (bool) save bootstrap weights
Returns:
output: (dict) dictionary of Brain_Data summary images
"""
# Calculate SE of bootstraps
wstd = data.std()
wmean = data.mean()
wz = deepcopy(wmean)
wz.data = wmean.data / wstd.data
wp = deepcopy(wmean)
wp.data = 2*(1-norm.cdf(np.abs(wz.data)))
# Create outputs
output = {'Z': wz, 'p': wp, 'mean': wmean}
if save_weights:
output['samples'] = data
return output
示例7: whelchs_t
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def whelchs_t(a_mu, a_var, b_mu, b_var, a_n, b_n):
"""
:param np.ndarray a_mu:
:param np.ndarray a_var:
:param np.ndarray b_mu:
:param np.ndarray b_var:
:param int a_n:
:param int b_n:
:return float, float: statistic and p-value
"""
df = whelch_satterthwaite_df(a_var, b_var, a_n, b_n)
numerator = a_mu - b_mu # (samples, genes)
denominator = np.sqrt(a_var + b_var) # (samples, genes)
statistic = numerator / denominator # (samples, genes)
# statistic has NaNs where there are no observations of a or b (DivideByZeroError)
statistic[np.isnan(statistic)] = 0
median_statistic = np.median(np.abs(statistic), axis=0)
p = (1 - t.cdf(median_statistic, df)) * 2 # p-value
ci_95 = np.percentile(np.abs(statistic), [2.5, 97.5], axis=0).T
return median_statistic, p, ci_95
示例8: calc_prob_mom
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def calc_prob_mom(returns, other_returns):
"""
`Probabilistic momentum <http://cssanalytics.wordpress.com/2014/01/28/are-simple-momentum-strategies-too-dumb-introducing-probabilistic-momentum/>`_ (see `momentum investing <https://www.investopedia.com/terms/m/momentum_investing.asp>`_)
Basically the "probability or confidence that one asset
is going to outperform the other".
Source:
http://cssanalytics.wordpress.com/2014/01/28/are-simple-momentum-strategies-too-dumb-introducing-probabilistic-momentum/ # NOQA
"""
return t.cdf(returns.calc_information_ratio(other_returns),
len(returns) - 1)
示例9: test_two_sample_welch_test
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def test_two_sample_welch_test(self):
sal_a = self.data.loc[self.data['discipline'] == 'A']['salary']
sal_b = self.data.loc[self.data['discipline'] == 'B']['salary']
ttest = tTest(y1=sal_a, y2=sal_b)
test_summary = ttest.test_summary
assert_almost_equal(test_summary['Sample 1 Mean'], np.mean(sal_a))
assert_almost_equal(test_summary['Sample 2 Mean'], np.mean(sal_b))
assert_almost_equal(test_summary['t-statistic'], -3.1386989278486013)
assert_almost_equal(test_summary['degrees of freedom'], 377.89897288941387)
assert_almost_equal(test_summary['p-value'], t.cdf(test_summary['t-statistic'],
test_summary['degrees of freedom']) * 2)
assert test_summary['alternative'] == 'two-sided'
assert test_summary['test description'] == "Two-Sample Welch's t-test"
ttest_group = tTest(group=self.data['discipline'], y1=self.data['salary'])
test_group_summary = ttest_group.test_summary
assert_almost_equal(test_summary['Sample 1 Mean'], test_group_summary['Sample 1 Mean'])
assert_almost_equal(test_summary['Sample 2 Mean'], test_group_summary['Sample 2 Mean'])
assert_almost_equal(test_summary['p-value'], test_group_summary['p-value'])
assert_almost_equal(test_summary['degrees of freedom'], test_group_summary['degrees of freedom'], 5)
assert_almost_equal(test_summary['t-statistic'], test_group_summary['t-statistic'])
assert test_group_summary['alternative'] == 'two-sided'
assert test_group_summary['test description'] == "Two-Sample Welch's t-test"
示例10: _compute_pvalues
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def _compute_pvalues(self):
"""
Compute p-values of coefficients (and intercept if fit_intercept==True)
"""
tstat_coef = self.coef / self.se_coef
self.pvalue_coef = 2 * t.cdf(-abs(tstat_coef), self._dgf)
if self.fit_intercept:
tstat_intercept = self.intercept / self.se_intercept
self.pvalue_intercept = 2 * t.cdf(-abs(tstat_intercept), self._dgf)
else:
self.pvalue_intercept = None
示例11: _gaussian
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def _gaussian(M, Rho):
"""
Generates samples from the Gaussian Copula, w/ dependency
matrix described by Rho. Rho should be a numpy square matrix.
It is assumed that we have a 0 mean.
"""
N = Rho.shape[0]
mu = np.zeros(N)
y = multivariate_normal(mu,Rho)
mvnData = y.rvs(size=M)
U = norm.cdf(mvnData)
return U
示例12: _t
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def _t(M, Rho, nu):
N = Rho.shape[0]
mu = np.zeros(N) # zero mean
x = mvt.multivariate_t_rvs(mu,Rho,nu,M) # generate T RV's
U = t.cdf(x, nu)
return U
# We generate the Archimedean Copula's as follows:
# Random pairs from these copulae can be generated sequentially: first
# generate u1 as a uniform r.v. Then generate u2 from the conditional
# distribution F(u2 | u1; alpha) by generating uniform random values, then
# inverting the conditional CDF.
# This method is outlined in Nelsen's Introduction to Copula's
示例13: dependent_corr
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def dependent_corr(xy, xz, yz, n, twotailed=True, conf_level=0.95, method='steiger'):
"""
Calculates the statistic significance between two dependent correlation coefficients
@param xy: correlation coefficient between x and y
@param xz: correlation coefficient between x and z
@param yz: correlation coefficient between y and z
@param n: number of elements in x, y and z
@param twotailed: whether to calculate a one or two tailed test, only works for 'steiger' method
@param conf_level: confidence level, only works for 'zou' method
@param method: defines the method uses, 'steiger' or 'zou'
@return: t and p-val
"""
if method == 'steiger':
d = xy - xz
determin = 1 - xy * xy - xz * xz - yz * yz + 2 * xy * xz * yz
av = (xy + xz)/2
cube = (1 - yz) * (1 - yz) * (1 - yz)
t2 = d * np.sqrt((n - 1) * (1 + yz)/(((2 * (n - 1)/(n - 3)) * determin + av * av * cube)))
p = 1 - t.cdf(abs(t2), n - 2)
if twotailed:
p *= 2
return t2, p
elif method == 'zou':
L1 = rz_ci(xy, n, conf_level=conf_level)[0]
U1 = rz_ci(xy, n, conf_level=conf_level)[1]
L2 = rz_ci(xz, n, conf_level=conf_level)[0]
U2 = rz_ci(xz, n, conf_level=conf_level)[1]
rho_r12_r13 = rho_rxy_rxz(xy, xz, yz)
lower = xy - xz - pow((pow((xy - L1), 2) + pow((U2 - xz), 2) - 2 * rho_r12_r13 * (xy - L1) * (U2 - xz)), 0.5)
upper = xy - xz + pow((pow((U1 - xy), 2) + pow((xz - L2), 2) - 2 * rho_r12_r13 * (U1 - xy) * (xz - L2)), 0.5)
return lower, upper
else:
raise Exception('Wrong method!')
示例14: asrfModel
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def asrfModel(myP,rho,c,alpha):
myX = np.linspace(0.0001,0.9999,100)
num = np.sqrt(1-rho)*norm.ppf(myX)-norm.ppf(myP)
cdf = norm.cdf(num/np.sqrt(rho))
pdf = util.asrfDensity(myX,myP,rho)
varAnalytic = np.sum(c)*np.interp(alpha,cdf,myX)
esAnalytic = asrfExpectedShortfall(alpha,myX,cdf,pdf,c,rho,myP)
return pdf,cdf,varAnalytic,esAnalytic
示例15: asrfExpectedShortfall
# 需要导入模块: from scipy.stats import t [as 别名]
# 或者: from scipy.stats.t import cdf [as 别名]
def asrfExpectedShortfall(alpha,myX,cdf,pdf,c,rho,myP):
expectedShortfall = np.zeros(len(alpha))
for n in range(0,len(alpha)):
myAlpha = np.linspace(alpha[n],1,1000)
loss = np.sum(c)*np.interp(myAlpha,cdf,myX)
prob = np.interp(loss,myX,pdf)
expectedShortfall[n] = np.dot(loss,prob)/np.sum(prob)
return expectedShortfall