bundles / scipy latest / scipy / stats / _binomtest / binomtest
function
scipy.stats._binomtest:binomtest
source: build-install/usr/lib/python3.14/site-packages/scipy/stats/_binomtest.py:182
Signature
def binomtest(k, n, p = 0.5, alternative = two-sided)Summary
Perform a test that the probability of success is p.
Extended Summary
The binomial test [1] is a test of the null hypothesis that the probability of success in a Bernoulli experiment is p.
Details of the test can be found in many texts on statistics, such as section 24.5 of [2].
The documentation is written as though the function accepts and returns Python scalars, but the function is vectorized to work elementwise with NumPy arrays.
Parameters
k: intThe number of successes.
n: intThe number of trials.
p: float, optionalThe hypothesized probability of success, i.e. the expected proportion of successes. The value must be in the interval
0 <= p <= 1. The default value isp = 0.5.alternative: {'two-sided', 'greater', 'less'}, optionalIndicates the alternative hypothesis. The default value is 'two-sided'.
Returns
result: `~scipy.stats._result_classes.BinomTestResult` instanceThe return value is an object with the following attributes:
k
The number of successes (copied from binomtest input).
n
The number of trials (copied from binomtest input).
alternative
Indicates the alternative hypothesis specified in the input to binomtest. It will be one of
'two-sided','greater', or'less'.statistic
The estimate of the proportion of successes.
pvalue
The p-value of the hypothesis test.
The object has the following methods:
proportion_ci(confidence_level=0.95, method='exact') :
Compute the confidence interval for
statistic.
Notes
Examples
from scipy.stats import binomtest
✓result = binomtest(3, n=15, p=0.1, alternative='greater')
✓result.pvalue
✗np.float64(0.18406106910639106)The null hypothesis cannot be rejected at the 5% level of significance because the returned p-value is greater than the critical value of 5%. The test statistic is equal to the estimated proportion, which is simply ``3/15``:
result.statistic
✗np.float64(0.2)We can use the `proportion_ci()` method of the result to compute the confidence interval of the estimate:
result.proportion_ci(confidence_level=0.95)
✗ConfidenceInterval(low=np.float64(0.056846867590246805), high=np.float64(1.0))
Aliases
scipy.stats.binomtest