{ } Raw JSON

bundles / scipy 1.17.1 / scipy / stats / _binomtest / binomtest

function

scipy.stats._binomtest:binomtest

source: /scipy/stats/_binomtest.py :203

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].

Parameters

k : int

The number of successes.

n : int

The number of trials.

p : float, optional

The hypothesized probability of success, i.e. the expected proportion of successes. The value must be in the interval 0 <= p <= 1. The default value is p = 0.5.

alternative : {'two-sided', 'greater', 'less'}, optional

Indicates the alternative hypothesis. The default value is 'two-sided'.

Returns

result : `~scipy.stats._result_classes.BinomTestResult` instance

The return value is an object with the following attributes:

k

k

n

n

alternative

alternative

statistic

statistic

pvalue

pvalue

The object has the following methods:

proportion_ci(confidence_level=0.95, method='exact') :

Compute the confidence interval for statistic.

Notes

Array API Standard Support

binomtest has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ⛔                   
PyTorch               ⛔                     ⛔                   
JAX                   ⛔                     ⛔                   
Dask                  ⛔                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

Examples

from scipy.stats import binomtest
A car manufacturer claims that no more than 10% of their cars are unsafe. 15 cars are inspected for safety, 3 were found to be unsafe. Test the manufacturer's claim:
result = binomtest(3, n=15, p=0.1, alternative='greater')
result.pvalue
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
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)

Aliases

  • scipy.stats.binomtest

Referenced by