ó
    Eñi:<  ã            
       óü   • S SK r S SKJr  S SKJrJrJrJr  S SKJ	r	J
r
Jr  S SKJr  SS/rS rS	 rS
 rS r\" SS/S9\" \
SS\SSS9S SSS.S j5       5       r\" SS/S/S9\" \
SS\SSS9SSS S.S j5       5       rg)é    N)Ústats)Úxp_capabilitiesÚarray_namespaceÚ
xp_promoteÚxp_result_type)Ú_SimpleNormalÚSignificanceResultÚ_get_pvalue)Ú_axis_nan_policy_factoryÚchatterjeexiÚspearmanrhoc           	      ó"  • U R                   S   nUR                  U SS9nUR                  XQ5      u  pQUR                  XSS9n[        R
                  " USSS9n[        R
                  " U* SSS9nUR                  X`R                  5      UR                  XpR                  5      pvUR                  UR                  UR                  USS95      SS9nU(       a  SSU-  US-  S-
  -  -
  n	O"SUR                  XG-
  U-  SS9-  n
SXH-  U
-  -
  n	X–U4$ )Néÿÿÿÿ©ÚaxisÚmax)Úmethodr   é   é   é   )ÚshapeÚargsortÚbroadcast_arraysÚtake_along_axisr   ÚrankdataÚastypeÚdtypeÚsumÚabsÚdiff)ÚxÚyÚy_continuousÚxpÚnÚjÚrÚlÚnumÚ	statisticÚdens              ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/stats/_correlation.pyÚ_xi_statisticr-      s  € ð 	
�‰�‰€Að 	�
‰
�1˜2ˆ
Ð€AØ×Ñ˜qÓ$�D€AØ
×Ñ˜1 bÐÐ)€Aô 	�Š�q ¨RÑ0€Aô 	�Š˜�r %¨bÑ1€AØ�9‰9�QŸ™Ó  "§)¡)¨A¯w©wÓ"7€qà
�&‰&�—‘˜Ÿ™ ¨˜Ð+Ó,°2ˆ&Ð
6€CÞØ˜˜C™ 1¨¡6¨A¡:Ñ.Ñ.‰	à�"—&‘&˜!™% 1™¨2�&Ð.Ñ.ˆØ˜™ #™Ñ%ˆ	à˜ˆ?Ðó    c                 óÖ  • U R                   S   nU(       aE  UR                  [        R                  " S5      [        R                  " U5      -  U R                  S9$ UR                  SUS-   U R                  S9nUR                  U SS9nUR                  USS9nSUS-  -  UR                  SU-  SU-  -
  S-   US-  -  SS9-  nSUS-  -  UR                  XtU-
  U-  -   S-  SS9-  n	SUS	-  -  UR                  SU-  SU-  -
  S-   U-  SS9-  n
SUS	-  -  UR                  XU-
  -  SS9-  nUSU	-  -
  U
S-  -   US-  -  nUR                  U5      [        R                  " U5      -  $ )
Nr   gš™™™™™Ù?)r   r   r   é   r   é   r   )	r   ÚasarrayÚmathÚsqrtr   ÚarangeÚsortÚcumulative_sumr   )r'   r(   r#   r$   r%   ÚiÚuÚvÚanÚbnÚcnÚdnÚtau2s                r,   Ú_xi_stdr@   )   s�  € ð 	
�‰�‰€Aö Ø�z‰zœ$Ÿ)š) EÓ*¬T¯YªY°q«\Ñ9ÀÇÁˆzÐIÐIð
 	�	‰	�!�Q˜‘U !§'¡'ˆ	Ð*€AØ
�‰�˜ˆÐ€AØ
×Ñ˜! "ÐÐ%€AØ	
ˆQ�‰T‰�B—F‘F˜A˜a™C ! A¡#™I¨™M¨Q°©TÑ1¸�FÐ;Ñ	;€BØ	
ˆQ�‰T‰�B—F‘F˜A Q¡¨¡	™M¨AÑ-°B�FÐ7Ñ	7€BØ	
ˆQ�‰T‰�B—F‘F˜A˜a™C ! A¡#™I¨™M¨QÑ.°R�FÐ8Ñ	8€BØ	
ˆQ�‰T‰�B—F‘F˜A Q¡™K¨r�FÐ2Ñ	2€BØ��2‘‰I˜˜A™Ñ  Q¡Ñ&€Dà�7‰7�4‹=œ4Ÿ9š9 Q›<Ñ'Ð'r.   c                 ó®   • U S;  a  [        S5      e[        U[        R                  5      (       d#  UR	                  5       nSnUS:w  a  [        U5      eX4$ )N>   FTz`y_continuous` must be boolean.z@`method` must be 'asymptotic' or a `PermutationMethod` instance.Ú
asymptotic)Ú
ValueErrorÚ
isinstancer   ÚPermutationMethodÚlower)r#   r   Úmessages      r,   Ú_chatterjeexi_ivrH   C   sW   € ð ˜=Ó(ÜÐ:Ó;Ð;ä�fœe×5Ñ5×6Ñ6Ø—‘“ˆØTˆØ�\Ó!Ü˜WÓ%Ð%àÐÐr.   c                 ó2   • U R                   U R                  4$ )N)r*   Úpvalue)ÚresÚ_s     r,   Ú_unpackrM   S   s   € Ø�=‰=˜#Ÿ*™*Ð$Ð$r.   )ú
dask.arrayzno take_along_axis)Úcupyz#no rankdata (xp.repeats limitation))Úskip_backendsTr   r   )ÚpairedÚ	n_samplesÚresult_to_tupleÚ	n_outputsÚ	too_smallFrB   )r   r#   r   c                ó  ^ ^^• [        T U5      m[        TU5      u  mn[        T USTS9u  m nSnUS:X  a2  [        T UTTS9u  pgn[	        XxTTS9n	[        5       n
[        Xi-  X¥TS9nOj[        U[        R                  5      (       aK  [        R                  " SU4U UU4S jUSS	.UR                  5       DS
S0D6nUR                  UR                  p¶WR                  S:X  a  US   OUnWR                  S:X  a  US   OUn[        Xk5      $ )aJ  Compute the xi correlation and perform a test of independence

The xi correlation coefficient is a measure of association between two
variables; the value tends to be close to zero when the variables are
independent and close to 1 when there is a strong association. Unlike
other correlation coefficients, the xi correlation is effective even
when the association is not monotonic.

Parameters
----------
x, y : array-like
    The samples: corresponding observations of the independent and
    dependent variable. The (N-d) arrays must be broadcastable.
axis : int, default: 0
    Axis along which to perform the test.
method : 'asymptotic' or `PermutationMethod` instance, optional
    Selects the method used to calculate the *p*-value.
    Default is 'asymptotic'. The following options are available.

    * ``'asymptotic'``: compares the standardized test statistic
      against the normal distribution.
    * `PermutationMethod` instance. In this case, the p-value
      is computed using `permutation_test` with the provided
      configuration options and other appropriate settings.

y_continuous : bool, default: False
    Whether `y` is assumed to be drawn from a continuous distribution.
    If `y` is drawn from a continuous distribution, results are valid
    whether this is assumed or not, but enabling this assumption will
    result in faster computation and typically produce similar results.

Returns
-------
res : SignificanceResult
    An object containing attributes:

    statistic : float
        The xi correlation statistic.
    pvalue : float
        The associated *p*-value: the probability of a statistic at least as
        high as the observed value under the null hypothesis of independence.

See Also
--------
scipy.stats.pearsonr, scipy.stats.spearmanr, scipy.stats.kendalltau

Notes
-----
There is currently no special handling of ties in `x`; they are broken arbitrarily
by the implementation. [1]_ recommends: "if there are ties among the Xi's, then
choose an increasing rearrangement as above by breaking ties uniformly at random."
This is easily accomplished by adding a small amount of random noise to `x`; see
examples.

[1]_ notes that the statistic is not symmetric in `x` and `y` *by design*:
"...we may want to understand if :math:`Y` is a function :math:`X`, and not just
if one of the variables is a function of the other." See [1]_ Remark 1.

References
----------
.. [1] Chatterjee, Sourav. "A new coefficient of correlation." Journal of
       the American Statistical Association 116.536 (2021): 2009-2022.
       :doi:`10.1080/01621459.2020.1758115`.

Examples
--------
Generate perfectly correlated data, and observe that the xi correlation is
nearly 1.0.

>>> import numpy as np
>>> from scipy import stats
>>> rng = np.random.default_rng(348932549825235)
>>> x = rng.uniform(0, 10, size=100)
>>> y = np.sin(x)
>>> res = stats.chatterjeexi(x, y)
>>> res.statistic
np.float64(0.9012901290129013)

The probability of observing such a high value of the statistic under the
null hypothesis of independence is very low.

>>> res.pvalue
np.float64(2.2206974648177804e-46)

As noise is introduced, the correlation coefficient decreases.

>>> noise = rng.normal(scale=[[0.1], [0.5], [1]], size=(3, 100))
>>> res = stats.chatterjeexi(x, y + noise, axis=-1)
>>> res.statistic
array([0.79507951, 0.41824182, 0.16651665])

Because the distribution of `y` is continuous, it is valid to pass
``y_continuous=True``. The statistic is identical, and the p-value
(not shown) is only slightly different.

>>> stats.chatterjeexi(x, y + noise, y_continuous=True, axis=-1).statistic
array([0.79507951, 0.41824182, 0.16651665])

Consider a case in which there are ties in `x`.

>>> x = rng.integers(10, size=1000)
>>> y = rng.integers(10, size=1000)

[1]_ recommends breaking the ties uniformly at random.

>>> d = rng.uniform(1e-5, size=x.size)
>>> res = stats.chatterjeexi(x + d, y)
>>> res.statistic
-0.029919991638798438

Since this gives a randomized estimate of the statistic, [1]_ also suggests
considering the average over all possibilities of breaking ties. This is
computationally infeasible when there are many ties, but a randomized estimate of
*this* quantity can be obtained by considering many random possibilities of breaking
ties.

>>> d = rng.uniform(1e-5, size=(9999, x.size))
>>> res = stats.chatterjeexi(x + d, y, axis=1)
>>> np.mean(res.statistic)
0.001186895213756626

T©Úforce_floatingr$   ÚgreaterrB   ©r$   )Úalternativer$   c                 ó"   >• [        TU TTS9S   $ )NrZ   r   )r-   )r"   r   r!   r$   r#   s     €€€r,   Ú<lambda>Úchatterjeexi.<locals>.<lambda>ë   s   ø€ ¤m°A°q¸,È2Ñ&NÈqÒ&Qr.   Úpairings)Údatar*   r[   Úpermutation_typer   r   r   © )r   rH   r   r-   r@   r   r
   rD   r   rE   Úpermutation_testÚ_asdictr*   rJ   Úndimr	   )r!   r"   r   r#   r   r[   Úxir'   r(   ÚstdÚnormrJ   rK   r$   s   `  `         @r,   r   r   W   s  ú€ ô~ 
˜˜AÓ	€Bô ,¨L¸&ÓAÑ€L�&Ü�a˜¨4°BÑ7�D€A€qð
 €Kà�ÓÜ   A |¸Ñ;‰ˆˆqÜ�a˜L¨RÑ0ˆÜ‹ˆÜ˜R™X tÈÑL‰Ü	�FœE×3Ñ3×	4Ñ	4Ü×$Ò$ð à�ÞQØ#°jñ	ð EKÇNÁNÓDTñ	ð
 òˆð —]‘] C§J¡JˆFà—7‘7˜a“<ˆˆBŠ R€BØ!Ÿ;™;¨!Ó+ˆV�BŠZ°€FÜ˜bÓ)Ð)r.   z	jax.numpy)rN   z+not supported by rankdata (take_along_axis))Úcpu_onlyÚ
exceptionsrP   z	two-sided)r[   r   r   c               ó*  • [        X5      n[        XSUS9n[        R                  " XS9n[        R                  " XS9nUR	                  XvSS9nUR	                  X†SS9n[        R
                  " XxX2US9n	[        U	R                  U	R                  5      $ )a'  Calculate a Spearman rho correlation coefficient with associated p-value.

The Spearman rank-order correlation coefficient is a nonparametric measure
of the monotonicity of the relationship between two datasets.
Like other correlation coefficients, it varies between -1 and +1 with 0
implying no correlation. Coefficients of -1 or +1 are associated with an exact
monotonic relationship.  Positive correlations indicate that as `x` increases,
so does `y`; negative correlations indicate that as `x` increases, `y` decreases.
The p-value is the probability of an uncorrelated system producing datasets
with a Spearman correlation at least as extreme as the one computed from the
observed dataset.

Parameters
----------
x, y : array-like
    The samples: corresponding observations of the independent and
    dependent variable. The (N-d) arrays must be broadcastable.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis. Default is 'two-sided'.
    The following options are available:

    * 'two-sided': the correlation is nonzero
    * 'less': the correlation is negative (less than zero)
    * 'greater':  the correlation is positive (greater than zero)

method : ResamplingMethod, optional
    Defines the method used to compute the p-value. If `method` is an
    instance of `PermutationMethod`/`MonteCarloMethod`, the p-value is
    computed using
    `scipy.stats.permutation_test`/`scipy.stats.monte_carlo_test` with the
    provided configuration options and other appropriate settings.
    Otherwise, the p-value is computed using an asymptotic approximation of
    the null distribution.
axis : int or None, optional
    If axis=0 (default), then each column represents a variable, with
    observations in the rows. If axis=1, the relationship is transposed:
    each row represents a variable, while the columns contain observations.
    If axis=None, then both arrays will be raveled.
    Like other `scipy.stats` functions, `axis` is interpreted after the
    arrays are broadcasted.

Returns
-------
res : SignificanceResult
    An object containing attributes:

    statistic : floating point array or NumPy scalar
        Spearman correlation coefficient
    pvalue : floating point array NumPy scalar
        The p-value - the probabilitiy of realizing such an extreme statistic
        value under the null hypothesis that two samples have no ordinal
        correlation. See `alternative` above for alternative hypotheses.

Warns
-----
`~scipy.stats.ConstantInputWarning`
    Raised if an input is a constant array.  The correlation coefficient
    is not defined in this case, so ``np.nan`` is returned.

Notes
-----
`spearmanrho` was created to make improvements to SciPy's implementation of
the Spearman correlation test without making backward-incompatible changes
to `spearmanr`. Advantages of `spearmanrho` over `spearmanr` include:

- `spearmanrho` follows standard array broadcasting rules.
- `spearmanrho` is compatible with some non-NumPy arrays.
- `spearmanrho` can compute exact p-values, even in the presence of ties,
  when an appropriate instance of `PermutationMethod` is provided via the
  `method` argument.

References
----------
.. [1] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
   Probability and Statistics Tables and Formulae. Chapman & Hall: New
   York. 2000.
   Section  14.7
.. [2] Kendall, M. G. and Stuart, A. (1973).
   The Advanced Theory of Statistics, Volume 2: Inference and Relationship.
   Griffin. 1973.
   Section 31.18

Examples
--------
Univariate samples, approximate p-value.

>>> import numpy as np
>>> from scipy import stats
>>> x = [1, 2, 3, 4, 5]
>>> y = [5, 6, 7, 8, 7]
>>> res = stats.spearmanrho(x, y)
>>> res.statistic
np.float64(0.8207826816681233)
>>> res.pvalue
np.float64(0.08858700531354405)

Univariate samples, exact p-value.

>>> res = stats.spearmanrho(x, y, method=stats.PermutationMethod())
>>> res.statistic
np.float64(0.8207826816681233)
>>> res.pvalue
np.float64(0.13333333333333333)

Batch of univariate samples, one vectorized call.

>>> rng = np.random.default_rng(98145152315484)
>>> x2 = rng.standard_normal((2, 100))
>>> y2 = rng.standard_normal((2, 100))
>>> res = stats.spearmanrho(x2, y2, axis=-1)
>>> res.statistic
array([ 0.16585659, -0.12151215])
>>> res.pvalue
array([0.0991155 , 0.22846869])

Bivariate samples using standard broadcasting rules.

>>> res = stats.spearmanrho(x2[np.newaxis, :], x2[:, np.newaxis], axis=-1)
>>> res.statistic
array([[ 1.        , -0.14670267],
       [-0.14670267,  1.        ]])
>>> res.pvalue
array([[0.        , 0.14526128],
       [0.14526128, 0.        ]])

TrW   r   F)Úcopy)r   r[   r   )	r   r   r   r   r   Úpearsonrr	   r*   rJ   )
r!   r"   r[   r   r   r$   r   ÚrxÚryrK   s
             r,   r   r   ö   s„   € ôH 
˜Ó	€BÜ˜1°¸Ñ<€EÜ	�Š˜Ñ	%€BÜ	�Š˜Ñ	%€BØ	�‰�2 5ˆÐ	)€BØ	�‰�2 5ˆÐ	)€BÜ
�.Š.˜¨ÈdÑ
S€CÜ˜cŸm™m¨S¯Z©ZÓ8Ð8r.   )r3   Úscipyr   Úscipy._lib._array_apir   r   r   r   Úscipy.stats._stats_pyr   r	   r
   Úscipy.stats._axis_nan_policyr   Ú__all__r-   r@   rH   rM   r   r   rb   r.   r,   Ú<module>ru      sÙ   ðÛ Ý ÷3ó 3ç PÑ PÝ Að ˜=Ð
)€òò:(ò4 ò %ñ Ð DØ Oð Qñ RáÐ,°TÀQØ*1¸QÈ!ñMà ¨u¸\ô X*óMóRðX*ñv ˜$¨K¨=ØPÐQññ Ð,°TÀQØ*1¸QÈ!ñMà(3¸DÀqô F9óMóñ
F9r.   