ó
    Eñiê?  ã                   óÌ   • S r / SQrSSKrSSKJr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Jr  SS	 jrSS
 jrSS jr  SS jrSS jrSS jrSS jrSS jrSS jrSS jrg)zB
Additional statistics functions with support for masked arrays.

)
Úcompare_medians_msÚhdquantilesÚhdmedianÚhdquantiles_sdÚidealfourthsÚmedian_cihsÚmjciÚmquantiles_cimjÚrshÚtrimmed_mean_cié    N)Úfloat64Úndarray)ÚMaskedArrayé   )Ú_mstats_basic)ÚnormÚbetaÚtÚbinomc                 ót  • S n[         R                  " U S[        S9n [        R                  " [        R
                  " U5      5      nUb  U R                  S:X  a
  U" XU5      nO@U R                  S:”  a  [        SU R                   35      e[         R                  " XBXU5      n[         R                  " USS9$ )at  
Computes quantile estimates with the Harrell-Davis method.

The quantile estimates are calculated as a weighted linear combination
of order statistics.

Parameters
----------
data : array_like
    Data array.
prob : sequence, optional
    Sequence of probabilities at which to compute the quantiles.
axis : int or None, optional
    Axis along which to compute the quantiles. If None, use a flattened
    array.
var : bool, optional
    Whether to return the variance of the estimate.

Returns
-------
hdquantiles : MaskedArray
    A (p,) array of quantiles (if `var` is False), or a (2,p) array of
    quantiles and variances (if `var` is True), where ``p`` is the
    number of quantiles.

See Also
--------
hdquantiles_sd

Examples
--------
>>> import numpy as np
>>> from scipy.stats.mstats import hdquantiles
>>>
>>> # Sample data
>>> data = np.array([1.2, 2.5, 3.7, 4.0, 5.1, 6.3, 7.0, 8.2, 9.4])
>>>
>>> # Probabilities at which to compute quantiles
>>> probabilities = [0.25, 0.5, 0.75]
>>>
>>> # Compute Harrell-Davis quantile estimates
>>> quantile_estimates = hdquantiles(data, prob=probabilities)
>>>
>>> # Display the quantile estimates
>>> for i, quantile in enumerate(probabilities):
...     print(f"{int(quantile * 100)}th percentile: {quantile_estimates[i]}")
25th percentile: 3.1505820231763066 # may vary
50th percentile: 5.194344084883956
75th percentile: 7.430626414674935

c                 ó4  • [         R                  " [         R                  " U R                  5       R	                  [
        5      5      5      nUR                  n[         R                  " S[        U5      4[        5      nUS:  a#  [         R                  Ul        U(       a  U$ US   $ [         R                  " US-   5      [        U5      -  n[        R                  n[!        U5       He  u  p‰U" XdS-   U	-  US-   SU	-
  -  5      n
U
SS U
SS -
  n[         R"                  " X³5      nXÅSU4'   [         R"                  " X³U-
  S-  5      USU4'   Mg     US   USUS:H  4'   US   USUS:H  4'   U(       a$  [         R                  =USUS:H  4'   USUS:H  4'   U$ US   $ )zGComputes the HD quantiles for a 1D array. Returns nan for invalid data.é   r   r   Néÿÿÿÿ)ÚnpÚsqueezeÚsortÚ
compressedÚviewr   ÚsizeÚemptyÚlenr   ÚnanÚflatÚarangeÚfloatr   ÚcdfÚ	enumerateÚdot)ÚdataÚprobÚvarÚxsortedÚnÚhdÚvÚbetacdfÚiÚpÚ_wÚwÚhd_means                ÚW/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/stats/_mstats_extras.pyÚ_hd_1DÚhdquantiles.<locals>._hd_1DP   sw  € ä—*’*œRŸWšW T§_¡_Ó%6×%;Ñ%;¼GÓ%DÓEÓFˆà�L‰Lˆä�XŠX�qœ˜T›�m¤WÓ-ˆØˆq‹5Ü—f‘fˆBŒGÞØ�	Ø�a‘5ˆLä�IŠI�a˜‘c‹NœU 1›XÑ%ˆÜ—(‘(ˆÜ˜t–_‰EˆQÙ˜˜q™S !™G a¨¡c¨A¨a©C¡[Ó1ˆBØ�1�2�˜˜C˜R˜Ñ ˆAÜ—f’f˜QÓ(ˆGØˆq�ˆs‰Gä—f’f˜Q¨¡°1Ñ 4Ó5ˆBˆq�ˆs‹Gñ %ð # 1™:ˆˆ1ˆd�a‰iˆ<ÑØ" 2™;ˆˆ1ˆd�a‰iˆ<ÑÞÜ24·&±&Ð8ˆBˆq�$˜!‘)ˆ|Ñ˜r ! T¨Q¡Y ,Ñ/ØˆIØ�!‰uˆó    F©ÚcopyÚdtyper   r   úBArray 'data' must be at most two dimensional, but got data.ndim = ©r;   )
ÚmaÚarrayr   r   Ú
atleast_1dÚasarrayÚndimÚ
ValueErrorÚapply_along_axisÚfix_invalid)r)   r*   Úaxisr+   r7   r2   Úresults          r6   r   r      s¡   € òhô< �8Š8�D˜u¬GÑ4€DÜ
�Š”b—j’j Ó&Ó'€Aà‰˜$Ÿ)™) q›.Ù˜ Ó%‰à�9‰9�q‹=Üð  4Ø48·I±I°;ð@ó Að Aä×$Ò$ V°4¸CÓ@ˆä�>Š>˜& uÑ-Ð-r9   c                 ó:   • [        U S/XS9nUR                  5       $ )aõ  
Returns the Harrell-Davis estimate of the median along the given axis.

Parameters
----------
data : ndarray
    Data array.
axis : int, optional
    Axis along which to compute the quantiles. If None, use a flattened
    array.
var : bool, optional
    Whether to return the variance of the estimate.

Returns
-------
hdmedian : MaskedArray
    The median values.  If ``var=True``, the variance is returned inside
    the masked array.  E.g. for a 1-D array the shape change from (1,) to
    (2,).

ç      à?)rG   r+   )r   r   )r)   rG   r+   rH   s       r6   r   r   |   s!   € ô, ˜˜s˜e¨$Ñ8€FØ�>‰>ÓÐr9   c                 ól  • S n[         R                  " U S[        S9n [        R                  " [        R
                  " U5      5      nUc	  U" X5      nO?U R                  S:”  a  [        SU R                   35      e[         R                  " X2X5      n[         R                  " USS9R                  5       $ )aµ  
The standard error of the Harrell-Davis quantile estimates by jackknife.

Parameters
----------
data : array_like
    Data array.
prob : sequence, optional
    Sequence of quantiles to compute.
axis : int, optional
    Axis along which to compute the quantiles. If None, use a flattened
    array.

Returns
-------
hdquantiles_sd : MaskedArray
    Standard error of the Harrell-Davis quantile estimates.

See Also
--------
hdquantiles

c                 óÜ  • [         R                  " U R                  5       5      n[        U5      n[         R                  " [        U5      [
        5      nUS:  a  [         R                  Ul        [         R                  " U5      [        US-
  5      -  n[        R                  n[        U5       H¹  u  pxU" XSU-  USU-
  -  5      n	U	SS U	SS -
  n
[         R                  " U5      n[         R                  " X¢SS -  5      USS& USS=== [         R                  " U
SSS2   USSS2   -  5      SSS2   -  sss& [         R                  " UR!                  5       US-
  -  5      XG'   M»     U$ )z%Computes the std error for 1D arrays.r   r   Nr   r   )r   r   r   r!   r    r   r"   r#   r$   r%   r   r&   r'   Ú
zeros_likeÚcumsumÚsqrtr+   )r)   r*   r,   r-   ÚhdsdÚvvr0   r1   r2   r3   r4   Úmx_s               r6   Ú_hdsd_1DÚ hdquantiles_sd.<locals>._hdsd_1D®   s3  € ä—'’'˜$Ÿ/™/Ó+Ó,ˆÜ�‹Lˆä�xŠxœ˜D›	¤7Ó+ˆØˆq‹5ÜŸ™ˆDŒIä�YŠY�q‹\œE ! A¡#›JÑ&ˆÜ—(‘(ˆä˜t–_‰EˆQÙ˜˜q™S ! Q q¡S¡'Ó*ˆBØ�1�2�˜˜C˜R˜Ñ ˆAô —-’- Ó(ˆCÜ—i’i ¨C¨R LÑ 0Ó1ˆC��ˆGà��‹HœŸ	š	 !¡D b D¡'¨G°E°Q°r°E©NÑ":Ó;¹D¸b¸DÑAÑA‹HÜ—g’g˜cŸg™g›i¨1¨q©5Ñ1Ó2ˆD‹Gñ %ð ˆr9   Fr:   r   r=   r>   )r?   r@   r   r   rA   rB   rC   rD   rE   rF   Úravel)r)   r*   rG   rS   r2   rH   s         r6   r   r   –   s›   € ò0ô2 �8Š8�D˜u¬GÑ4€DÜ
�Š”b—j’j Ó&Ó'€Aà‰Ù˜$Ó"‰à�9‰9�q‹=Üð  4Ø48·I±I°;ð@ó Að Aä×$Ò$ X°TÓ=ˆä�>Š>˜& uÑ-×3Ñ3Ó5Ð5r9   c                 óH  • [         R                  " U SS9n [        R                  " XX$S9nUR	                  U5      n[        R
                  " XX$S9nUR                  U5      S-
  n[        R                  " SUS-  -
  U5      n	[        R                  " XiU-  -
  XiU-  -   45      $ )a3  
Selected confidence interval of the trimmed mean along the given axis.

Parameters
----------
data : array_like
    Input data.
limits : {None, tuple}, optional
    None or a two item tuple.
    Tuple of the percentages to cut on each side of the array, with respect
    to the number of unmasked data, as floats between 0. and 1. If ``n``
    is the number of unmasked data before trimming, then
    (``n * limits[0]``)th smallest data and (``n * limits[1]``)th
    largest data are masked.  The total number of unmasked data after
    trimming is ``n * (1. - sum(limits))``.
    The value of one limit can be set to None to indicate an open interval.

    Defaults to (0.2, 0.2).
inclusive : (2,) tuple of boolean, optional
    If relative==False, tuple indicating whether values exactly equal to
    the absolute limits are allowed.
    If relative==True, tuple indicating whether the number of data being
    masked on each side should be rounded (True) or truncated (False).

    Defaults to (True, True).
alpha : float, optional
    Confidence level of the intervals.

    Defaults to 0.05.
axis : int, optional
    Axis along which to cut. If None, uses a flattened version of `data`.

    Defaults to None.

Returns
-------
trimmed_mean_ci : (2,) ndarray
    The lower and upper confidence intervals of the trimmed data.

Fr>   )ÚlimitsÚ	inclusiverG   r   ç       @)
r?   r@   ÚmstatsÚtrimrÚmeanÚtrimmed_stdeÚcountr   Úppfr   )
r)   rW   rX   ÚalpharG   ÚtrimmedÚtmeanÚtstdeÚdfÚtppfs
             r6   r   r   Õ   s’   € ôT �8Š8�D˜uÑ%€DÜ�lŠl˜4¸)ÑO€GØ�L‰L˜Ó€EÜ×Ò ¸YÑQ€EØ	�‰�tÓ	˜qÑ	 €BÜ�5Š5��5˜‘8‘˜BÓ€DÜ�8Š8�U %™ZÑ'¨°E©zÑ)9Ð:Ó;Ð;r9   c                 ó  • S n[         R                  " U SS9n U R                  S:”  a  [        SU R                   35      e[        R
                  " [        R                  " U5      5      nUc  U" X5      $ [         R                  " X2X5      $ )aT  
Returns the Maritz-Jarrett estimators of the standard error of selected
experimental quantiles of the data.

Parameters
----------
data : ndarray
    Data array.
prob : sequence, optional
    Sequence of quantiles to compute.
axis : int or None, optional
    Axis along which to compute the quantiles. If None, use a flattened
    array.

c                 óv  • [         R                  " U R                  5       5      n U R                  n[         R                  " U5      U-  S-   R                  [        5      n[        R                  n[         R                  " [        U5      [        5      n[         R                  " SUS-   [        S9U-  nUSU-  -
  n[        U5       Hn  u  p‰U" XiS-
  X)-
  5      U" XyS-
  X)-
  5      -
  n
[         R                  " X 5      n[         R                  " X S-  5      n[         R                  " XËS-  -
  5      XX'   Mp     U$ )NrJ   r   )r<   g      ð?r   )r   r   r   r   r@   ÚastypeÚintr   r&   r    r!   r   r$   r'   r(   rO   )r)   r2   r-   r*   r0   ÚmjÚxÚyr1   ÚmÚWÚC1ÚC2s                r6   Ú_mjci_1DÚmjci.<locals>._mjci_1D  sö   € Ü�wŠw�t—‘Ó(Ó)ˆØ�I‰IˆÜ—’˜“˜a‘ #Ñ%×-Ñ-¬cÓ2ˆÜ—(‘(ˆä�XŠX”c˜$“i¤Ó)ˆÜ�IŠI�a˜˜!™¤7Ñ+¨aÑ/ˆØ��1‘‰HˆÜ˜t–_‰EˆQÙ˜˜A™#˜a™cÓ"¡W¨Q°©s°1±3Ó%7Ñ7ˆAÜ—’˜“ˆBÜ—’˜ ™'Ó"ˆBÜ—G’G˜B Q¡™JÓ'ˆB‹Eñ	 %ð
 ˆ	r9   Fr>   r   r=   )r?   r@   rC   rD   r   rA   rB   rE   )r)   r*   rG   rq   r2   s        r6   r   r     s€   € ò ô  �8Š8�D˜uÑ%€DØ‡y�y�1ƒ}Üð 0Ø04·	±	¨{ð<ó =ð 	=ô 	�Š”b—j’j Ó&Ó'€Aà‰Ù˜Ó Ð ä×"Ò" 8°4Ó;Ð;r9   c                 ó¶   • [        USU-
  5      n[        R                  " SUS-  -
  5      n[        R                  " XSSUS9n[        XUS9nXTU-  -
  XTU-  -   4$ )a}  
Computes the alpha confidence interval for the selected quantiles of the
data, with Maritz-Jarrett estimators.

Parameters
----------
data : ndarray
    Data array.
prob : sequence, optional
    Sequence of quantiles to compute.
alpha : float, optional
    Confidence level of the intervals.
axis : int or None, optional
    Axis along which to compute the quantiles.
    If None, use a flattened array.

Returns
-------
ci_lower : ndarray
    The lower boundaries of the confidence interval.  Of the same length as
    `prob`.
ci_upper : ndarray
    The upper boundaries of the confidence interval.  Of the same length as
    `prob`.

r   rY   r   )ÚalphapÚbetaprG   ©rG   )Úminr   r_   rZ   Ú
mquantilesr   )r)   r*   r`   rG   ÚzÚxqÚsmjs          r6   r	   r	   5  sc   € ô6 ��q˜5‘yÓ!€EÜ�Š��U˜2‘X‘Ó€AÜ	×	Ò	˜4¨a°q¸tÑ	D€BÜ
ˆt Ñ
%€CØ�S‘‰L˜" 3™w™,Ð'Ð'r9   c                 óÎ   • S n[         R                  " U SS9n Uc
  U" X5      nU$ U R                  S:”  a  [        SU R                   35      e[         R                  " X2X5      nU$ )aý  
Computes the alpha-level confidence interval for the median of the data.

Uses the Hettmasperger-Sheather method.

Parameters
----------
data : array_like
    Input data. Masked values are discarded. The input should be 1D only,
    or `axis` should be set to None.
alpha : float, optional
    Confidence level of the intervals.
axis : int or None, optional
    Axis along which to compute the quantiles. If None, use a flattened
    array.

Returns
-------
median_cihs
    Alpha level confidence interval.

c                 óÜ  • [         R                  " U R                  5       5      n [        U 5      n[	        USU-
  5      n[        [        R                  " US-  US5      5      n[        R                  " X#-
  US5      [        R                  " US-
  US5      -
  nUSU-
  :  a;  US-  n[        R                  " X#-
  US5      [        R                  " US-
  US5      -
  n[        R                  " X#-
  S-
  US5      [        R                  " X2S5      -
  nUS-
  U-   XE-
  -  nX#-
  U-  [        X2SU-  -
  U-  -   5      -  nXpU   -  SU-
  XS-
     -  -   XpX#-
  S-
     -  SU-
  XU-
     -  -   4nU$ )Nr   rY   rJ   r   )
r   r   r   r!   rw   ri   r   Ú_ppfr&   r%   )	r)   r`   r-   ÚkÚgkÚgkkÚIÚlambdÚlimss	            r6   Ú_cihs_1DÚmedian_cihs.<locals>._cihs_1Dn  s_  € Ü�wŠw�t—‘Ó(Ó)ˆÜ�‹IˆÜ�E˜1˜U™7Ó#ˆÜ”—
’
˜5 ™8 Q¨Ó,Ó-ˆÜ�YŠY�q‘s˜1˜SÓ!¤E§I¢I¨a°©c°!°CÓ$8Ñ8ˆØ��%‘‹<Ø�‰FˆAÜ—’˜1™3˜q Ó%¬¯	ª	°!°A±#°a¸Ó(<Ñ<ˆBÜ�iŠi˜™˜A™˜a Ó$¤u§y¢y°°SÓ'9Ñ9ˆØ�!‰V�e‰^˜b™hÑ'ˆØ‘˜‘	œE !¨¨1©¡u¨a¡i¡-Ó0Ñ0ˆØ˜1‘g‘  5¡¨$°©s©)Ñ 3Ñ3Ø˜1™3˜q™5‘kÑ! Q u¡W¨d°Q±3©iÑ$7Ñ7ð9ˆàˆr9   Fr>   r   r=   )r?   r@   rC   rD   rE   )r)   r`   rG   r…   rH   s        r6   r   r   W  sv   € ò.ô �8Š8�D˜uÑ%€Dà‰Ù˜$Ó&ˆð €Mð �9‰9�q‹=Üð  4Ø48·I±I°;ð@ó Að Aä×$Ò$ X°TÓAˆà€Mr9   c                 ó@  • [         R                  " XS9[         R                  " XS9pC[        R                  " XS9[        R                  " XS9pe[        R
                  " X4-
  5      [         R                  " US-  US-  -   5      -  nS[        R                  " U5      -
  $ )a†  
Compares the medians from two independent groups along the given axis.

The comparison is performed using the McKean-Schrader estimate of the
standard error of the medians.

Parameters
----------
group_1 : array_like
    First dataset.  Has to be of size >=7.
group_2 : array_like
    Second dataset.  Has to be of size >=7.
axis : int, optional
    Axis along which the medians are estimated. If None, the arrays are
    flattened.  If `axis` is not None, then `group_1` and `group_2`
    should have the same shape.

Returns
-------
compare_medians_ms : {float, ndarray}
    If `axis` is None, then returns a float, otherwise returns a 1-D
    ndarray of floats with a length equal to the length of `group_1`
    along `axis`.

Examples
--------

>>> from scipy import stats
>>> a = [1, 2, 3, 4, 5, 6, 7]
>>> b = [8, 9, 10, 11, 12, 13, 14]
>>> stats.mstats.compare_medians_ms(a, b, axis=None)
1.0693225866553746e-05

The function is vectorized to compute along a given axis.

>>> import numpy as np
>>> rng = np.random.default_rng()
>>> x = rng.random(size=(3, 7))
>>> y = rng.random(size=(3, 8))
>>> stats.mstats.compare_medians_ms(x, y, axis=1)
array([0.36908985, 0.36092538, 0.2765313 ])

References
----------
.. [1] McKean, Joseph W., and Ronald M. Schrader. "A comparison of methods
   for studentizing the sample median." Communications in
   Statistics-Simulation and Computation 13.6 (1984): 751-773.

rv   r   r   )	r?   ÚmedianrZ   Ústde_medianr   ÚabsrO   r   r&   )Úgroup_1Úgroup_2rG   Úmed_1Úmed_2Ústd_1Ústd_2rn   s           r6   r   r   Š  s|   € ôd —i’i Ñ2´B·I²I¸gÑ4PˆEÜ×(Ò(¨Ñ<Ü×(Ò(¨Ñ<ð ä
�Šˆu‰}Ó¤§¢¨¨q©°5¸!±8Ñ(;Ó <Ñ<€AØŒt�xŠx˜‹{‰?Ðr9   c                 óš   • S n[         R                  " XS9R                  [        5      n Uc  U" U 5      $ [         R                  " X!U 5      $ )a  
Returns an estimate of the lower and upper quartiles.

Uses the ideal fourths algorithm.

Parameters
----------
data : array_like
    Input array.
axis : int, optional
    Axis along which the quartiles are estimated. If None, the arrays are
    flattened.

Returns
-------
idealfourths : {list of floats, masked array}
    Returns the two internal values that divide `data` into four parts
    using the ideal fourths algorithm either along the flattened array
    (if `axis` is None) or along `axis` of `data`.

c                 ó$  • U R                  5       n[        U5      nUS:  a   [        R                  [        R                  /$ [	        US-  S-   S5      u  p4[        U5      nSU-
  XS-
     -  XAU   -  -   nX#-
  nSU-
  X   -  XAUS-
     -  -   nXW/$ )Né   g      @g«ªªªªªÚ?r   )r   r!   r   r"   Údivmodri   )r)   rk   r-   ÚjÚhÚqlor   Úqups           r6   Ú_idfÚidealfourths.<locals>._idfÙ  sš   € Ø�O‰OÓˆÜ�‹FˆØˆq‹5Ü—F‘Fœ2Ÿ6™6�?Ð"Ü�q˜‘t˜e‘| AÓ&‰ˆÜ�‹FˆØ�‰s�A˜‘c‘F‰l˜Q ™t™VÑ#ˆØ‰EˆØ�‰s�A‘D‰j˜1˜q ™s™V™8Ñ#ˆØˆzÐr9   rv   )r?   r   r   r   rE   )r)   rG   r™   s      r6   r   r   Ã  sD   € ò,
ô �7Š7�4Ñ#×(Ñ(¬Ó5€DØ‰Ù�D‹zÐä×"Ò" 4¨tÓ4Ð4r9   c                 óÌ  • [         R                  " U SS9n Uc  U nO*[        R                  " [        R                  " U5      5      nU R
                  S:w  a  [        S5      eU R                  5       n[        U SS9nSUS   US	   -
  -  US
-  -  nU SS2S4   USSS24   U-   :*  R                  S	5      nU SS2S4   USSS24   U-
  :  R                  S	5      nXV-
  SU-  U-  -  $ )a½  
Evaluates Rosenblatt's shifted histogram estimators for each data point.

Rosenblatt's estimator is a centered finite-difference approximation to the
derivative of the empirical cumulative distribution function.

Parameters
----------
data : sequence
    Input data, should be 1-D. Masked values are ignored.
points : sequence or None, optional
    Sequence of points where to evaluate Rosenblatt shifted histogram.
    If None, use the data.

Fr>   Nr   z#The input array should be 1D only !rv   g333333ó?r   r   çš™™™™™É?rY   )
r?   r@   r   rA   rB   rC   ÚAttributeErrorr^   r   Úsum)r)   Úpointsr-   Úrr–   ÚnhiÚnlos          r6   r
   r
   ë  së   € ô  �8Š8�D˜uÑ%€DØ�~Ø‰ä—’œrŸzšz¨&Ó1Ó2ˆà‡y�y�Aƒ~ÜÐBÓCÐCà�
‰
‹€AÜ�T Ñ%€AØˆq�‰u�Q�q‘T‰zÑ˜Q ™YÑ&€AØ’�$�‰<˜6 $¢q &™>¨AÑ-Ñ-×
2Ñ
2°1Ó
5€CØ’�$�‰<˜& ¢a ™.¨1Ñ,Ñ,×
1Ñ
1°!Ó
4€CØ‰G˜˜1™˜Q™ÑÐr9   )©g      Ð?rJ   g      è?NF)r   F)r£   N))rœ   rœ   )TTçš™™™™™©?N)r£   r¤   N)r¤   N)N)Ú__doc__Ú__all__Únumpyr   r   r   Únumpy.mar?   r   Ú r   rZ   Úscipy.stats.distributionsr   r   r   r   r   r   r   r   r   r	   r   r   r   r
   © r9   r6   Ú<module>r¬      sl   ðñò€ó ß "å Ý  å %ç :Ó :ô].ô@ô4<6ð~ 7BØ%)ô0<ôf*<ôZ(ôD0ôf6ôr%5õP r9   