本文整理汇总了Python中scipy.stats.f.cdf方法的典型用法代码示例。如果您正苦于以下问题:Python f.cdf方法的具体用法?Python f.cdf怎么用?Python f.cdf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats.f
的用法示例。
在下文中一共展示了f.cdf方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pvalue
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f 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
示例2: sign_test
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f 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'])
示例3: friedman_test
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f 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'])
示例4: _p_value
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f 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
示例5: _f_stat_raw
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f import cdf [as 别名]
def _f_stat_raw(self):
"""Returns the raw f-stat value."""
from scipy.stats import f
cols = self._x.columns
if self._nw_lags is None:
F = self._r2_raw / (self._r2_raw - self._r2_adj_raw)
q = len(cols)
if 'intercept' in cols:
q -= 1
shape = q, self.df_resid
p_value = 1 - f.cdf(F, shape[0], shape[1])
return F, shape, p_value
k = len(cols)
R = np.eye(k)
r = np.zeros((k, 1))
try:
intercept = cols.get_loc('intercept')
R = np.concatenate((R[0: intercept], R[intercept + 1:]))
r = np.concatenate((r[0: intercept], r[intercept + 1:]))
except KeyError:
# no intercept
pass
return math.calc_F(R, r, self._beta_raw, self._var_beta_raw,
self._nobs, self.df)
示例6: calc_F
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f import cdf [as 别名]
def calc_F(R, r, beta, var_beta, nobs, df):
"""
Computes the standard F-test statistic for linear restriction
hypothesis testing
Parameters
----------
R: ndarray (N x N)
Restriction matrix
r: ndarray (N x 1)
Restriction vector
beta: ndarray (N x 1)
Estimated model coefficients
var_beta: ndarray (N x N)
Variance covariance matrix of regressors
nobs: int
Number of observations in model
df: int
Model degrees of freedom
Returns
-------
F value, (q, df_resid), p value
"""
from scipy.stats import f
hyp = np.dot(R, beta.reshape(len(beta), 1)) - r
RSR = np.dot(R, np.dot(var_beta, R.T))
q = len(r)
F = np.dot(hyp.T, np.dot(inv(RSR), hyp)).squeeze() / q
p_value = 1 - f.cdf(F, q, nobs - df)
return F, (q, nobs - df), p_value
示例7: friedman_aligned_rank_test
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f import cdf [as 别名]
def friedman_aligned_rank_test(data):
""" Method of aligned ranks for the Friedman 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 aligned_rank_stat: Friedman's aligned rank chi-square statistic.
"""
# 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 the average value achieved by all algorithms in each problem
control = np.mean(data, axis=1)
# Compute the difference between control an data
diff = [data[:, j] - control for j in range(data.shape[1])]
# rank diff
alignedRanks = ranks(np.ravel(diff))
alignedRanks = np.reshape(alignedRanks, newshape=(n_samples, k), order='F')
# Compute statistic
Rhat_i = np.sum(alignedRanks, axis=1)
Rhat_j = np.sum(alignedRanks, axis=0)
si, sj = np.sum(Rhat_i ** 2), np.sum(Rhat_j ** 2)
A = sj - (k * n_samples ** 2 / 4.0) * (k * n_samples + 1) ** 2
B1 = (k * n_samples * (k * n_samples + 1) * (2 * k * n_samples + 1) / 6.0)
B2 = si / float(k)
alignedRanks_stat = ((k - 1) * A) / (B1 - B2)
p_value = 1 - chi2.cdf(alignedRanks_stat, df=k - 1)
return pd.DataFrame(data=np.array([alignedRanks_stat, p_value]), index=['Aligned Rank stat', 'p-value'],
columns=['Results'])
示例8: quade_test
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f import cdf [as 别名]
def quade_test(data):
""" Quade 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 from the F-distribution.
:return fq: Computed F-value.
"""
# 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 the range of each problem
problemRange = np.max(data, axis=1) - np.min(data, axis=1)
# Compute problem rank
problemRank = ranks(problemRange)
# Compute S_stat: weight of each observation within the problem, adjusted to reflect
# the significance of the problem when it appears.
S_stat = np.zeros((n_samples, k))
for i in range(n_samples):
S_stat[i, :] = problemRank[i] * (datarank[i, :] - 0.5 * (k + 1))
Salg = np.sum(S_stat, axis=0)
# Compute Fq (Quade Test statistic) and associated p_value
A = np.sum(S_stat ** 2)
B = np.sum(Salg ** 2) / float(n_samples)
if A == B:
Fq = np.Inf
p_value = (1 / (np.math.factorial(k))) ** (n_samples - 1)
else:
Fq = (n_samples - 1.0) * B / (A - B)
p_value = 1 - f.cdf(Fq, k - 1, (k - 1) * (n_samples - 1))
return pd.DataFrame(data=np.array([Fq, p_value]), index=['Quade Test statistic', 'p-value'], columns=['Results'])
示例9: rm_anova
# 需要导入模块: from scipy.stats import f [as 别名]
# 或者: from scipy.stats.f import cdf [as 别名]
def rm_anova(data, output_sig = False, output_eta_sq = False):
"""
Repeated measure ANOVA for longitudinal dependent variables
Parameters
----------
data : array
Data array (N_intervals, N_individuals, N_dependent variables)
Optional Flags
----------
output_sig : bool
outputs p-values of F-statistics
Returns
-------
F : array
F-statistics of the interval variable
P : array
P-statistics of the interval variable (P = None if output_sig = False)
partial_eta_sq : array
Partial eta squared of the interval variable (partial_eta_sq = None if output_eta_sq = False)
"""
k = data.shape[0]
ni = data.shape[1]
mu_grand = np.zeros_like(np.mean(data[0],0))
for i in range(k):
mu_grand += np.mean(data[i],0)
mu_grand = np.divide(mu_grand,k)
SStime = np.zeros_like(np.mean(data[0],0))
for i in range(k):
SStime += (np.mean(data[i],0)-mu_grand)**2
SStime *= ni
SSw = np.zeros_like(np.mean(data[0],0))
for i in range(k):
SSw += np.sum(np.square(data[i] - np.mean(data[i],0)),0)
SSsub = k * np.sum(np.square(np.divide((data.sum(0)),k) - mu_grand),0)
SSerror = SSw - SSsub
df_time = (k-1)
df_error = (ni -1) * df_time
MStime = np.divide(SStime, df_time)
MSerror = np.divide(SSerror, df_error)
F = np.divide(MStime, MSerror)
if output_sig:
P = 1 - f.cdf(F,df_time,df_error)
else:
P = None
if output_eta_sq:
partial_eta_sq = SStime / (SStime + SSerror)
else:
partial_eta_sq = None
return(F, P, partial_eta_sq)