
    (phA                        S SK r S SKJr  S SKJrJr  S SKJr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
KJrJrJr  \(       a  S SKJr  S/r\ " S S5      5       r\" SSS9SSS.SSSSS\S   S\S\4
S jj5       rS\S   SSS\S   S\S\\\
R@                     \
R@                  \4   4
S jr!S\\
R@                     S\
R@                  S\\
R@                  \"\"\
R@                  \"4   4S jr#S\\
R@                     S\
R@                  S\"S\
R@                  S\"S\\
R@                  \$\
R@                  \
R@                  4   4S  jr% S$S!\
R@                  S\"S"\
R@                  S\S   S\S\
R@                  4S# jjr&g)%    N)Sequence)	dataclassfield)TYPE_CHECKINGLiteral)stats)minimize_scalar)ConfidenceInterval)check_random_state)_var)_transition_to_rngDecimalNumberSeedTypedunnettc                      \ rS rSr% Sr\R                  \S'   \R                  \S'   \" SS9r	\
S   \S'   \" SS9r\R                  \S	'   \" SS9r\\S
'   \" SS9r\\S'   \" SS9r\R                  \S'   \" SS9r\R                  \S'   \" SS9r\R                  \S'   \" SS9r\\S'   \" SS9r\\S'   \" SSS9r\S-  \S'   \" SSS9r\S-  \S'   S r SS\S\S\4S jjr SS\S\4S jjrSrg)DunnettResult   a  Result object returned by `scipy.stats.dunnett`.

Attributes
----------
statistic : float ndarray
    The computed statistic of the test for each comparison. The element
    at index ``i`` is the statistic for the comparison between
    groups ``i`` and the control.
pvalue : float ndarray
    The computed p-value of the test for each comparison. The element
    at index ``i`` is the p-value for the comparison between
    group ``i`` and the control.
	statisticpvalueF)repr	two-sidedlessgreater_alternative_rho_df_std_mean_samples_mean_control
_n_samples
_n_control_rngN)defaultr   _ci_ci_clc           
      n   U R                   c  U R                  SS9  SU R                  S-  S S3n[        U R                  R
                  5       Ha  nUSU SU R                  U   S	 U R                  U   S	 U R                   R                  U   S	 U R                   R                  U   S	 S
3-  nMc     U$ )Nffffff?confidence_levelzDunnett's test (d   z.1fzW% Confidence Interval)
Comparison               Statistic  p-value  Lower CI  Upper CI
z	 (Sample z - Control) z>10.3f
)	r%   confidence_intervalr&   ranger   sizer   lowhigh)selfsis      I/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_multicomp.py__str__DunnettResult.__str__6   s     88$$c$:S% &PP 	

 t{{''(AIaST^^A->v,F[[^F+XX\\!_V,XX]]1%f-R1 2A )     r*   tolreturnc                 ~  ^ ^ SU-
  mUU 4S jn[        USUS9nUR                  nUR                  SL d  UR                  US-  :  a)  [        R
                  " STSUR                  -   -   S3S	S
9  UT R                  -  [        R                  " ST R                  -  ST R                  -  -   5      -  n[        U5      $ )a  Allowance.

It is the quantity to add/subtract from the observed difference
between the means of observed groups and the mean of the control
group. The result gives confidence limits.

Parameters
----------
confidence_level : float, optional
    Confidence level for the computed confidence interval.
    Default is .95.
tol : float, optional
    A tolerance for numerical optimization: the allowance will produce
    a confidence within ``10*tol*(1 - confidence_level)`` of the
    specified level, or a warning will be emitted. Tight tolerances
    may be impractical due to noisy evaluation of the objective.
    Default is 1e-3.

Returns
-------
allowance : float
    Allowance around the mean.
   c                    > [         R                  " U 5      n [        TR                  TR                  U TR
                  TR                  S9n[        UT-
  5      T-  $ )Nrhodfr   alternativerng)nparray_pvalue_dunnettr   r   r   r#   abs)r   sfalphar2   s     r5   pvalue_from_stat2DunnettResult._allowance.<locals>.pvalue_from_state   sO    +I II$((#1B1BIIB
 rEz?5((r8   brent)methodr9   F
   zComputation of the confidence interval did not converge to the desired level. The confidence level corresponding with the returned interval is approximately .   )
stacklevel)r	   xsuccessfunwarningswarnr   rC   sqrtr!   r"   rF   )r2   r*   r9   rI   rescritical_value	allowancerH   s   `      @r5   
_allowanceDunnettResult._allowanceI   s    4 $$	) .wCH ;;%377c"f#4MM::?377:K9LAO 	 #499,RWWdoo$// 11.
 
	 9~r8   c                    U R                   b  XR                  :X  a  U R                   $ SUs=:  a  S:  d  O  [        S5      eU R                  US9nU R                  U R
                  -
  nX2-
  nX2-   nU R                  S:X  a  [        R                  /[        U5      -  nO.U R                  S:X  a  [        R                  * /[        U5      -  nXl        [        UUS9U l         U R                   $ )a  Compute the confidence interval for the specified confidence level.

Parameters
----------
confidence_level : float, optional
    Confidence level for the computed confidence interval.
    Default is .95.

Returns
-------
ci : ``ConfidenceInterval`` object
    The object has attributes ``low`` and ``high`` that hold the
    lower and upper bounds of the confidence intervals for each
    comparison. The high and low values are accessible for each
    comparison at index ``i`` for each group ``i``.

r   r<   z)Confidence level must be between 0 and 1.r)   r   r   )r0   r1   )r%   r&   
ValueErrorrZ   r   r    r   rC   inflenr
   )r2   r*   rY   
diff_meansr0   r1   s         r5   r-   !DunnettResult.confidence_interval   s    , HH '7;;'F88O$(q(HIIOO5EOF	''$*<*<<
"#	)FF8c*o-D&(FF7)c*o-C&%
 xxr8   )r%   r&   )r(   gMbP?)r(   )__name__
__module____qualname____firstlineno____doc__rC   ndarray__annotations__r   r   r   r   r   intr   floatr   r    r!   r"   r#   r   r%   r
   r&   r   r6   rZ   r-   __static_attributes__ r8   r5   r   r      s0    zzJJ<Au<ML'89M%(D"**(% C U#D%# %5 1M2::1 %5 1M2::1".J

.'J'&D(&%*4e%DC	d	"D#(E#BFMD B( LP< -<;H<	<~ 15, -,	, ,r8   r   random_stateF)replace_docr   )rA   rB   samplesznpt.ArrayLikecontrolrA   r   rB   r:   c                     [        X0XS9u  pEn[        XES9u  pgpn
[        XEXyU
5      u  pp[        XgXUS9n[	        XUXgUUUU	U
US9$ )a  Dunnett's test: multiple comparisons of means against a control group.

This is an implementation of Dunnett's original, single-step test as
described in [1]_.

Parameters
----------
sample1, sample2, ... : 1D array_like
    The sample measurements for each experimental group.
control : 1D array_like
    The sample measurements for the control group.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis.

    The null hypothesis is that the means of the distributions underlying
    the samples and control are equal. The following alternative
    hypotheses are available (default is 'two-sided'):

    * 'two-sided': the means of the distributions underlying the samples
      and control are unequal.
    * 'less': the means of the distributions underlying the samples
      are less than the mean of the distribution underlying the control.
    * 'greater': the means of the distributions underlying the
      samples are greater than the mean of the distribution underlying
      the control.
rng : `numpy.random.Generator`, optional
    Pseudorandom number generator state. When `rng` is None, a new
    `numpy.random.Generator` is created using entropy from the
    operating system. Types other than `numpy.random.Generator` are
    passed to `numpy.random.default_rng` to instantiate a ``Generator``.

    .. versionchanged:: 1.15.0

        As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
        transition from use of `numpy.random.RandomState` to
        `numpy.random.Generator`, this keyword was changed from `random_state` to
        `rng`. For an interim period, both keywords will continue to work, although
        only one may be specified at a time. After the interim period, function
        calls using the `random_state` keyword will emit warnings. Following a
        deprecation period, the `random_state` keyword will be removed.

Returns
-------
res : `~scipy.stats._result_classes.DunnettResult`
    An object containing attributes:

    statistic : float ndarray
        The computed statistic of the test for each comparison. The element
        at index ``i`` is the statistic for the comparison between
        groups ``i`` and the control.
    pvalue : float ndarray
        The computed p-value of the test for each comparison. The element
        at index ``i`` is the p-value for the comparison between
        group ``i`` and the control.

    And the following method:

    confidence_interval(confidence_level=0.95) :
        Compute the difference in means of the groups
        with the control +- the allowance.

See Also
--------
tukey_hsd : performs pairwise comparison of means.
:ref:`hypothesis_dunnett` : Extended example

Notes
-----
Like the independent-sample t-test, Dunnett's test [1]_ is used to make
inferences about the means of distributions from which samples were drawn.
However, when multiple t-tests are performed at a fixed significance level,
the "family-wise error rate" - the probability of incorrectly rejecting the
null hypothesis in at least one test - will exceed the significance level.
Dunnett's test is designed to perform multiple comparisons while
controlling the family-wise error rate.

Dunnett's test compares the means of multiple experimental groups
against a single control group. Tukey's Honestly Significant Difference Test
is another multiple-comparison test that controls the family-wise error
rate, but `tukey_hsd` performs *all* pairwise comparisons between groups.
When pairwise comparisons between experimental groups are not needed,
Dunnett's test is preferable due to its higher power.

The use of this test relies on several assumptions.

1. The observations are independent within and among groups.
2. The observations within each group are normally distributed.
3. The distributions from which the samples are drawn have the same finite
   variance.

References
----------
.. [1] Dunnett, Charles W. (1955) "A Multiple Comparison Procedure for
       Comparing Several Treatments with a Control." Journal of the American
       Statistical Association, 50:272, 1096-1121,
       :doi:`10.1080/01621459.1955.10501294`
.. [2] Thomson, M. L., & Short, M. D. (1969). Mucociliary function in
       health, chronic obstructive airway disease, and asbestosis. Journal
       of applied physiology, 26(5), 535-539.
       :doi:`10.1152/jappl.1969.26.5.535`

Examples
--------
We'll use data from [2]_, Table 1. The null hypothesis is that the means of
the distributions underlying the samples and control are equal.

First, we test that the means of the distributions underlying the samples
and control are unequal (``alternative='two-sided'``, the default).

>>> import numpy as np
>>> from scipy.stats import dunnett
>>> samples = [[3.8, 2.7, 4.0, 2.4], [2.8, 3.4, 3.7, 2.2, 2.0]]
>>> control = [2.9, 3.0, 2.5, 2.6, 3.2]
>>> res = dunnett(*samples, control=control)
>>> res.statistic
array([ 0.90874545, -0.05007117])
>>> res.pvalue
array([0.58325114, 0.99819341])

Now, we test that the means of the distributions underlying the samples are
greater than the mean of the distribution underlying the control.

>>> res = dunnett(*samples, control=control, alternative='greater')
>>> res.statistic
array([ 0.90874545, -0.05007117])
>>> res.pvalue
array([0.30230596, 0.69115597])

For a more detailed example, see :ref:`hypothesis_dunnett`.
)ro   rp   rA   rB   )ro   rp   r>   )r   r   r   r   r   r   r   r    r!   r"   r#   )_iv_dunnett_params_dunnett_statistic_dunnettrE   r   )rp   rA   rB   ro   samples_control_r?   r@   n_group	n_samples	n_controlr   stdmean_controlmean_samplesr   s                   r5   r   r      s    R *H
 .=.*CW 2DB92.IL )#F  s""	 	r8   c                 T   [        U5      nUS;  a  [        S5      eSnSn[        R                  " U5      nU  Vs/ s H  n[        R                  " U5      PM     nnXq/-   nU H9  nUR                  S:  a  [        U5      eUR
                  S:  d  M0  [        U5      e   XqU4$ s  snf )z$Input validation for Dunnett's test.>   r   r   r   z4alternative must be 'less', 'greater' or 'two-sided'z,Control and samples groups must be 1D arraysz;Control and samples groups must have at least 1 observationr<   )r   r]   rC   asarrayndimr/   )	ro   rp   rA   rB   ndim_msg	n_obs_msgsampleru   samples_controls	            r5   rr   rr   \  s     S
!C::B
 	
 >HMIjj!G189v

6"H9 )19(<O!;;?X&&;;?Y'' " c!! :s    B%c                 j   [         R                  " U  Vs/ s H  o"R                  PM     sn5      nUR                  5       nUR                  nXE-   n[	        U 5      nXg-
  S-
  nXS-  S-   n	S[         R
                  " U	SS2S4   U	SSS24   -  5      -  n	[         R                  " U	S5        XXsU4$ s  snf )zSpecific parameters for Dunnett's test.

Degree of freedom is the number of observations minus the number of groups
including the control.
r<   N)rC   rD   r/   sumr_   rV   fill_diagonal)
ro   rp   r   rx   n_samplery   nn_groupsr@   r?   s
             r5   rs   rs   |  s     G<G&++G<=I }}HIA7|H	
	B 

!C
BGGC4L3tQw</0
0CS!H22 =s   B0r@   rx   ry   c                    [         R                  " U5      n[         R                  " U  Vs/ s H  n[         R                  " U5      PM     sn5      nU/U -   n[         R                  " U/U/5      n	[         R                  " [        X5       VV
s/ s H  u  pj[        XjS9UR                  -  PM     sn
n5      U-  n[         R                  " U5      nXu-
  [         R                  " SU-  SU-  -   5      -  nX-  XU4$ s  snf s  sn
nf )z[Statistic of Dunnett's test.

Computation based on the original single-step test from [1].
)meanr<   )	rC   r   rD   concatenater   zipr   r/   rV   )ro   rp   r@   rx   ry   r{   r   r|   all_samples	all_meansr   s2rz   zs                 r5   rt   rt     s     777#L887C7RWWV_7CDL)g%K=>I 
%(%@B%@\V f(4%@B 
CEG
HB
''"+C 
	$)a	k0I(JJA7C|33 D
Bs    C="D
r?   r   c                 Z   UR                  SS5      n[        R                  " XUS9nUS:X  a  [        U5      nSUR	                  X"* S9-
  nOJUS:X  a#  SUR	                  U[
        R                  * S9-
  nO!SUR	                  [
        R                  US9-
  n[
        R                  " U5      $ )zqpvalue from the multivariate t-distribution.

Critical values come from the multivariate student-t distribution.
r<   )shaper@   seedr   )lower_limitr   )reshaper   multivariate_trF   cdfrC   r^   
atleast_1d)r?   r@   r   rA   rB   mvtr   s          r5   rE   rE     s     !!"a(I


Sc
:Ck!	N	SWWYJW??			!SWWYRVVGW<<SWWRVVW;;==  r8   )N)'rT   collections.abcr   dataclassesr   r   typingr   r   numpyrC   scipyr   scipy.optimizer	   scipy.stats._commonr
   scipy.stats._qmcr   scipy.stats._stats_pyr   scipy._lib._utilr   r   r   numpy.typingnpt__all__r   r   tuplelistrg   rr   ri   rs   rj   rt   rE   rl   r8   r5   <module>r      s    $ ( )   * 2 / & H H  
 Y Y Yx N6 <G	bbb 78b 
	b
 b 7bJ"o&"" 78" 
	"
 4

RZZ12"@3"**3(*

3
2::sCS01324"**4(*

48;4zz4&)4 2::ubjj"**4546 !	!!)+!78! 
! ZZ	!r8   