
    (ph>3                         S SK Jr  S SKrS SKJr  S SKJr  S SKJ	r	  SSK
Jr  SSKJr   " S	 S
5      rS rS rS rSS jrS rg)    )sqrtN)_validate_int)brentq)ndtri   )binom)ConfidenceIntervalc                   .    \ rS rSrSrS rS rSS jrSrg)	BinomTestResult
   a  
Result of `scipy.stats.binomtest`.

Attributes
----------
k : int
    The number of successes (copied from `binomtest` input).
n : int
    The number of trials (copied from `binomtest` input).
alternative : str
    Indicates the alternative hypothesis specified in the input
    to `binomtest`.  It will be one of ``'two-sided'``, ``'greater'``,
    or ``'less'``.
statistic: float
    The estimate of the proportion of successes.
pvalue : float
    The p-value of the hypothesis test.

c                 L    Xl         X l        X0l        X@l        XPl        X@l        g N)knalternative	statisticpvalueproportion_estimate)selfr   r   r   r   r   s         I/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_binomtest.py__init__BinomTestResult.__init__   s$    &" $-     c                     SU R                    SU R                   SU R                  < SU R                   SU R                   S3nU$ )NzBinomTestResult(k=z, n=z, alternative=z, statistic=z	, pvalue=)r   r   r   r   r   )r   ss     r   __repr__BinomTestResult.__repr__(   s\    && &&  ,,/ 0..) *{{m1& r   c                 D   US;  a  [        SU S35      eSUs=::  a  S::  d  O  [        SU S35      eUS:X  a/  [        U R                  U R                  UU R                  5      u  p4O0[        U R                  U R                  UU R                  US	:H  S
9u  p4[        X4S9$ )a  
Compute the confidence interval for ``statistic``.

Parameters
----------
confidence_level : float, optional
    Confidence level for the computed confidence interval
    of the estimated proportion. Default is 0.95.
method : {'exact', 'wilson', 'wilsoncc'}, optional
    Selects the method used to compute the confidence interval
    for the estimate of the proportion:

    'exact' :
        Use the Clopper-Pearson exact method [1]_.
    'wilson' :
        Wilson's method, without continuity correction ([2]_, [3]_).
    'wilsoncc' :
        Wilson's method, with continuity correction ([2]_, [3]_).

    Default is ``'exact'``.

Returns
-------
ci : ``ConfidenceInterval`` object
    The object has attributes ``low`` and ``high`` that hold the
    lower and upper bounds of the confidence interval.

References
----------
.. [1] C. J. Clopper and E. S. Pearson, The use of confidence or
       fiducial limits illustrated in the case of the binomial,
       Biometrika, Vol. 26, No. 4, pp 404-413 (Dec. 1934).
.. [2] E. B. Wilson, Probable inference, the law of succession, and
       statistical inference, J. Amer. Stat. Assoc., 22, pp 209-212
       (1927).
.. [3] Robert G. Newcombe, Two-sided confidence intervals for the
       single proportion: comparison of seven methods, Statistics
       in Medicine, 17, pp 857-872 (1998).

Examples
--------
>>> from scipy.stats import binomtest
>>> result = binomtest(k=7, n=50, p=0.1)
>>> result.statistic
0.14
>>> result.proportion_ci()
ConfidenceInterval(low=0.05819170033997342, high=0.26739600249700846)
)exactwilsonwilsonccz	method ('z2') must be one of 'exact', 'wilson' or 'wilsoncc'.r   r   zconfidence_level (z!) must be in the interval [0, 1].r!   r#   )
correction)lowhigh)
ValueError_binom_exact_conf_intr   r   r   _binom_wilson_conf_intr	   )r   confidence_levelmethodr%   r&   s        r   proportion_ciBinomTestResult.proportion_ci1   s    b 88y 17 7 8 8%**12B1C D4 4 5 5W-dffdff.>.2.>.>@IC
 /tvvtvv/?/3/?/?:@J:NPIC "c55r   )r   r   r   r   r   r   N)gffffff?r!   )	__name__
__module____qualname____firstlineno____doc__r   r   r,   __static_attributes__ r   r   r   r   
   s    &-A6r   r   c                      [        U SS5      nU$ ! [         a    [        S5      S e[         a  n[        S5      UeS nAff = f)Nr   r   zHnumerical solver failed to converge when computing the confidence limitsz?brentq raised a ValueError; report this to the SciPy developers)r   RuntimeErrorr'   )funcpexcs      r   _findpr:   u   sb    64A H  H = >CG	H 6 , -25	66s    A<Ac                 H  ^ ^^ US:X  aB  SU-
  S-  mT S:X  a  SnO[        UU U4S j5      nT T:X  a  SnXE4$ [        UU U4S j5      n XE4$ US	:X  a'  SU-
  mSnT T:X  a  SnXE4$ [        UU U4S
 j5      n XE4$ US:X  a!  SU-
  mT S:X  a  SnO[        UU U4S j5      nSnWW4$ )zn
Compute the estimate and confidence interval for the binomial test.

Returns proportion, prop_low, prop_high
	two-sidedr      r           c                 @   > [         R                  " TS-
  TU 5      T-
  $ Nr   r   sfr8   alphar   r   s    r   <lambda>'_binom_exact_conf_int.<locals>.<lambda>       EHHQqS!Q$7%$?r         ?c                 :   > [         R                  " TTU 5      T-
  $ r   r   cdfrC   s    r   rE   rF          UYYq!Q%7%%?r   lessc                 :   > [         R                  " TTU 5      T-
  $ r   rJ   rC   s    r   rE   rF      rL   r   greaterc                 @   > [         R                  " TS-
  TU 5      T-
  $ r@   rA   rC   s    r   rE   rF      rG   r   )r:   )r   r   r*   r   plowphighrD   s   ``    @r   r(   r(      s     k!%%*6D?@D6E" ; ?@E ; 
	$$6E ; ?@E ; 
		!$$6D?@D;r   c                 >   X-  nUS:X  a  [        SSU-  -   5      nO[        U5      nSXS-  -   -  nSU-  U-  US-  -   U-  nSU-
  n	U(       a  US:X  d  U S:X  a  Sn
O2SU[        US-  S-
  SU-  -
  SU-  X-  S-   -  -   5      -  -   U-  nX-
  n
US	:X  d  X:X  a  S
nX4$ SU[        US-  S-   SU-  -
  SU-  X-  S-
  -  -   5      -  -   U-  nX-   n X4$ Xg-  [        SU-  U-  U	-  US-  -   5      -  nUS:X  d  U S:X  a  Sn
OX-
  n
US	:X  d  X:X  a  S
nX4$ X-   nX4$ )Nr<         ?r=   r   rM   r   r>      rO   rH   )r   r   )r   r   r*   r   r$   r8   zdenomcenterqlodlohidhideltas                  r   r)   r)      s    	
Ak!#,,,-"# qa4xLEc!eadlE!F	AA& AFBqadQh1nqsAC!G}<===FCB)#qvB 6M qadQh1nqsAC!G}<===FCB 6M $qs1uQwA~..& AFBB)#qvB 6M B6Mr   c           	        ^^ [        U SSS9n [        TSSS9mU T:  a  [        SU  ST S35      eSTs=::  a  S::  d  O  [        S	T S
35      eUS;  a  [        SU S35      eUS:X  a  [        R                  " U TT5      nGOVUS:X  a  [        R                  " U S-
  TT5      nGO3[        R
                  " U TT5      nSnU TT-  :X  a  SnGO U TT-  :  a  [        UU4S jU* U-  [        R                  " TT-  5      T5      nTU-
  [        XV-  [        R
                  " UTT5      :H  5      -   n[        R                  " U TT5      [        R                  " TU-
  TT5      -   nOh[        UU4S jXV-  S[        R                  " TT-  5      5      nUS-   n[        R                  " US-
  TT5      [        R                  " U S-
  TT5      -   n[        SU5      n[        U TUU T-  US9n	U	$ )a	  
Perform a test that the probability of success is p.

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 : int
        The number of successes (copied from `binomtest` input).
    n : int
        The number of trials (copied from `binomtest` input).
    alternative : str
        Indicates the alternative hypothesis specified in the input
        to `binomtest`.  It will be one of ``'two-sided'``, ``'greater'``,
        or ``'less'``.
    statistic : float
        The estimate of the proportion of successes.
    pvalue : float
        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
-----
.. versionadded:: 1.7.0

References
----------
.. [1] Binomial test, https://en.wikipedia.org/wiki/Binomial_test
.. [2] Jerrold H. Zar, Biostatistical Analysis (fifth edition),
       Prentice Hall, Upper Saddle River, New Jersey USA (2010)

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
0.18406106910639114

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
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=0.05684686759024681, high=1.0)

r   r   )minimumr   r   zk (z) must not be greater than n (z).zp (z) must be in range [0,1])r<   rM   rO   zalternative ('z<') not recognized; 
must be 'two-sided', 'less' or 'greater'rM   rO   g  ?rH   c                 6   > [         R                  " U TT5      * $ r   r   pmfx1r   r8   s    r   rE   binomtest.<locals>.<lambda>6  s    %))B1:M9Mr   c                 4   > [         R                  " U TT5      $ r   rb   rd   s    r   rE   rf   @  s    2q!9Lr   r   )r   r'   r   rK   rB   rc   _binary_search_for_binom_tstnpceilintfloorminr   )
r   r   r8   r   pvaldrerrixyresults
    ``       r   	binomtestrt      s   j 	aa(Aaa(A1u3qc!?s"EFFKaK3qc!9:;;::>+ 7D D E 	EfyyAq!			!xx!Q" IIaAA:DQY-.M/0bgrwwq1u~qJB BQVuyyQ'::;;A99Q1%Q1(==D-.L./fa!a%JB QA99QqS!Q'%((1Q31*==D3~qA;'(s49FMr   c                     X#:  a1  X#U-
  S-  -   nU " U5      nXQ:  a  US-   nOXQ:  a  US-
  nOU$ X#:  a  M1  U " U5      U::  a  U$ US-
  $ )a  
Conducts an implicit binary search on a function specified by `a`.

Meant to be used on the binomial PMF for the case of two-sided tests
to obtain the value on the other side of the mode where the tail
probability should be computed. The values on either side of
the mode are always in order, meaning binary search is applicable.

Parameters
----------
a : callable
  The function over which to perform binary search. Its values
  for inputs lo and hi should be in ascending order.
d : float
  The value to search.
lo : int
  The lower end of range to search.
hi : int
  The higher end of the range to search.

Returns
-------
int
  The index, i between lo and hi
  such that a(i)<=d<a(i+1)
r=   r   r4   )aro   rZ   r\   midmidvals         r   rh   rh   P  sd    6 'rEA:o3:QBZQBJ ' 	uz	!tr   )rT   r<   )mathr   numpyri   scipy._lib._utilr   scipy.optimizer   scipy.specialr   _discrete_distnsr   _commonr	   r   r:   r(   r)   rt   rh   r4   r   r   <module>r      sD      * !  # 'h6 h6V	B%PCL'r   