
    (ph;                       S r / SQrSSKrSSKJr  SSKJr  SSKJrJr  SSK	r	SSK
r
SSKrSSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKrSSKJs  Jr  SSKJrJrJr   S r!S r"S r#S r$S r%S r&SeS jr'SfS jr(\" SS5      r)SgS jr*ShS jr+S r,S r-S r.  SiS jr/SjS jr0  SkS jr1S r2\" SS 5      r3S! r4SlS" jr5SmS# jrSnS$ jr\" S%S&S'/5      r6S( r7\" S)S*5      r8SoS+ jr9\9r:\" S,S*5      r;SpS- jr<\" S.S*5      r=SoS/ jr>\" S0S*5      r?SqS1 jr@\" S2S*5      rAS3 rB\BrC\" S4S55      SrS6 j5       rD\" S4S55      SsS7 j5       rE\ErF\" S4S55      SrS8 j5       rGStS9 jrHSuS: jrIS;rJSvS< jrK\KR                   (       a  \KR                   \J-  \Kl         SwS= jrL  SxS> jrM\MrN  SyS? jrO\OR                   (       a  \OR                   \J-  \Ol           SzS@ jrP\PR                   (       a  \PR                   \J-  \Pl           SzSA jrQ\QR                   (       a  \QR                   \J-  \Ql         S{SB jrRSC rSSuSD jrTS|SE jrUS}SF jrVS}SG jrWS|SH jrX  S~SI jrYSSJ jrZSSK.SL jr[SSM jr\ShSN jr]SSO jr^\" SPSQ5      r_SSR jr`SlSS jra\" STS*5      rbSoSU jrc\" SVS*5      rdSoSW jre\" SXS*5      rfSgSY jrg  SSZ jrhSS[ jriSS\ jrj\jrkS] rlSS^ jrm\" S_S*5      rnS` ro\" SaS*5      rpSb rq\" ScS*5      rrSSd jrsg)zA
An extension of scipy.stats._stats_py to support masked arrays

):argstoarraycount_tied_groupsdescribef_onewayfind_repeatsfriedmanchisquare
kendalltaukendalltau_seasonalkruskalkruskalwallis
ks_twosampks_2sampkurtosiskurtosistestks_1sampkstest
linregressmannwhitneyumeppfmodemoment
mquantilesmsign
normaltestobrientransformpearsonrplotting_positionspointbiserialrrankdatascoreatpercentilesemsen_seasonal_slopesskewskewtest	spearmanrsiegelslopestheilslopestmaxtmeantmintrimtrimbothtrimtailtrimatrimrtrimmed_meantrimmed_stdtrimmed_stdetrimmed_vartsemttest_1sampttest_onesamp	ttest_ind	ttest_reltvar	variation	winsorizebrunnermunzel    N)ndarray)maskednomask)
namedtuple   )distributions)_rename_parameter_contains_nan)_make_tuple_bunch)_find_repeatsr&   r%   c                 t    [         R                  " U 5      n Uc  [         R                  " U 5      n SnX4$ UnX4$ Nr<   ma
asanyarrayravel)aaxisoutaxiss      L/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_mstats_basic.py_chk_asarrayrQ   9   s@    
aA|HHQK : :    c                     [         R                  " U 5      n [         R                  " U5      nUc/  [         R                  " U 5      n [         R                  " U5      nSnOUnXU4$ rH   rI   )rM   brN   rO   s       rP   _chk2_asarrayrU   D   sQ    
aA
aA|HHQKHHQK=rR   c                     [         R                  " U 5      n [         R                  " U5      nU R                  UR                  p2X#:w  a  [        SU SU S35      eXU4$ )Nz+The size of the input array should match! (z <> ))rJ   rK   size
ValueError)rM   rT   nanbs       rP   	_chk_sizer\   P   s`    
aA
aA	x  TbT, - 	-":rR   c                    US:X  a   [         R                  R                  X5      nOqUS:X  a!  [         R                  R                  X* 5      nOJUS:X  a9  [         R                  R                  U [        R                  " U5      * 5      S-  nO[        S5      eUR                  S:X  a  US   nUR                  S:X  a  US   nX4$ )z+Common code between all 3 t-test functions.lessgreater	two-sided   z4alternative must be 'less', 'greater' or 'two-sided'r<    )special_ufuncsstdtrnpabsrY   ndim)dftalternativepvals       rP   _ttest_finishrm   Z   s     f$$R+			!$$R,		#$$R"&&)4Q6 < = 	= 	vv{bEyyA~Bx7NrR   c                  B   [        U 5      S:X  aM  [        U S   [        5      (       d5  [        R                  " U S   5      nUR
                  S:w  a  [        S5      eO[        U 5      n[        U  Vs/ s H  n[        U5      PM     sn5      n[        R                  " [        R                  " X$4[        S9SS9n[        U 5       H  u  p5XQUS[        U5      24'   M     [        U[        R                  " [        R                  " UR                   5      5      '   U$ s  snf )	a"  
Constructs a 2D array from a group of sequences.

Sequences are filled with missing values to match the length of the longest
sequence.

Parameters
----------
*args : sequences
    Group of sequences.

Returns
-------
argstoarray : MaskedArray
    A ( `m` x `n` ) masked array, where `m` is the number of arguments and
    `n` the length of the longest argument.

Notes
-----
`numpy.ma.vstack` has identical behavior, but is called with a sequence
of sequences.

Examples
--------
A 2D masked array constructed from a group of sequences is returned.

>>> from scipy.stats.mstats import argstoarray
>>> argstoarray([1, 2, 3], [4, 5, 6])
masked_array(
 data=[[1.0, 2.0, 3.0],
       [4.0, 5.0, 6.0]],
 mask=[[False, False, False],
       [False, False, False]],
 fill_value=1e+20)

The returned masked array filled with missing values when the lengths of
sequences are different.

>>> argstoarray([1, 3], [4, 5, 6])
masked_array(
 data=[[1.0, 3.0, --],
       [4.0, 5.0, 6.0]],
 mask=[[False, False,  True],
       [False, False, False]],
 fill_value=1e+20)

rA   r<   ra   zThe input should be 2DdtypeTmaskN)len
isinstancer=   rJ   asarrayrh   rY   maxarrayrf   emptyfloat	enumerater>   logical_notisfinite_data)argsoutputnkmvs         rP   r   r   p   s    ` 4yA~ja'::DG$;;!566  I&AQ&'"((A56TBt_EQ !1Wc!fW9 % 9?F2>>"++fll345M 's   1Dc                    [         R                  " [        R                  " U 5      [         R                  S9n [         R
                  " X5      nU(       a  UR                  5       n[        U5      $ ! [         a    Sn N0f = f)az  Find repeats in arr and return a tuple (repeats, repeat_count).

The input is cast to float64. Masked values are discarded.

Parameters
----------
arr : sequence
    Input array. The array is flattened if it is not 1D.

Returns
-------
repeats : ndarray
    Array of repeated values.
counts : ndarray
    Array of counts.

Examples
--------
>>> from scipy.stats import mstats
>>> mstats.find_repeats([2, 1, 2, 3, 2, 2, 5])
(array([2.]), array([4]))

In the above example, 2 repeats 4 times.

>>> mstats.find_repeats([[10, 20, 1, 2], [5, 5, 4, 4]])
(array([4., 5.]), array([2, 2]))

In the above example, both 4 and 5 repeat 2 times.

ro   F)	rf   ru   rJ   
compressedfloat64may_share_memoryAttributeErrorcopyrF   )arrcompr	need_copys      rP   r   r      sj    B JJr}}S)<E''3	
 

   	s   A1 1B ?B c           	         [         R                  " U 5      R                  5       n[         R                  " U 5      R	                  5       n[        U5      u  pE0 n[        U5      (       af  [        [        [        R                  " U5      [        R                  " S5      5      5      nUR                  [        [        [        U5      6 5      5        U(       a  U(       a   Xb==   S-  ss'   U$ U$ ! [         a    SXb'    U$ f = f)a  
Counts the number of tied values.

Parameters
----------
x : sequence
    Sequence of data on which to counts the ties
use_missing : bool, optional
    Whether to consider missing values as tied.

Returns
-------
count_tied_groups : dict
    Returns a dictionary (nb of ties: nb of groups).

Examples
--------
>>> from scipy.stats import mstats
>>> import numpy as np
>>> z = [0, 0, 0, 2, 2, 2, 3, 3, 4, 5, 6]
>>> mstats.count_tied_groups(z)
{2: 1, 3: 2}

In the above example, the ties were 0 (3x), 2 (3x) and 3 (2x).

>>> z = np.ma.array([0, 0, 1, 2, 2, 2, 3, 3, 4, 5, 6])
>>> mstats.count_tied_groups(z)
{2: 2, 3: 1}
>>> z[[1,-1]] = np.ma.masked
>>> mstats.count_tied_groups(z, use_missing=True)
{2: 2, 3: 1}

rA   )rJ   getmasksumr   r   r   rs   dictziprf   unique	itertoolsrepeatupdateKeyError)xuse_missingnmaskeddatatiescountsntiess          rP   r   r      s    D jjm!G==  "D!$'NTE
4yyS6*I,<,<Q,?@AT#|F3456;	NaN L5L  	ENL	s   C- -C?>C?c                     SS jn[         R                  " U SS9n UcH  U R                  S:  a0  U" U R                  5       U5      R	                  U R
                  5      $ U" X5      $ [         R                  " X1X5      R                  [        5      $ )a  Returns the rank (also known as order statistics) of each data point
along the given axis.

If some values are tied, their rank is averaged.
If some values are masked, their rank is set to 0 if use_missing is False,
or set to the average rank of the unmasked values if use_missing is True.

Parameters
----------
data : sequence
    Input data. The data is transformed to a masked array
axis : {None,int}, optional
    Axis along which to perform the ranking.
    If None, the array is first flattened. An exception is raised if
    the axis is specified for arrays with a dimension larger than 2
use_missing : bool, optional
    Whether the masked values have a rank of 0 (False) or equal to the
    average rank of the unmasked values (True).

Fc                    U R                  5       n[        R                  " U R                  [        S9nU R                  5       n[        R                  " SUS-   5      X4S U '   U(       a  US-   S-  X4US  '   OSX4US  '   [        U R                  5       5      nUS    H*  nX:H  R                  S5      nX7   R                  5       X7'   M,     U$ )Nro   rA          @r<   F)countrf   rx   rX   ry   argsortaranger   r   filledmean)r   r   r   rkidxrepeatsr	conditions           rP   _rank1drankdata.<locals>._rank1d%  s    JJLXXdiiu-llnii!A#&r7Q3(B12wKB12wKtyy{+A**51IM..0BM  	rR   r   rA   F)	rJ   rw   rh   rL   reshapeshapeapply_along_axisviewr=   )r   rN   r   r   s       rP   r   r     st    *" 88Du%D|99q=4::<5==djjII4--""7AFFwOOrR   
ModeResult)r   r   c                     [        XSS9$ )a  
Returns an array of the modal (most common) value in the passed array.

Parameters
----------
a : array_like
    n-dimensional array of which to find mode(s).
axis : int or None, optional
    Axis along which to operate. Default is 0. If None, compute over
    the whole array `a`.

Returns
-------
mode : ndarray
    Array of modal values.
count : ndarray
    Array of counts for each mode.

Notes
-----
For more details, see `scipy.stats.mode`.

Examples
--------
>>> import numpy as np
>>> from scipy import stats
>>> from scipy.stats import mstats
>>> m_arr = np.ma.array([1, 1, 0, 0, 0, 0], mask=[0, 0, 1, 1, 1, 0])
>>> mstats.mode(m_arr)  # note that most zeros are masked
ModeResult(mode=array([1.]), count=array([2.]))

T)rN   keepdims)_mode)rM   rN   s     rP   r   r   C  s    B --rR   c                 6   [        X5      u  pS nUcO  U" [        R                  " U 5      5      n[        R                  " US   5      [        R                  " US   5      4nO[        R                  " X1U 5      nUb  U(       ax  [        U R                  5      nSXQ'   [        S 5      /UR                  -  nSXa'   U[        U5         R                  U5      nSXa'   U[        U5         R                  U5      nXx4nO[        R                  " XAS5      n[        U6 $ )Nc                     [        U 5      u  pUR                  (       d  gUR                  (       a"  XR                  5          UR	                  5       4$ U R                  5       S4$ )Nr<   r<   rA   )r   rh   rX   argmaxrv   min)rM   repcnts      rP   _mode1D_mode.<locals>._mode1Dk  sH     O	xxXX

%swwy11EEGQ<rR   r<   rA   )rQ   rJ   rL   rw   r   listr   slicerh   tupler   rf   moveaxisr   )	rM   rN   r   r   r   newshapeslicesmodesr   s	            rP   r   r   g  s    1#GA  |!%((6!9%rxxq	':;$$WA6xAGG}HHNDk]V[[0FFL5=)11(;EFLE&M*228<F_F[[q1FvrR   c                     [         R                  " U5      n[        R                  " US:  US5      n[        R
                  " XU5      $ )N      ?)rf   rK   rJ   whererc   betainc)rM   rT   r   s      rP   _betair     s7    
aA
S!S!A??1##rR   c                 X    [         R                  " [        R                  " U 5      S5      $ )z+Returns the sign of x, or 0 if x is masked.r<   )rJ   r   rf   sign)r   s    rP   r   r     s    99RWWQZ##rR   c                     [        X5      u  pnU R                  5       UR                  5       p[        R                  " [        R                  " U 5      [        R                  " U5      5      nX#R                  5       -  nUS-
  nUS:  a  [        [        4$ [        R                  R                  R                  [        R                  " XS9R                  5       [        R                  " XS9R                  5       5      $ )aO  
Pearson correlation coefficient and p-value for testing non-correlation.

The Pearson correlation coefficient [1]_ measures the linear relationship
between two datasets.  The calculation of the p-value relies on the
assumption that each dataset is normally distributed.  (See Kowalski [3]_
for a discussion of the effects of non-normality of the input on the
distribution of the correlation coefficient.)  Like other correlation
coefficients, this one varies between -1 and +1 with 0 implying no
correlation. Correlations of -1 or +1 imply an exact linear relationship.

Parameters
----------
x : (N,) array_like
    Input array.
y : (N,) array_like
    Input array.

Returns
-------
r : float
    Pearson's correlation coefficient.
p-value : float
    Two-tailed p-value.

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.

`~scipy.stats.NearConstantInputWarning`
    Raised if an input is "nearly" constant.  The array ``x`` is considered
    nearly constant if ``norm(x - mean(x)) < 1e-13 * abs(mean(x))``.
    Numerical errors in the calculation ``x - mean(x)`` in this case might
    result in an inaccurate calculation of r.

See Also
--------
spearmanr : Spearman rank-order correlation coefficient.
kendalltau : Kendall's tau, a correlation measure for ordinal data.

Notes
-----
The correlation coefficient is calculated as follows:

.. math::

    r = \frac{\sum (x - m_x) (y - m_y)}
             {\sqrt{\sum (x - m_x)^2 \sum (y - m_y)^2}}

where :math:`m_x` is the mean of the vector x and :math:`m_y` is
the mean of the vector y.

Under the assumption that x and y are drawn from
independent normal distributions (so the population correlation coefficient
is 0), the probability density function of the sample correlation
coefficient r is ([1]_, [2]_):

.. math::

    f(r) = \frac{{(1-r^2)}^{n/2-2}}{\mathrm{B}(\frac{1}{2},\frac{n}{2}-1)}

where n is the number of samples, and B is the beta function.  This
is sometimes referred to as the exact distribution of r.  This is
the distribution that is used in `pearsonr` to compute the p-value.
The distribution is a beta distribution on the interval [-1, 1],
with equal shape parameters a = b = n/2 - 1.  In terms of SciPy's
implementation of the beta distribution, the distribution of r is::

    dist = scipy.stats.beta(n/2 - 1, n/2 - 1, loc=-1, scale=2)

The p-value returned by `pearsonr` is a two-sided p-value. The p-value
roughly indicates the probability of an uncorrelated system
producing datasets that have a Pearson correlation at least as extreme
as the one computed from these datasets. More precisely, for a
given sample with correlation coefficient r, the p-value is
the probability that abs(r') of a random sample x' and y' drawn from
the population with zero correlation would be greater than or equal
to abs(r). In terms of the object ``dist`` shown above, the p-value
for a given r and length n can be computed as::

    p = 2*dist.cdf(-abs(r))

When n is 2, the above continuous distribution is not well-defined.
One can interpret the limit of the beta distribution as the shape
parameters a and b approach a = b = 0 as a discrete distribution with
equal probability masses at r = 1 and r = -1.  More directly, one
can observe that, given the data x = [x1, x2] and y = [y1, y2], and
assuming x1 != x2 and y1 != y2, the only possible values for r are 1
and -1.  Because abs(r') for any sample x' and y' with length 2 will
be 1, the two-sided p-value for a sample of length 2 is always 1.

References
----------
.. [1] "Pearson correlation coefficient", Wikipedia,
       https://en.wikipedia.org/wiki/Pearson_correlation_coefficient
.. [2] Student, "Probable error of a correlation coefficient",
       Biometrika, Volume 6, Issue 2-3, 1 September 1908, pp. 302-310.
.. [3] C. J. Kowalski, "On the Effects of Non-Normality on the Distribution
       of the Sample Product-Moment Correlation Coefficient"
       Journal of the Royal Statistical Society. Series C (Applied
       Statistics), Vol. 21, No. 1 (1972), pp. 1-12.

Examples
--------
>>> import numpy as np
>>> from scipy import stats
>>> from scipy.stats import mstats
>>> mstats.pearsonr([1, 2, 3, 4, 5], [10, 9, 2.5, 6, 4])
(-0.7426106572325057, 0.1505558088534455)

There is a linear dependence between x and y if y = a + b*x + e, where
a,b are constants and e is a random error term, assumed to be independent
of x. For simplicity, assume that x is standard normal, a=0, b=1 and let
e follow a normal distribution with mean zero and standard deviation s>0.

>>> s = 0.5
>>> x = stats.norm.rvs(size=500)
>>> e = stats.norm.rvs(scale=s, size=500)
>>> y = x + e
>>> mstats.pearsonr(x, y)
(0.9029601878969703, 8.428978827629898e-185) # may vary

This should be close to the exact value given by

>>> 1/np.sqrt(1 + s**2)
0.8944271909999159

For s=0.5, we observe a high level of correlation. In general, a large
variance of the noise reduces the correlation, while the correlation
approaches one as the variance of the error goes to zero.

It is important to keep in mind that no correlation does not imply
independence unless (x, y) is jointly normal. Correlation can even be zero
when there is a very simple dependence structure: if X follows a
standard normal distribution, let y = abs(x). Note that the correlation
between x and y is zero. Indeed, since the expectation of x is zero,
cov(x, y) = E[x*y]. By definition, this equals E[x*abs(x)] which is zero
by symmetry. The following lines of code illustrate this observation:

>>> y = np.abs(x)
>>> mstats.pearsonr(x, y)
(-0.016172891856853524, 0.7182823678751942) # may vary

A non-zero correlation coefficient can be misleading. For example, if X has
a standard normal distribution, define y = x if x < 0 and y = 0 otherwise.
A simple calculation shows that corr(x, y) = sqrt(2/Pi) = 0.797...,
implying a high level of correlation:

>>> y = np.where(x < 0, x, 0)
>>> mstats.pearsonr(x, y)
(0.8537091583771509, 3.183461621422181e-143) # may vary

This is unintuitive since there is no dependence of x and y if x is larger
than zero which happens in about half of the cases if we sample x and y.
ra   r<   rq   )r\   rL   rJ   mask_orr   r   r>   scipystats	_stats_pyr   masked_arrayr   )r   yr   r   ri   s        rP   r   r     s    | !IQ1ggi


2::a="**Q-0ALA	
1B	Av;;  ))*557*5579 9rR   c                 .  ^ U(       d  [        S5      e[        X5      u  pUbB  [        X5      u  pUS:X  a  [        R                  " X45      n O[        R                  " X45      n US:X  a  U R
                  n US:X  a  [        R                  " U 5      n U4S jnU R                  S   n	U	S:X  a  U" U 5      $ [        R                  " X4[        S9n
[        R                  " X4[        S9n[        U	S-
  5       Hi  n[        US-   U	5       HS  nU" U SS2X/4   5      nUR                  XU4'   UR                  XU4'   UR                  XU4'   UR                  XU4'   MU     Mk     [        R                   R"                  R%                  X5      nXl        U$ )	a  
Calculates a Spearman rank-order correlation coefficient and the p-value
to test for non-correlation.

The Spearman correlation is a nonparametric measure of the linear
relationship between two datasets. Unlike the Pearson correlation, the
Spearman correlation does not assume that both datasets are normally
distributed. Like other correlation coefficients, this one varies
between -1 and +1 with 0 implying no correlation. Correlations of -1 or
+1 imply a monotonic relationship. Positive correlations imply that
as `x` increases, so does `y`. Negative correlations imply that as `x`
increases, `y` decreases.

Missing values are discarded pair-wise: if a value is missing in `x`, the
corresponding value in `y` is masked.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.

Parameters
----------
x, y : 1D or 2D array_like, y is optional
    One or two 1-D or 2-D arrays containing multiple variables and
    observations. When these are 1-D, each represents a vector of
    observations of a single variable. For the behavior in the 2-D case,
    see under ``axis``, below.
use_ties : bool, optional
    DO NOT USE.  Does not do anything, keyword is only left in place for
    backwards compatibility reasons.
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.
nan_policy : {'propagate', 'raise', 'omit'}, optional
    Defines how to handle when input contains nan. 'propagate' returns nan,
    'raise' throws an error, 'omit' performs the calculations ignoring nan
    values. Default is 'propagate'.
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)

    .. versionadded:: 1.7.0

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

    statistic : float or ndarray (2-D square)
        Spearman correlation matrix or correlation coefficient (if only 2
        variables are given as parameters). Correlation matrix is square
        with length equal to total number of variables (columns or rows) in
        ``a`` and ``b`` combined.
    pvalue : float
        The p-value for a hypothesis test whose null hypothesis
        is that two sets of data are linearly uncorrelated. See
        `alternative` above for alternative hypotheses. `pvalue` has the
        same shape as `statistic`.

References
----------
[CRCProbStat2000] section 14.7

z3`use_ties=False` is not supported in SciPy >= 1.2.0Nr<   rA   omitc                 L  > [         R                  " U SS9n X R                  R                  SS9) S S 24   n [        R                  " U R
                  5      (       d]  [        R                  R                  R                  [        R                  [        R                  5      n[        R                  Ul        U$ [         R                  " U 5      nU R                  S   nUS-
  [        UR                  SS9S   5      -
  nUS:  a  [!        S5      e[#        U SS9n[         R$                  " USS9R
                  n[        R&                  " SS	9   U[        R(                  " XFS
-   S
U-
  -  -  R+                  S5      5      -  nS S S 5        [-        UWT	5      u  pxUR                  S:X  a<  [        R                  R                  R                  US   US   5      nUS   Ul        U$ [        R                  R                  R                  Xh5      nXal        U$ ! , (       d  f       N= f)Nr<   rN   rA   ra   z'The input must have at least 3 entries!F)rowvarignore)divider   )ra   ra   rA   r<   )rJ   mask_rowcolsrr   anyrf   r   r   r   r   SignificanceResultnancorrelationr   r   intr   rY   r   corrcoeferrstatesqrtcliprm   )
r   resr   n_obsdofx_rankedrsrj   probrk   s
            rP   _spearmanr_2cols#spearmanr.<locals>._spearmanr_2cols  s    OOAA&vvzzqz!!1$% vvaff~~++''::266266JC ffCOJJJqM
ai#aeeemA.//7FGG AA&[[%055 [[) RWWcfR%89??BCCA *
  Q4 88v++''::2d8;?:GC hCOJ++''::2DC OJ! *)s   4H
H#ra   ro   )rY   rQ   rJ   column_stackvstackTmasked_invalidr   rf   onesry   zerosranger   pvaluer   r   r   r   )r   r   use_tiesrN   
nan_policyrk   axisout_r   n_varsr   r   var1var2resultr   s        `          rP   r$   r$   ?  su   R NOO a&JA}A$a<'A		1&!A!|CCVa 'V WWQZF{""WWf%U3xx(6&1*%Dd1ff-)!A|O*<=!'!3!3:!'!3!3:#)==4Z #)==4Z  . & kk##66r@
rR   c           	      (   XU S-
  -  S-  U-
  :  nUS:H  n[        [        XU S-
  -  S-  U-
  5      5      nU S::  a  [        SU  S35      eUS:  d  SU-  X S-
  -  :  a  [        SU S	X S-
  -   S
35      eU S:X  a  SnSnGOU S:X  a  SnSnGOUS:X  a(  U S:  a  S[        R                  " U 5      -  OSnUS-  nGOUS:X  aB  U S:  a  S[        R                  " U S-
  5      -  OSnU S-
  [        R                  " U 5      -  nGOZSU-  X S-
  -  :X  a
  US:X  a  SnGOBU S:  a  [
        R                  " US-   5      nSUSS& [        SU S-   5       H6  n[
        R                  " U5      nX::  d  M   XxS === US US-   U-
   -  sss& M8     S[
        R                  " U5      -  [        R                  " U 5      -  nUS   [        R                  " U 5      -  nO[
        R                  " US-   5      nSUSS& [        SU S-   5       H9  n[
        R                  " U5      U-  nX::  d  M#  XxS === US US-   U-
   -  sss& M;     [
        R                  " U5      nUS   S-  nUS:w  a  X4:X  a  US-  nOSUS-  -
  W-   n[
        R                  " USS5      nU$ )NrA   ra   r_   r<   zn (z) must be positive   zc (z#) must satisfy 0 <= 4c <= n(n-1) = .r         ?   r              r`      )r   r   rY   math	factorialrf   r   r   cumsumr   r   )	r   crk   in_right_tailalternative_greaterr   p_mass_at_cnewjs	            rP   _kendall_p_exactr    s    ac7Q,**M&)3CqsGa<!#$%A 	Av3qc!3455	
Q!A#Q3-3qc!DQ!WIQOPP	
a	
a	
a()Cs4>>!$$S1f	
a*+c's4>>!A#&&ssDNN1--	
1Q3K;6 	
ShhqsmAaq1A))C.CvB3v!A;&  266#;t~~a00"gdnnQ//hhqsmAaq!A#A))C."CvB3v!A;&  vvc{"gaik! /AIDtAv:+D774ADKrR   c           
         [        X5      u  pnU R                  5       UR                  5       p[        R                  " [        R                  " U 5      [        R                  " U5      5      nU[
        LaF  [        R                  " XSS9n [        R                  " XSS9nU[        UR                  5       5      -  nUS:  a]  [        R                  R                  R                  [        R                  [        R                  5      n[        R                  Ul        U$ [        R                   " [#        XS9S5      n	[        R                   " [#        XS9S5      n
U	R%                  5       nX   X   p[        R                  " ['        [)        U
5      S-
  5       Vs/ s H9  nXS-   S X   :  XS-   S X   :  -  R+                  S5      R                  5       PM;     sn[,        S9n[        R                  " ['        [)        U
5      S-
  5       Vs/ s H9  nXS-   S X   :  XS-   S X   :  -  R+                  S5      R                  5       PM;     sn[,        S9n[/        U 5      n[/        U5      nU(       a  [        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  PM     snn[,        S9n[        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  PM     snn[,        S9n[        R2                  " XfS-
  -  U-
  S	-  XfS-
  -  U-
  -  S	-  5      nO
XfS-
  -  S	-  nX-
  U-  nUS
:X  a  U(       d  U(       a  [5        S5      eUS:X  a4  U(       d+  U(       d$  US::  d  [7        XUS-
  -  S	-  U-
  5      S::  a  S
nOSnU(       d  U(       d  US
:X  a  [9        XmU5      nGOUS:X  Gat  XfS-
  -  SU-  S-   -  nU(       Ga  U[        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  SU-  S-   -  S-  PM     snn5      -  nU[        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  SU-  S-   -  S-  PM     snn5      -  n[        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  PM     snn[,        S9[        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  PM     snn[,        S9-  nUS	U-  US-
  -  -  nUS:  a  [        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  US-
  -  PM     snn[,        S9[        R                  " UR1                  5        VVs/ s H  u  nnUU-  US-
  -  US-
  -  PM     snn[,        S9-  nUSU-  US-
  -  US-
  -  -  nOSnOS=nnUS-  nUUU-   -  nX-
  [        R2                  " U5      -  n[        R                  R                  R;                  U[<        R>                  U5      nO[5        S[A        U5      -   S-   5      e[        R                  R                  R                  US   US   5      nUUl        U$ s  snf s  snf s  snnf s  snnf s  snnf s  snnf s  snnf s  snnf s  snnf s  snnf )ac  
Computes Kendall's rank correlation tau on two variables *x* and *y*.

Parameters
----------
x : sequence
    First data list (for example, time).
y : sequence
    Second data list.
use_ties : {True, False}, optional
    Whether ties correction should be performed.
use_missing : {False, True}, optional
    Whether missing data should be allocated a rank of 0 (False) or the
    average rank (True)
method : {'auto', 'asymptotic', 'exact'}, optional
    Defines which method is used to calculate the p-value [1]_.
    'asymptotic' uses a normal approximation valid for large samples.
    'exact' computes the exact p-value, but can only be used if no ties
    are present. As the sample size increases, the 'exact' computation
    time may grow and the result may lose some precision.
    'auto' is the default and selects the appropriate
    method based on a trade-off between speed and accuracy.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis. Default is 'two-sided'.
    The following options are available:

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

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

    statistic : float
       The tau statistic.
    pvalue : float
       The p-value for a hypothesis test whose null hypothesis is
       an absence of association, tau = 0.

References
----------
.. [1] Maurice G. Kendall, "Rank Correlation Methods" (4th Edition),
       Charles Griffin & Co., 1970.

T)rr   r   ra   r   r<   rA   Nro   r   exactz(Ties found, exact method cannot be used.auto!   
asymptotic   r         "@g      2@zUnknown method z1 specified, please use auto, exact or asymptotic.rb   )!r\   flattenrJ   r   r   r?   rw   r   r   r   r   r   r   rf   r   r   masked_equalr   r   r   rs   r   ry   r   itemsr   rY   r   r  _get_pvaluerB   normstr)r   r   r   r   methodrk   r   r   r   rxryr   iCDxtiesytiesr   r   corr_xcorr_ydenomtaur   var_sv1v2zs                               rP   r   r     s   b !IQ1iik199;


2::a="**Q-0AHHQT*HHQT* 	
S\1ukk##66rvvrvvF&&
	!=q	AB	!=q	AB
**,C
s2wqy)+)A qST(RU"rA#$x"%'78@@CGGI)+27	9A
s2wqy)+)A qST(RU"R!X%56>>qAEEG)+27	9Aa Ea E>u!1ac>eL>u!1ac>eLaC+qA#wv~>rABQ3
3%-CeuCDDe!r'SqsGCKM5Ja5OF!F6W#4k2	<	Q31QRVVu{{}M}eqQqS!A#Y!A.r1}MNNERVVu{{}M}eqQqS!A#Y!A.r1}MNNE&&%++-@-A!A#qs)-@N&&%++-@-A!A#qs)-@NOB"Q$!*B1uVV%++-H-!AQqS!A#Y!_-H"')VV%++-H-!AQqS!A#Y!_-H"')) bdAaCj!A#&&KB"r'S"''%. {{$$00M4F4FT*3v;6 8: : ; 	; ++


2
23r7DH
ECCOJo++
 ?>* NM@@ IHs>   A ZA ZZ
Z
 $Z!$Z'#Z-
(Z3Z9
Z?c           	        ^ ^^ [         R                  " T SSSS9m T R                  u  pT R                  S5      n[	        U 4S j[        U5       5       5      nUR	                  5       nT R                  5       n[        T R                  5       5      n[	        S UR                  5        5       5      n[         R                  " SU-  US	-
  -  XfS	-
  -  U-
  -  5      S
-  n	[        T SSS9n
[         R                  " X"4[        S9n[         R                  " X"4[        S9n[         R                  " U[        S9n[        U5       GH  m[        T SS2T4   R                  5       5      n[	        S UR                  5        5       5      nUT   UT   S	-
  -  n[        TUS	5       H  m[	        UUU 4S j[        U5       5       5      UTT4'   UTT4   SU
SS2T4   U
SS2T4   -  R	                  5       -  -   XT   S	-   -  UT   S	-   -  -
  S-  UTT4'   UTT4   UTT4'   UTT4   UTT4'   M     [         R                  " UUU-
  -  5      S
-  UT'   GM     UR                  5       n[        U5      [!        U5      S	-
  -  [         R                  " U5      -  n[        U5      [!        U5      S	-
  -  [         R                  " UR	                  5       5      -  n[        U5      [!        U5      S	-
  -  [         R                  " UR	                  5       5      -  n["        R$                  " [!        UR&                  5      [(        R                  " S5      -  5      n["        R$                  " [!        U5      [(        R                  " S5      -  5      n["        R$                  " [!        U5      [(        R                  " S5      -  5      nUU-  R	                  5       nUUR+                  5       S-  -  nXM-  XY-  X]R	                  5       -  UUUUUS.nU$ )z
Computes a multivariate Kendall's rank correlation tau, for seasonal data.

Parameters
----------
x : 2-D ndarray
    Array of seasonal data, with seasons in columns.

TFra   subokr   ndminr<   c              3   j   >#    U  H(  n[        TUS  TU   -
  5      R                  S5      v   M*     g 7frH   r   r   ).0r#  r   s     rP   	<genexpr>&kendalltau_seasonal.<locals>.<genexpr>  s2     ;(QaeAaDj!%%a(((s   03c              3   :   #    U  H  u  pX!-  US -
  -  v   M     g7frA   Nrb   r6  r   r   s      rP   r7  r8    s     8<%1AC1I<   r   rA   r   )rN   r   ro   Nc              3   :   #    U  H  u  pX!-  US -
  -  v   M     g7fr:  rb   r;  s      rP   r7  r8    s     ;N5AQS!A#YNr<  c              3      >#    U  H?  n[        TUS 2T4   TUT4   -
  TUS 2T4   TUT4   -
  -  5      R                  5       v   MA     g 7fNr5  )r6  r#  r  r   r   s     rP   r7  r8    sZ      ,"*Q !"Q$!A#12a41Q3@AEEGG"*s   AA
r         @)zseasonal tauz
global tauzglobal tau (alt)zseasonal p-valuezglobal p-value (indep)zglobal p-value (dep)z
chi2 totalz
chi2 trend)rJ   rw   r   r   r   r   r   r   r  r   r   rx   r   ry   diagonalr   rg   rc   erfcr   rf   r   )r   r   r   n_pS_sznS_totn_totr   	corr_ties	denom_totRKcovmat	denom_sznties_jcorr_jcmbvar_sznz_szn	z_tot_ind	z_tot_depprob_sznprob_tot_indprob_tot_depchi2_totchi2_trdr   r  r   s   `                          @@rP   r	   r	     sl    	$U!4AGGEQ
''!*C;%(;;EIIKEGGIEQ\\^,D84::<88I5%'*E7OI,EFGJI-A
!c"AXXqe5)F%(I1X"1QqS6#4#4#67;FLLN;;!fc!fQhq1A ,"'(, ,AacFQqS6Aq1va!f}&9&9&;$;;!fQh<Q23467F1Q3KqsVAacF 1+F1Q3K  wwsCJ/025	!  ooG%LCJqL)BGGG,<<EeE
1-0FFIeE
1-

0EEI||C

OBGGAJ67H<<Irwwqz 9:L<<Irwwqz 9:Le  "H5::<?"H#o!O"'"7"*(4&2$$F MrR   PointbiserialrResult)r   r   c                    [         R                  " U SS9R                  [        5      n [         R                  " USS9R                  [        5      n[         R
                  " [         R                  " U 5      [         R                  " U5      5      nU[        La  [        R                  " U5      nX   n X   n[        U 5      nU R                  5       [	        U5      -  nX)    nX   nUR                  5       nUR                  5       n	X-
  [        R                  " USU-
  -  5      -  UR                  5       -  n
US-
  nU
[         R                  " USU
S-  -
  -  5      -  n[        SU-  SXX-  -   -  5      n[!        X5      $ )a  Calculates a point biserial correlation coefficient and its p-value.

Parameters
----------
x : array_like of bools
    Input array.
y : array_like
    Input array.

Returns
-------
correlation : float
    R value
pvalue : float
    2-tailed p-value

Notes
-----
Missing values are considered pair-wise: if a value is missing in x,
the corresponding value in y is masked.

For more details on `pointbiserialr`, see `scipy.stats.pointbiserialr`.

Tr   rA   ra   r   r  )rJ   fix_invalidastypeboolry   r   r   r?   rf   r{   rs   r   r   r   stdr   rY  )r   r   r   unmaskr   phaty0y1y0my1mrpbri   rj   r   s                 rP   r   r     s5   2 	qt$++D1A
qt$++E2A


2::a="**Q-0A"IIAA557U1XD	
2B	
B
'')C
'')C9bggdafo.
.
8C	
1BBGGBCF
O$$A#b&#rac6{+D**rR   c           	         Uch  [         R                  " U 5      n U R                  S   S:X  a  U u  pOfU R                  S   S:X  a  U R                  u  pOD[	        SU R                   35      e[         R                  " U 5      n [         R                  " U5      nU R                  5       n UR                  5       n[        R                  " U 5      [        R                  " U 5      :X  a  [        U 5      S:  a  [	        S5      e[         R                  " [         R                  " U 5      [         R                  " U5      SS9nU[        La  [         R                  " XS	9n [         R                  " XS	9n[        R                  " U) 5      (       a5  [        R                  " U R                   U)    UR                   U)    5      nU$ [        R"                  " SSSSSSS
9n U$ [        R                  " U R                   UR                   5      nU$ )aV  
Calculate a linear least-squares regression for two sets of measurements.

Parameters
----------
x, y : array_like
    Two sets of measurements.  Both arrays should have the same length N.  If
    only `x` is given (and ``y=None``), then it must be a two-dimensional
    array where one dimension has length 2.  The two sets of measurements
    are then found by splitting the array along the length-2 dimension. In
    the case where ``y=None`` and `x` is a 2xN array, ``linregress(x)`` is
    equivalent to ``linregress(x[0], x[1])``.

Returns
-------
result : ``LinregressResult`` instance
    The return value is an object with the following attributes:

    slope : float
        Slope of the regression line.
    intercept : float
        Intercept of the regression line.
    rvalue : float
        The Pearson correlation coefficient. The square of ``rvalue``
        is equal to the coefficient of determination.
    pvalue : float
        The p-value for a hypothesis test whose null hypothesis is
        that the slope is zero, using Wald Test with t-distribution of
        the test statistic. See `alternative` above for alternative
        hypotheses.
    stderr : float
        Standard error of the estimated slope (gradient), under the
        assumption of residual normality.
    intercept_stderr : float
        Standard error of the estimated intercept, under the assumption
        of residual normality.

See Also
--------
scipy.optimize.curve_fit :
    Use non-linear least squares to fit a function to data.
scipy.optimize.leastsq :
    Minimize the sum of squares of a set of equations.

Notes
-----
Missing values are considered pair-wise: if a value is missing in `x`,
the corresponding value in `y` is masked.

For compatibility with older versions of SciPy, the return value acts
like a ``namedtuple`` of length 5, with fields ``slope``, ``intercept``,
``rvalue``, ``pvalue`` and ``stderr``, so one can continue to write::

    slope, intercept, r, p, se = linregress(x, y)

With that style, however, the standard error of the intercept is not
available.  To have access to all the computed values, including the
standard error of the intercept, use the return value as an object
with attributes, e.g.::

    result = linregress(x, y)
    print(result.intercept, result.intercept_stderr)

Examples
--------
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy import stats
>>> rng = np.random.default_rng()

Generate some data:

>>> x = rng.random(10)
>>> y = 1.6*x + rng.random(10)

Perform the linear regression:

>>> res = stats.mstats.linregress(x, y)

Coefficient of determination (R-squared):

>>> print(f"R-squared: {res.rvalue**2:.6f}")
R-squared: 0.717533

Plot the data along with the fitted line:

>>> plt.plot(x, y, 'o', label='original data')
>>> plt.plot(x, res.intercept + res.slope*x, 'r', label='fitted line')
>>> plt.legend()
>>> plt.show()

Calculate 95% confidence interval on slope and intercept:

>>> # Two-sided inverse Students t-distribution
>>> # p - probability, df - degrees of freedom
>>> from scipy.stats import t
>>> tinv = lambda p, df: abs(t.ppf(p/2, df))

>>> ts = tinv(0.05, len(x)-2)
>>> print(f"slope (95%): {res.slope:.6f} +/- {ts*res.stderr:.6f}")
slope (95%): 1.453392 +/- 0.743465
>>> print(f"intercept (95%): {res.intercept:.6f}"
...       f" +/- {ts*res.intercept_stderr:.6f}")
intercept (95%): 0.616950 +/- 0.544475

Nr<   ra   rA   zZIf only `x` is given as input, it has to be of shape (2, N) or (N, 2), provided shape was zBCannot calculate a linear regression if all x values are identicalF)shrinkrq   )slope	interceptrvaluer   stderrintercept_stderr)rJ   rw   r   r   rY   r  rf   amaxaminrs   r   r   r?   r   r   r   r   LinregressResult)r   r   r   r   s       rP   r   r     s   V 	yHHQK771:?DAqWWQZ1_33DAq 33477)= > > HHQKHHQK			A			A	wwqzRWWQZCFQJ 9 : 	: 	

2::a="**Q->AHHQHHQ661"::))!&&!*affaRjAF M //dd7;D7;AEGF M %%affaff5MrR   c                 j   [         R                  " U 5      R                  5       n Uc#  [         R                  " [	        U 5      [
        S9nO`[         R                  " U5      R                  5       n[	        U5      [	        U 5      :w  a$  [        S[	        U 5       S[	        U5       S35      e[         R                  " [         R                  " U5      [         R                  " U 5      5      nU=U l	        Ul	        U R                  5       n UR                  5       R                  [
        5      n[        XX#S9$ )a  
Computes the Theil-Sen estimator for a set of points (x, y).

`theilslopes` implements a method for robust linear regression.  It
computes the slope as the median of all slopes between paired values.

Parameters
----------
y : array_like
    Dependent variable.
x : array_like or None, optional
    Independent variable. If None, use ``arange(len(y))`` instead.
alpha : float, optional
    Confidence degree between 0 and 1. Default is 95% confidence.
    Note that `alpha` is symmetric around 0.5, i.e. both 0.1 and 0.9 are
    interpreted as "find the 90% confidence interval".
method : {'joint', 'separate'}, optional
    Method to be used for computing estimate for intercept.
    Following methods are supported,

        * 'joint': Uses np.median(y - slope * x) as intercept.
        * 'separate': Uses np.median(y) - slope * np.median(x)
                      as intercept.

    The default is 'separate'.

    .. versionadded:: 1.8.0

Returns
-------
result : ``TheilslopesResult`` instance
    The return value is an object with the following attributes:

    slope : float
        Theil slope.
    intercept : float
        Intercept of the Theil line.
    low_slope : float
        Lower bound of the confidence interval on `slope`.
    high_slope : float
        Upper bound of the confidence interval on `slope`.

See Also
--------
siegelslopes : a similar technique using repeated medians


Notes
-----
For more details on `theilslopes`, see `scipy.stats.theilslopes`.

ro   Incompatible lengths ! (<>rW   )alphar   )rJ   ru   r  r   rs   ry   rY   r   r   _maskr   r\  stats_theilslopes)r   r   rs  r   r   s        rP   r&   r&     s    j 	

1AyIIc!fE*JJqM!!#q6SV7Axr#a&KLL


2::a="**Q-0AAGag	A	e$AQ>>rR   c                 j   [         R                  " U 5      R                  5       n Uc#  [         R                  " [	        U 5      [
        S9nO`[         R                  " U5      R                  5       n[	        U5      [	        U 5      :w  a$  [        S[	        U 5       S[	        U5       S35      e[         R                  " [         R                  " U5      [         R                  " U 5      5      nU=U l	        Ul	        U R                  5       n UR                  5       R                  [
        5      n[        XUS9$ )aP  
Computes the Siegel estimator for a set of points (x, y).

`siegelslopes` implements a method for robust linear regression
using repeated medians to fit a line to the points (x, y).
The method is robust to outliers with an asymptotic breakdown point
of 50%.

Parameters
----------
y : array_like
    Dependent variable.
x : array_like or None, optional
    Independent variable. If None, use ``arange(len(y))`` instead.
method : {'hierarchical', 'separate'}
    If 'hierarchical', estimate the intercept using the estimated
    slope ``slope`` (default option).
    If 'separate', estimate the intercept independent of the estimated
    slope. See Notes for details.

Returns
-------
result : ``SiegelslopesResult`` instance
    The return value is an object with the following attributes:

    slope : float
        Estimate of the slope of the regression line.
    intercept : float
        Estimate of the intercept of the regression line.

See Also
--------
theilslopes : a similar technique without repeated medians

Notes
-----
For more details on `siegelslopes`, see `scipy.stats.siegelslopes`.

ro   rq  rr  rW   )r   )rJ   ru   rL   r   rs   ry   rY   r   r   rt  r   r\  stats_siegelslopes)r   r   r   r   s       rP   r%   r%     s    P 	

1AyIIc!fE*JJqM!q6SV7Axr#a&KLL


2::a="**Q-0AAGag	A	e$Aa622rR   SenSeasonalSlopesResultintra_slopeinter_slopec                 v   [         R                  " U SSSS9n U R                  u  p[         R                  " [	        U5       Vs/ s H0  nXS-   S X   -
  [
        R                  " SX-
  5      SS2S4   -  PM2     sn5      n[         R                  " USS9n[         R                  " USS9n[        XV5      $ s  snf )	a  
Computes seasonal Theil-Sen and Kendall slope estimators.

The seasonal generalization of Sen's slope computes the slopes between all
pairs of values within a "season" (column) of a 2D array. It returns an
array containing the median of these "within-season" slopes for each
season (the Theil-Sen slope estimator of each season), and it returns the
median of the within-season slopes across all seasons (the seasonal Kendall
slope estimator).

Parameters
----------
x : 2D array_like
    Each column of `x` contains measurements of the dependent variable
    within a season. The independent variable (usually time) of each season
    is assumed to be ``np.arange(x.shape[0])``.

Returns
-------
result : ``SenSeasonalSlopesResult`` instance
    The return value is an object with the following attributes:

    intra_slope : ndarray
        For each season, the Theil-Sen slope estimator: the median of
        within-season slopes.
    inter_slope : float
        The seasonal Kendall slope estimator: the median of within-season
        slopes *across all* seasons.

See Also
--------
theilslopes : the analogous function for non-seasonal data
scipy.stats.theilslopes : non-seasonal slopes for non-masked arrays

Notes
-----
The slopes :math:`d_{ijk}` within season :math:`i` are:

.. math::

    d_{ijk} = \frac{x_{ij} - x_{ik}}
                        {j - k}

for pairs of distinct integer indices :math:`j, k` of :math:`x`.

Element :math:`i` of the returned `intra_slope` array is the median of the
:math:`d_{ijk}` over all :math:`j < k`; this is the Theil-Sen slope
estimator of season :math:`i`. The returned `inter_slope` value, better
known as the seasonal Kendall slope estimator, is the median of the
:math:`d_{ijk}` over all :math:`i, j, k`.

References
----------
.. [1] Hirsch, Robert M., James R. Slack, and Richard A. Smith.
       "Techniques of trend analysis for monthly water quality data."
       *Water Resources Research* 18.1 (1982): 107-121.

Examples
--------
Suppose we have 100 observations of a dependent variable for each of four
seasons:

>>> import numpy as np
>>> rng = np.random.default_rng()
>>> x = rng.random(size=(100, 4))

We compute the seasonal slopes as:

>>> from scipy import stats
>>> intra_slope, inter_slope = stats.mstats.sen_seasonal_slopes(x)

If we define a function to compute all slopes between observations within
a season:

>>> def dijk(yi):
...     n = len(yi)
...     x = np.arange(n)
...     dy = yi - yi[:, np.newaxis]
...     dx = x - x[:, np.newaxis]
...     # we only want unique pairs of distinct indices
...     mask = np.triu(np.ones((n, n), dtype=bool), k=1)
...     return dy[mask]/dx[mask]

then element ``i`` of ``intra_slope`` is the median of ``dijk[x[:, i]]``:

>>> i = 2
>>> np.allclose(np.median(dijk(x[:, i])), intra_slope[i])
True

and ``inter_slope`` is the median of the values returned by ``dijk`` for
all seasons:

>>> all_slopes = np.concatenate([dijk(x[:, i]) for i in range(x.shape[1])])
>>> np.allclose(np.median(all_slopes), inter_slope)
True

Because the data are randomly generated, we would expect the median slopes
to be nearly zero both within and across all seasons, and indeed they are:

>>> intra_slope.data
array([ 0.00124504, -0.00277761, -0.00221245, -0.00036338])
>>> inter_slope
-0.0010511779872922058

TFra   r1  rA   Nr<   r   )	rJ   rw   r   r   r   rf   r   medianrx  )r   r   r   r#  
szn_slopesszn_medslopesmedslopes          rP   r!   r!   (  s    T 	$U!4AGGEQ%*1X/%- stWQT\299Qqs+;AdF+CC%-/ 0JIIjq1Myy$/H"=;;	/s   7B6Ttest_1sampResult)	statisticr   c                    [        X5      u  pU R                  S:X  a   [        R                  [        R                  4$ U R	                  US9nU R                  USS9nU R                  US9n[        R                  " US-
  5      nUS-
  U-  U-  n[        R                  " SSS9   XA-
  [        R                  " X-  5      -  n	SSS5        [        UW	U5      u  p[        X5      $ ! , (       d  f       N(= f)	a  
Calculates the T-test for the mean of ONE group of scores.

Parameters
----------
a : array_like
    sample observation
popmean : float or array_like
    expected value in null hypothesis, if array_like than it must have the
    same shape as `a` excluding the axis dimension
axis : int or None, optional
    Axis along which to compute test. If None, compute over the whole
    array `a`.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis.
    The following options are available (default is 'two-sided'):

    * 'two-sided': the mean of the underlying distribution of the sample
      is different than the given population mean (`popmean`)
    * 'less': the mean of the underlying distribution of the sample is
      less than the given population mean (`popmean`)
    * 'greater': the mean of the underlying distribution of the sample is
      greater than the given population mean (`popmean`)

    .. versionadded:: 1.7.0

Returns
-------
statistic : float or array
    t-statistic
pvalue : float or array
    The p-value

Notes
-----
For more details on `ttest_1samp`, see `scipy.stats.ttest_1samp`.

r<   r   rA   rN   ddofr   r   r   invalidN)rQ   rX   rf   r   r   varr   rJ   rK   r   r   rm   r  )rM   popmeanrN   rk   r   r   r   ri   svarrj   r   s              rP   r4   r4     s    N 1#GAvv{	DA	4a A	TA	q3w	BWMRD	Hh	7[BGGDH-- 
8 B;/GAQ%%	 
8	7s   %C%%
C3Ttest_indResultc                    [        XU5      u  pnU R                  S:X  d  UR                  S:X  a(  [        [        R                  [        R                  5      $ U R                  U5      UR                  U5      peU R                  USS9UR                  USS9pU R                  U5      UR                  U5      pU(       aR  [        R                  " X-   S-
  5      nU	S-
  U-  U
S-
  U-  -   U-  n[        R                  " USU	-  SU
-  -   -  5      nOXy-  nX-  n[        R                  " SSS9   X-   S-  US-  U	S-
  -  US-  U
S-
  -  -   -  nS	S	S	5        [        R                  " [        R                  " W5      SU5      n[        R                  " X-   5      n[        R                  " SSS9   XV-
  U-  nS	S	S	5        [        UWU5      u  nn[        UU5      $ ! , (       d  f       N= f! , (       d  f       N;= f)
a|  
Calculates the T-test for the means of TWO INDEPENDENT samples of scores.

Parameters
----------
a, b : array_like
    The arrays must have the same shape, except in the dimension
    corresponding to `axis` (the first, by default).
axis : int or None, optional
    Axis along which to compute test. If None, compute over the whole
    arrays, `a`, and `b`.
equal_var : bool, optional
    If True, perform a standard independent 2 sample test that assumes equal
    population variances.
    If False, perform Welch's t-test, which does not assume equal population
    variance.

    .. versionadded:: 0.17.0
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis.
    The following options are available (default is 'two-sided'):

    * 'two-sided': the means of the distributions underlying the samples
      are unequal.
    * 'less': the mean of the distribution underlying the first sample
      is less than the mean of the distribution underlying the second
      sample.
    * 'greater': the mean of the distribution underlying the first
      sample is greater than the mean of the distribution underlying
      the second sample.

    .. versionadded:: 1.7.0

Returns
-------
statistic : float or array
    The calculated t-statistic.
pvalue : float or array
    The p-value.

Notes
-----
For more details on `ttest_ind`, see `scipy.stats.ttest_ind`.

r<   rA   r  r   r   r   r  ra   N)rU   rX   r  rf   r   r   r  r   rJ   rK   r   r   r   isnanrm   )rM   rT   rN   	equal_varrk   x1x2r-  r.  n1n2ri   r  r*  vn1vn2rj   r   s                     rP   r6   r6     s   \ qT*JA$vv{affkrvvrvv..taffTl4a(!%%T%*Bqwwt}]]27S=)Ar	2a4)#r)c"fs2vo./ee[[(;)a36R!V#4sAva7H#HIB <
 XXbhhrlAr*	"	Hh	7UeO 
8 B;/GAt1d## <; 
8	7s   / G0G-
G*-
G;Ttest_relResultc                 |   [        XU5      u  pn[        U 5      [        U5      :w  a  [        S5      eU R                  S:X  d  UR                  S:X  a(  [	        [
        R                  [
        R                  5      $ U R                  U5      n[        R                  " US-
  5      nX-
  R                  S5      nUR                  U5      nUR                  USS9n[        R                  " X-  5      n	[
        R                  " SSS9   Xy-  n
S	S	S	5        [        UW
U5      u  p[	        X5      $ ! , (       d  f       N(= f)
a!  
Calculates the T-test on TWO RELATED samples of scores, a and b.

Parameters
----------
a, b : array_like
    The arrays must have the same shape.
axis : int or None, optional
    Axis along which to compute test. If None, compute over the whole
    arrays, `a`, and `b`.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis.
    The following options are available (default is 'two-sided'):

    * 'two-sided': the means of the distributions underlying the samples
      are unequal.
    * 'less': the mean of the distribution underlying the first sample
      is less than the mean of the distribution underlying the second
      sample.
    * 'greater': the mean of the distribution underlying the first
      sample is greater than the mean of the distribution underlying
      the second sample.

    .. versionadded:: 1.7.0

Returns
-------
statistic : float or array
    t-statistic
pvalue : float or array
    two-tailed p-value

Notes
-----
For more details on `ttest_rel`, see `scipy.stats.ttest_rel`.

zunequal length arraysr<   r   drA   r  r   r  N)rU   rs   rY   rX   r  rf   r   r   rJ   rK   r\  r   r  r   r   rm   )rM   rT   rN   rk   r   ri   r  dmr   r*  rj   r   s               rP   r7   r7   .  s    L qT*JA$
1vQ011vv{affkrvvrvv..	A	qu	B	
SA	
B	4a AGGAENE	Hh	7J 
8 B;/GA1##	 
8	7s   D--
D;MannwhitneyuResultc                 x   [         R                  " U 5      R                  5       R                  [        5      n [         R                  " U5      R                  5       R                  [        5      n[        [        R                  " X/5      5      n[        U 5      [        U5      pTXE-   nUSU R                  5       XDS-   -  S-  -
  n[        XtU-  U-
  5      nXE-  U-
  nXE-  S-  n	US-  U-
  S-  n
[        U5      nU
[        S UR                  5        5       5      S-  -  n
XU-  [        XfS-
  -  5      -  -  n
U(       a   US-
  U	-
  [         R                  " U
5      -  nOXy-
  [         R                  " U
5      -  n[        R                   " [#        U5      [        R                  " S5      -  5      n[%        X5      $ )	a  
Computes the Mann-Whitney statistic

Missing values in `x` and/or `y` are discarded.

Parameters
----------
x : sequence
    Input
y : sequence
    Input
use_continuity : {True, False}, optional
    Whether a continuity correction (1/2.) should be taken into account.

Returns
-------
statistic : float
    The minimum of the Mann-Whitney statistics
pvalue : float
    Approximate two-sided p-value assuming a normal distribution.

NrA   r   r        (@c              3   :   #    U  H  u  pX!S -  U-
  -  v   M     g7fr  Nrb   r;  s      rP   r7  mannwhitneyu.<locals>.<genexpr>       6qDFr<  r  ra   )rJ   ru   r   r   r=   r   rf   concatenaters   r   rv   r   r  ry   r   rc   rB  rg   r  )r   r   use_continuityranksnxnyntUumusigsqr   r/  r   s                 rP   r   r   l  sm   . 	

1  "''0A


1  "''0AR^^QE*+EAA	Bcr
2!t9R<'AA"uqyA
	A
%BURZEU#D	S666s::E	U5T###EX]bggen,Vrwwu~%<<Arwwqz)*Da&&rR   KruskalResultc                  "   [        U 6 n[        R                  " [        USS9S5      nUR	                  S5      nUR                  S5      nUR                  5       nSXUS-   -  -  US-  U-  R	                  5       -  SUS-   -  -
  n[        U5      nS	[	        S
 UR                  5        5       5      [        US-  U-
  5      -  -
  nUS:X  a  [        S5      eXh-  n[        U5      S-
  n	[        R                  R                  Xi5      n
[        Xj5      $ )aQ  
Compute the Kruskal-Wallis H-test for independent samples

Parameters
----------
sample1, sample2, ... : array_like
   Two or more arrays with the sample measurements can be given as
   arguments.

Returns
-------
statistic : float
   The Kruskal-Wallis H statistic, corrected for ties
pvalue : float
   The p-value for the test using the assumption that H has a chi
   square distribution

Notes
-----
For more details on `kruskal`, see `scipy.stats.kruskal`.

Examples
--------
>>> from scipy.stats.mstats import kruskal

Random samples from three different brands of batteries were tested
to see how long the charge lasted. Results were as follows:

>>> a = [6.3, 5.4, 5.7, 5.2, 5.0]
>>> b = [6.9, 7.0, 6.1, 7.9]
>>> c = [7.2, 6.9, 6.1, 6.5]

Test the hypothesis that the distribution functions for all of the brands'
durations are identical. Use 5% level of significance.

>>> kruskal(a, b, c)
KruskalResult(statistic=7.113812154696133, pvalue=0.028526948491942164)

The null hypothesis is rejected at the 5% level of significance
because the returned p-value is less than the critical value of 5%.

Fr  r<   r  r  rA   ra   r  r   c              3   :   #    U  H  u  pX!S -  U-
  -  v   M     g7fr  rb   r;  s      rP   r7  kruskal.<locals>.<genexpr>  r  r<  z$All numbers are identical in kruskal)r   rJ   r  r   r   r   r   r  ry   rY   rs   rB   chi2sfr  )r~   r   r  sumrkngrpntotHr   r   ri   r   s              rP   r
   r
     s    V $FOOHV?CEIIbME;;r?D;;=DT6]uax}1133aaj@AU#D
S666uT1WT\7JJJAAv?@@FA	VqB  'D!!rR   r   r   c                     SSSS.R                  UR                  5       S   U5      n[        R                  R                  R                  XX#US9$ )a  
Computes the Kolmogorov-Smirnov test on one sample of masked values.

Missing values in `x` are discarded.

Parameters
----------
x : array_like
    a 1-D array of observations of random variables.
cdf : str or callable
    If a string, it should be the name of a distribution in `scipy.stats`.
    If a callable, that callable is used to calculate the cdf.
args : tuple, sequence, optional
    Distribution parameters, used if `cdf` is a string.
alternative : {'two-sided', 'less', 'greater'}, optional
    Indicates the alternative hypothesis.  Default is 'two-sided'.
method : {'auto', 'exact', 'asymp'}, optional
    Defines the method used for calculating the p-value.
    The following options are available (default is 'auto'):

      * 'auto' : use 'exact' for small size arrays, 'asymp' for large
      * 'exact' : use approximation to exact distribution of test statistic
      * 'asymp' : use asymptotic distribution of test statistic

Returns
-------
d : float
    Value of the Kolmogorov Smirnov test
p : float
    Corresponding p-value.

r`   r_   r^   rj   glr<   )r~   rk   r   )getlowerr   r   r   r   )r   cdfr~   rk   r   s        rP   r   r     sZ    D $)&AEE1{,K;;  ))	T6 * C CrR   c                     SSSS.R                  UR                  5       S   U5      n[        R                  R                  R                  XUUS9$ )a(  
Computes the Kolmogorov-Smirnov test on two samples.

Missing values in `x` and/or `y` are discarded.

Parameters
----------
data1 : array_like
    First data set
data2 : array_like
    Second data set
alternative : {'two-sided', 'less', 'greater'}, optional
    Indicates the alternative hypothesis.  Default is 'two-sided'.
method : {'auto', 'exact', 'asymp'}, optional
    Defines the method used for calculating the p-value.
    The following options are available (default is 'auto'):

      * 'auto' : use 'exact' for small size arrays, 'asymp' for large
      * 'exact' : use approximation to exact distribution of test statistic
      * 'asymp' : use asymptotic distribution of test statistic

Returns
-------
d : float
    Value of the Kolmogorov Smirnov test
p : float
    Corresponding p-value.

r`   r_   r^   r  r<   rk   r   )r  r  r   r   r   r   )data1data2rk   r   s       rP   r   r     sY    D $)&AEE1{,K;;  ))%6A17 * 9 9rR   c                 T    [         R                  R                  R                  XUX4S9$ )aJ  

Parameters
----------
data1 : array_like
data2 : str, callable or array_like
args : tuple, sequence, optional
    Distribution parameters, used if `data1` or `data2` are strings.
alternative : str, as documented in stats.kstest
method : str, as documented in stats.kstest

Returns
-------
tuple of (K-S statistic, probability)

r  )r   r   r   r   )r  r  r~   rk   r   s        rP   r   r   2  s/    $ ;;  ''d4? ( P PrR   c                    [         R                  " U 5      n U R                  5         Ub  US:X  a  U $ Uu  p4Uu  pVSnUb  U(       a  XpU:  -  nOXpU:*  -  nUb  U(       a  XpU:  -  nOXpU:  -  n[        XR	                  S5      '   U $ )a  
Trims an array by masking the data outside some given limits.

Returns a masked version of the input array.

Parameters
----------
a : array_like
    Input array.
limits : {None, tuple}, optional
    Tuple of (lower limit, upper limit) in absolute values.
    Values of the input array lower (greater) than the lower (upper) limit
    will be masked.  A limit is None indicates an open interval.
inclusive : (bool, bool) tuple, optional
    Tuple of (lower flag, upper flag), indicating whether values exactly
    equal to the lower (upper) limit are allowed.

Examples
--------
>>> from scipy.stats.mstats import trima
>>> import numpy as np

>>> a = np.arange(10)

The interval is left-closed and right-open, i.e., `[2, 8)`.
Trim the array by keeping only values in the interval.

>>> trima(a, limits=(2, 8), inclusive=(True, False))
masked_array(data=[--, --, 2, 3, 4, 5, 6, 7, --, --],
             mask=[ True,  True, False, False, False, False, False, False,
                    True,  True],
       fill_value=999999)

)NNFT)rJ   ru   unshare_maskr>   r   )rM   limits	inclusive	lower_lim	upper_limlower_inupper_inr   s           rP   r-   r-   H  s    F 	

1ANNFl2#Y$XIi-(Iy.)Ii-(Iy.)I &AtHrR   c           	         S n[         R                  " U 5      n U R                  5         Uc  U $ Uu  pVSnUb!  US:  d  US:  a  [        US-  SU S3-   5      eUb!  US:  d  US:  a  [        US-  SU S3-   5      eUu  pUc3  U R                  n
U" U R                  5       XVX5      R                  U
5      $ [         R                  " XCXXhU	5      $ )	a  
Trims an array by masking some proportion of the data on each end.
Returns a masked version of the input array.

Parameters
----------
a : sequence
    Input array.
limits : {None, tuple}, optional
    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.
    Noting n the number of unmasked data before trimming, the
    (n*limits[0])th smallest data and the (n*limits[1])th largest data are
    masked, and 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.
inclusive : {(True,True) tuple}, optional
    Tuple of flags indicating whether the number of data being masked on
    the left (right) end should be truncated (True) or rounded (False) to
    integers.
axis : {None,int}, optional
    Axis along which to trim. If None, the whole array is trimmed, but its
    shape is maintained.

c                 j   U R                  5       nU R                  5       nU(       aA  U(       a  [        X-  5      nO![        [        R                  " X-  5      5      n[
        XS U '   UbG  U(       a  U[        XR-  5      -
  nO$U[        [        R                  " XR-  5      5      -
  n[
        XUS  '   U $ r?  )r   r   r   rf   roundr>   )	rM   	low_limitup_limitlow_inclusiveup_inclusiver   r   lowidxupidxs	            rP   _trimr1Dtrimr.<locals>._trimr1D  s    GGIiikY[)RXXik23$A'6lOC
O+C 455#A%&kNrR   =The proportion to cut from the %s should be between 0. and 1.r   r<   	beginning(got rW   end)rJ   ru   r  rY   r   rL   r   r   )rM   r  r  rN   r  lolimuplimerrmsgloincupincshps              rP   r.   r.     s    4" 	

1ANN~ NULF2:Vk1eE7!4DDEE2:Ve^eWA.>>??NU|gg	%e:BB3GG""81ENNrR   aZ  
    Parameters
    ----------
    a : sequence
        Input array
    limits : {None, tuple}, optional
        If `relative` is False, tuple (lower limit, upper limit) in absolute values.
        Values of the input array lower (greater) than the lower (upper) limit are
        masked.

        If `relative` is True, tuple (lower percentage, upper percentage) to cut
        on each side of the  array, with respect to the number of unmasked data.

        Noting n the number of unmasked data before trimming, the (n*limits[0])th
        smallest data and the (n*limits[1])th largest data are masked, and the
        total number of unmasked data after trimming is n*(1.-sum(limits))
        In each case, the value of one limit can be set to None to indicate an
        open interval.

        If limits is None, no trimming is performed
    inclusive : {(bool, bool) tuple}, optional
        If `relative` is False, tuple indicating whether values exactly equal
        to the absolute limits are allowed.
        If `relative` is True, tuple indicating whether the number of data
        being masked on each side should be rounded (True) or truncated
        (False).
    relative : bool, optional
        Whether to consider the limits as absolute values (False) or proportions
        to cut (True).
    axis : int, optional
        Axis along which to trim.
c                 8    U(       a
  [        XX$S9$ [        XUS9$ )aL  
Trims an array by masking the data outside some given limits.

Returns a masked version of the input array.

%s

Examples
--------
>>> from scipy.stats.mstats import trim
>>> z = [ 1, 2, 3, 4, 5, 6, 7, 8, 9,10]
>>> print(trim(z,(3,8)))
[-- -- 3 4 5 6 7 8 -- --]
>>> print(trim(z,(0.1,0.2),relative=True))
[-- 2 3 4 5 6 7 8 -- --]

r  r  rN   r  r  )r.   r-   rM   r  r  relativerN   s        rP   r*   r*     s!    $ QFFQ;;rR   c                     [        XU4X#S9$ )aG  
Trims the smallest and largest data values.

Trims the `data` by masking the ``int(proportiontocut * n)`` smallest and
``int(proportiontocut * n)`` largest values of data along the given axis,
where n is the number of unmasked values before trimming.

Parameters
----------
data : ndarray
    Data to trim.
proportiontocut : float, optional
    Percentage of trimming (as a float between 0 and 1).
    If n is the number of unmasked values before trimming, the number of
    values after trimming is ``(1 - 2*proportiontocut) * n``.
    Default is 0.2.
inclusive : {(bool, bool) tuple}, optional
    Tuple indicating whether the number of data being masked on each side
    should be rounded (True) or truncated (False).
axis : int, optional
    Axis along which to perform the trimming.
    If None, the input array is first flattened.

r  )r.   )r   proportiontocutr  rN   s       rP   r+   r+     s    2 ?$1 1rR   c                     [        U5      R                  5       S   nUS:X  a  US4nOUS:X  a  SU4nO[        S5      e[        XXCS9$ )a  
Trims the data by masking values from one tail.

Parameters
----------
data : array_like
    Data to trim.
proportiontocut : float, optional
    Percentage of trimming. If n is the number of unmasked values
    before trimming, the number of values after trimming is
    ``(1 - proportiontocut) * n``.  Default is 0.2.
tail : {'left','right'}, optional
    If 'left' the `proportiontocut` lowest values will be masked.
    If 'right' the `proportiontocut` highest values will be masked.
    Default is 'left'.
inclusive : {(bool, bool) tuple}, optional
    Tuple indicating whether the number of data being masked on each side
    should be rounded (True) or truncated (False).  Default is
    (True, True).
axis : int, optional
    Axis along which to perform the trimming.
    If None, the input array is first flattened.  Default is None.

Returns
-------
trimtail : ndarray
    Returned array of same shape as `data` with masked tail values.

r<   r  Nr   z/The tail argument should be in ('left','right'))r  rN   r  )r  r  	TypeErrorr.   )r   r  tailr  rN   r  s         rP   r,   r,   !  sT    > t9??QDs{!$'	(IJJ4EErR   c                     [        U[        5      (       d  [        U[        5      (       a  X4nU(       a  [        XX$S9R	                  US9$ [        XUS9R	                  US9$ )z@Returns the trimmed mean of the data along the given axis.

%s

r  r   r  )rt   r   ry   r.   r   r-   r  s        rP   r/   r/   N  s^     ve$$*VE*B*B!QyCHHdHSSQy9>>D>IIrR   c                     [        U[        5      (       d  [        U[        5      (       a  X4nU(       a  [        XX$S9nO
[	        XUS9nUR                  XES9$ )a  Returns the trimmed variance of the data along the given axis.

%s
ddof : {0,integer}, optional
    Means Delta Degrees of Freedom. The denominator used during computations
    is (n-ddof). DDOF=0 corresponds to a biased estimate, DDOF=1 to an un-
    biased estimate of the variance.

r  r  r  )rt   r   ry   r.   r-   r  rM   r  r  r  rN   r  outs          rP   r2   r2   a  sQ     ve$$*VE*B*B!AyCAi8777((rR   c                     [        U[        5      (       d  [        U[        5      (       a  X4nU(       a  [        XX$S9nO
[	        XUS9nUR                  XES9$ )a(  Returns the trimmed standard deviation of the data along the given axis.

%s
ddof : {0,integer}, optional
    Means Delta Degrees of Freedom. The denominator used during computations
    is (n-ddof). DDOF=0 corresponds to a biased estimate, DDOF=1 to an un-
    biased estimate of the variance.

r  r  r  )rt   r   ry   r.   r-   r^  r  s          rP   r0   r0   z  sQ     ve$$*VE*B*B!AiBAi8777''rR   c           	      |   S n[         R                  " U SSS9n U R                  5         Uc6  U R                  USS9[         R                  " U R                  U5      5      -  $ [        U[        5      (       d  [        U[        5      (       a  X4nUu  pVSnUb!  US:  d  US:  a  [        US	-  S
U S3-   5      eUb!  US:  d  US:  a  [        US-  S
U S3-   5      eUu  pUc  U" U R                  5       XVX5      $ U R                  S:  a  [        SU R                  -  5      e[         R                  " XCU XVX5      $ )a  
Returns the standard error of the trimmed mean along the given axis.

Parameters
----------
a : sequence
    Input array
limits : {(0.1,0.1), tuple of float}, optional
    tuple (lower percentage, upper percentage) to cut  on each side of the
    array, with respect to the number of unmasked data.

    If n is the number of unmasked data before trimming, the values
    smaller than ``n * limits[0]`` and the values larger than
    ``n * `limits[1]`` are masked, and the total number of unmasked
    data after trimming is ``n * (1.-sum(limits))``.  In each case,
    the value of one limit can be set to None to indicate an open interval.
    If `limits` is None, no trimming is performed.
inclusive : {(bool, bool) tuple} optional
    Tuple indicating whether the number of data being masked on each side
    should be rounded (True) or truncated (False).
axis : int, optional
    Axis along which to trim.

Returns
-------
trimmed_stde : scalar or ndarray

c                    U R                  5       nU R                  5       nU(       a8  U(       a  [        X-  5      nO[        R                  " X-  5      n[
        XSU '   Ub>  U(       a  U[        XR-  5      -
  nOU[        R                  " XR-  5      -
  n[
        XUS '   XW      XSU '   XWS-
        XUS '   U R                  SS9n	U	SU-
  U-
  [        R                  " [        U 5      5      -  -  $ )zCReturns the standard error of the trimmed mean for a 1D input data.NrA   r  )	r   r   r   rf   r  r>   r^  r   rs   )
rM   r  r  r  r  r   r   r  r  winstds
             rP   _trimmed_stde_1D&trimmed_stde.<locals>._trimmed_stde_1D  s    GGIiikY[))+.$A'6lOC
O+BHHQZ00#A%&kNK.gv,uQw<ef+A!I+h.A?@@rR   Tr   r2  rA   r  r  r   r<   r  r  rW   r  ra   z>Array 'a' must be at most two dimensional, but got a.ndim = %d)rJ   rw   r  r^  r   r   rt   r   ry   rY   rL   rh   r   )
rM   r  r  rN   r  r  r  r  r  r  s
             rP   r1   r1     sK   :A* 	T*ANN~uu$Au&rwwqwwt}'===ve$$*VE*B*B! NULF2:Vk1eE7!4DDEE2:Ve^eWA.>>??NU	%eBB66A: 356VV< = =""#31#(u< 	<rR   c                 \   Uu  p4Uu  pV[         R                  " U 5      nUb4  U(       a  [         R                  " Xs5      nO[         R                  " Xs5      nUb4  U(       a  [         R                  " Xt5      nO[         R
                  " Xt5      nUR                  5       S:X  a  [        S5      eU$ )ad  Mask an array for values outside of given limits.

This is primarily a utility function.

Parameters
----------
a : array
limits : (float or None, float or None)
A tuple consisting of the (lower limit, upper limit).  Values in the
input array less than the lower limit or greater than the upper limit
will be masked out. None implies no limit.
inclusive : (bool, bool)
A tuple consisting of the (lower flag, upper flag).  These flags
determine whether values exactly equal to lower or upper are allowed.

Returns
-------
A MaskedArray.

Raises
------
A ValueError if there are no values within the given limits.
r<   z#No array values within given limits)rJ   MaskedArraymasked_lessmasked_less_equalmasked_greatermasked_greater_equalr   rY   )rM   r  r  lower_limitupper_limitlower_includeupper_includeams           rP   _mask_to_limitsr    s    0  &K#, M		B0B%%b6B""23B((9B	xxzQ>??IrR   c                 0    [        XUS9R                  US9$ )a  
Compute the trimmed mean.

Parameters
----------
a : array_like
    Array of values.
limits : None or (lower limit, upper limit), optional
    Values in the input array less than the lower limit or greater than the
    upper limit will be ignored.  When limits is None (default), then all
    values are used.  Either of the limit values in the tuple can also be
    None representing a half-open interval.
inclusive : (bool, bool), optional
    A tuple consisting of the (lower flag, upper flag).  These flags
    determine whether values exactly equal to the lower or upper limits
    are included.  The default value is (True, True).
axis : int or None, optional
    Axis along which to operate. If None, compute over the
    whole array. Default is None.

Returns
-------
tmean : float

Notes
-----
For more details on `tmean`, see `scipy.stats.tmean`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import mstats
>>> a = np.array([[6, 8, 3, 0],
...               [3, 9, 1, 2],
...               [8, 7, 8, 2],
...               [5, 6, 0, 2],
...               [4, 5, 5, 2]])
...
...
>>> mstats.tmean(a, (2,5))
3.3
>>> mstats.tmean(a, (2,5), axis=0)
masked_array(data=[4.0, 5.0, 4.0, 2.0],
             mask=[False, False, False, False],
       fill_value=1e+20)

r  r   )r-   r   )rM   r  r  rN   s       rP   r(   r(   	  s     ` Y7<<$<GGrR   c                 $   U R                  [        5      R                  5       n UcC  U R                  ) R	                  5       n[
        R                  R                  U 5      U-  US-
  -  $ [        XUS9n[
        R                  R                  XcUS9$ )a@  
Compute the trimmed variance

This function computes the sample variance of an array of values,
while ignoring values which are outside of given `limits`.

Parameters
----------
a : array_like
    Array of values.
limits : None or (lower limit, upper limit), optional
    Values in the input array less than the lower limit or greater than the
    upper limit will be ignored. When limits is None, then all values are
    used. Either of the limit values in the tuple can also be None
    representing a half-open interval.  The default value is None.
inclusive : (bool, bool), optional
    A tuple consisting of the (lower flag, upper flag).  These flags
    determine whether values exactly equal to the lower or upper limits
    are included.  The default value is (True, True).
axis : int or None, optional
    Axis along which to operate. If None, compute over the
    whole array. Default is zero.
ddof : int, optional
    Delta degrees of freedom. Default is 1.

Returns
-------
tvar : float
    Trimmed variance.

Notes
-----
For more details on `tvar`, see `scipy.stats.tvar`.

r   r  r  )	r\  ry   rL   rr   r   rf   rJ   r  r  )rM   r  r  rN   r  r   r  s          rP   r8   r8   @	  st    H 	
A~ffWMMOuuyy|a2&&	Y	?B5599R9..rR   c                 z    [        X5      u  p[        XS4US45      n[        R                  R	                  XB5      $ )a  
Compute the trimmed minimum

Parameters
----------
a : array_like
    array of values
lowerlimit : None or float, optional
    Values in the input array less than the given limit will be ignored.
    When lowerlimit is None, then all values are used. The default value
    is None.
axis : int or None, optional
    Axis along which to operate. Default is 0. If None, compute over the
    whole array `a`.
inclusive : {True, False}, optional
    This flag determines whether values exactly equal to the lower limit
    are included.  The default value is True.

Returns
-------
tmin : float, int or ndarray

Notes
-----
For more details on `tmin`, see `scipy.stats.tmin`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import mstats
>>> a = np.array([[6, 8, 3, 0],
...               [3, 2, 1, 2],
...               [8, 1, 8, 2],
...               [5, 3, 0, 2],
...               [4, 7, 5, 2]])
...
>>> mstats.tmin(a, 5)
masked_array(data=[5, 7, 5, --],
             mask=[False, False, False,  True],
       fill_value=999999)

NF)rQ   r-   rJ   minimumreduce)rM   
lowerlimitrN   r  r  s        rP   r)   r)   m	  s<    V 1#GA	qt$y%&8	9B::R&&rR   c                 |    [        X5      u  p[        U SU4SU45      n[        R                  R	                  XB5      $ )a  
Compute the trimmed maximum

This function computes the maximum value of an array along a given axis,
while ignoring values larger than a specified upper limit.

Parameters
----------
a : array_like
    array of values
upperlimit : None or float, optional
    Values in the input array greater than the given limit will be ignored.
    When upperlimit is None, then all values are used. The default value
    is None.
axis : int or None, optional
    Axis along which to operate. Default is 0. If None, compute over the
    whole array `a`.
inclusive : {True, False}, optional
    This flag determines whether values exactly equal to the upper limit
    are included.  The default value is True.

Returns
-------
tmax : float, int or ndarray

Notes
-----
For more details on `tmax`, see `scipy.stats.tmax`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import mstats
>>> a = np.array([[6, 8, 3, 0],
...               [3, 9, 1, 2],
...               [8, 7, 8, 2],
...               [5, 6, 0, 2],
...               [4, 5, 5, 2]])
...
...
>>> mstats.tmax(a, 4)
masked_array(data=[4, --, 3, 2],
             mask=[False,  True, False, False],
       fill_value=999999)

NF)rQ   r-   rJ   maximumr  )rM   
upperlimitrN   r  r  s        rP   r'   r'   	  s>    ^ 1#GA	q4$ui&8	9B::R&&rR   c                    [         R                  " U 5      R                  5       n Uc?  [        U R	                  5       5      nU R                  X4S9[         R                  " U5      -  $ [        U R                  5       X5      n[        R                  " UR                  X4S95      nU[        R                  " UR	                  5       5      -  $ )a0  
Compute the trimmed standard error of the mean.

This function finds the standard error of the mean for given
values, ignoring values outside the given `limits`.

Parameters
----------
a : array_like
    array of values
limits : None or (lower limit, upper limit), optional
    Values in the input array less than the lower limit or greater than the
    upper limit will be ignored. When limits is None, then all values are
    used. Either of the limit values in the tuple can also be None
    representing a half-open interval.  The default value is None.
inclusive : (bool, bool), optional
    A tuple consisting of the (lower flag, upper flag).  These flags
    determine whether values exactly equal to the lower or upper limits
    are included.  The default value is (True, True).
axis : int or None, optional
    Axis along which to operate. If None, compute over the
    whole array. Default is zero.
ddof : int, optional
    Delta degrees of freedom. Default is 1.

Returns
-------
tsem : float

Notes
-----
For more details on `tsem`, see `scipy.stats.tsem`.

r  )
rJ   ru   rL   ry   r   r^  r   r-   rf   r  )rM   r  r  rN   r  r   r  sds           rP   r3   r3   	  s    F 	

1A~!'')uu$u*2771:55	qwwy&	,B	T-	.B
###rR   c                    S n[        X5      u  pu[        R                  " U [        R                  " U5      S9n Uc  U $ [        U[        5      (       d  [        U[        5      (       a  X4nUu  pSn
Ub!  US:  d  US:  a  [        U
S-  SU S3-   5      eU	b!  U	S:  d  U	S:  a  [        U
S	-  SU	 S3-   5      eUu  pUc4  U R                  nU" U R                  5       XXXu5      R                  U5      $ [        R                  " XdXXXU5	      $ )
a  Returns a Winsorized version of the input array.

The (limits[0])th lowest values are set to the (limits[0])th percentile,
and the (limits[1])th highest values are set to the (1 - limits[1])th
percentile.
Masked values are skipped.


Parameters
----------
a : sequence
    Input array.
limits : {None, tuple of float}, optional
    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.
    Noting n the number of unmasked data before trimming, the
    (n*limits[0])th smallest data and the (n*limits[1])th largest data are
    masked, and 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.
inclusive : {(True, True) tuple}, optional
    Tuple indicating whether the number of data being masked on each side
    should be truncated (True) or rounded (False).
inplace : {False, True}, optional
    Whether to winsorize in place (True) or to use a copy (False)
axis : {None, int}, optional
    Axis along which to trim. If None, the whole array is trimmed, but its
    shape is maintained.
nan_policy : {'propagate', 'raise', 'omit'}, optional
    Defines how to handle when input contains nan.
    The following options are available (default is 'propagate'):

      * 'propagate': allows nan values and may overwrite or propagate them
      * 'raise': throws an error
      * 'omit': performs the calculations ignoring nan values

Notes
-----
This function is applied to reduce the effect of possibly spurious outliers
by limiting the extreme values.

Examples
--------
>>> import numpy as np
>>> from scipy.stats.mstats import winsorize

A shuffled array contains integers from 1 to 10.

>>> a = np.array([10, 4, 9, 8, 5, 3, 7, 2, 1, 6])

The 10% of the lowest value (i.e., ``1``) and the 20% of the highest
values (i.e., ``9`` and ``10``) are replaced.

>>> winsorize(a, limits=[0.1, 0.2])
masked_array(data=[8, 4, 8, 8, 5, 3, 7, 2, 2, 6],
             mask=False,
       fill_value=999999)

c                 x   U R                  5       nU R                  5       nU(       a*  [        R                  " [        R                  " U 5      5      n	U(       aj  U(       a  [        X-  5      n
O+[        R                  " X-  5      R                  [
        5      n
U(       a  US:X  a  [        XW	-
  S-
  5      n
XU
      XS U
 '   Ubt  U(       a  U[        Xr-  5      -
  nO.U[        R                  " Xr-  5      R                  [
        5      -
  nU(       a  US:X  a  XUS-
        XUW	*  '   U $ XUS-
        XUS  '   U $ )Nr   rA   )	r   r   rf   count_nonzeror  r   r  r\  r   )rM   r  r  low_include
up_includecontains_nanr   r   r   	nan_countr  r  s               rP   _winsorize1Dwinsorize.<locals>._winsorize1D;
  s   GGIiik((!5IY]+)-077<
f 4Vy[]3FnA'6lOC--BHHQ\299#>>
f 4+,^+<eYJ'(  "#uqy>!2ef+rR   r   r  r   r<   r  r  rW   r  )rD   rJ   rw   rf   r{   rt   r   ry   rY   r   rL   r   r   )rM   r  r  inplacerN   r   r  r  r  r  r  r  r  r  s                 rP   r:   r:   	  s'   z2  -Q;L
01A~vu%%:fe+D+D! NULF2:Vk1eE7!4DDEE2:Ve^eWA.>>??NU|ggAGGIuU(66=gcl	C ""<q#(
D 	DrR   c           
         [        X5      u  pU R                  S:X  a  [        U R                  5      nX2	 U R                  R
                  S;   a  U R                  R                  O[        R                  n[        R                  " U5      (       a  UO[        U5      /U-   n[        U5      S:X  a  U" [        R                  5      $ [        R                  " [        R                  " U[        R                  US95      $ [        R                  " U5      (       d@  U R                  USS9nU Vs/ s H  n[!        XX&S9PM     nn[        R                  " U5      $ [!        XU5      $ s  snf )a  
Calculates the nth moment about the mean for a sample.

Parameters
----------
a : array_like
   data
moment : int, optional
   order of central moment that is returned
axis : int or None, optional
   Axis along which the central moment is computed. Default is 0.
   If None, compute over the whole array `a`.

Returns
-------
n-th central moment : ndarray or float
   The appropriate moment along the given axis or over all values if axis
   is None. The denominator for the moment calculation is the number of
   observations, no degrees of freedom correction is done.

Notes
-----
For more details about `moment`, see `scipy.stats.moment`.

r<   fcro   Tr   r   )rQ   rX   r   r   rp   kindtyperf   r   isscalarrs   r   rJ   rw   fullr   _moment)	rM   r   rN   moment_shaperp   	out_shaper   r#  mmnts	            rP   r   r   r
  s   4 1#GAvv{AGG} ! 4"**%'[[%8%8\v;-,6 	y>Q= 88BGGIrvvUCDD ;;vvvdTv*8>?1d.?xx~q$'' @s   -E%r  c                4   [         R                  " U[         R                  " U5      -
  5      S:  a  [        S5      eUS:X  d  US:X  a  [	        U R
                  5      nXB	 U R                  R                  S;   a  U R                  R                  O[         R                  n[        U5      S:X  a  U" US:X  a  S5      $ S5      $ US:X  a  [        R                  " XES9$ [        R                  " XES9$ U/nUnUS:  a1  US-  (       a	  US-
  S-  nOUS-  nUR                  U5        US:  a  M1  Uc  U R                  US	S
9OUnX-
  nUS   S:X  a  UR!                  5       n	OUS-  n	USS S2    H  n
U	S-  n	U
S-  (       d  M  X-  n	M     U	R                  U5      $ )Nr<   z&All moment parameters must be integersrA   r  r   r  ro   ra   Tr  r  )rf   rg   r  rY   r   r   rp   r  r  r   rs   rJ   r   r   appendr   r   )rM   r   rN   r   r   rp   n_list	current_na_zero_meansr   s              rP   r  r  
  s   	vvfrxx''(1,ABB{fk QWWK ! 4"**u:?!555539Q;BGGE/ 7%57 	!m1}&q[!O	Q	MM)$ !m /3lqvvdTv*h":?  "AQA BA1A1uu    vvd|rR   c                 ^    [        X5      u  pU R                  XS9U R                  U5      -  $ )a  
Compute the coefficient of variation.

The coefficient of variation is the standard deviation divided by the
mean.  This function is equivalent to::

    np.std(x, axis=axis, ddof=ddof) / np.mean(x)

The default for ``ddof`` is 0, but many definitions of the coefficient
of variation use the square root of the unbiased sample variance
for the sample standard deviation, which corresponds to ``ddof=1``.

Parameters
----------
a : array_like
    Input array.
axis : int or None, optional
    Axis along which to calculate the coefficient of variation. Default
    is 0. If None, compute over the whole array `a`.
ddof : int, optional
    Delta degrees of freedom.  Default is 0.

Returns
-------
variation : ndarray
    The calculated variation along the requested axis.

Notes
-----
For more details about `variation`, see `scipy.stats.variation`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats.mstats import variation
>>> a = np.array([2,8,4])
>>> variation(a)
0.5345224838248487
>>> b = np.array([2,8,3,4])
>>> c = np.ma.masked_array(b, mask=[0,0,1,0])
>>> variation(c)
0.5345224838248487

In the example above, it can be seen that this works the same as
`scipy.stats.variation` except 'stats.mstats.variation' ignores masked
array elements.

r  )rQ   r^  r   )rM   rN   r  s      rP   r9   r9   
  s/    b 1#GA555!!&&,..rR   c                 F   [        X5      u  pU R                  USS9n[        U SXS9n[        U SXS9nU[        R                  " UR
                  5      R                  UR                  U5      -  S-  :*  n[        R                  " SS9   [        R                  " USXTS	-  -  5      nS
S
S
5        U(       d  U[        R                  La  U[        R                  La  U R                  U5      nU) US:  -  n	U	R                  5       (       a  [        R                  " X5      n[        R                  " X5      n[        R                  " X5      n[        R                  " US-
  U-  5      US-
  -  U-  US	-  -  n
[        R                   " WX5        W$ ! , (       d  f       N= f)a  
Computes the skewness of a data set.

Parameters
----------
a : ndarray
    data
axis : int or None, optional
    Axis along which skewness is calculated. Default is 0.
    If None, compute over the whole array `a`.
bias : bool, optional
    If False, then the calculations are corrected for statistical bias.

Returns
-------
skewness : ndarray
    The skewness of values along an axis, returning 0 where all values are
    equal.

Notes
-----
For more details about `skew`, see `scipy.stats.skew`.

Tr  ra   r  r  r   allr<         ?Nr   r   )rQ   r   r  rf   finforp   
resolutionsqueezer   rJ   r   r>   r   r   extractr   place)rM   rN   biasr   m2m3zerovalsr   can_correctnvals              rP   r"   r"     sN   2 1"GA66$6&D	At	'B	At	'B288BHH%004<<3EEIID		"xxa#g. 
# D		)b		.AGGDMeq1uo??

;*AK,BK,B77AcE19%qu-b0S8DHHT;-K 
#	"s   
F
F c                 d   [        X5      u  pU R                  USS9n[        U SXS9n[        U SXS9nU[        R                  " UR
                  5      R                  UR                  U5      -  S-  :*  n[        R                  " SS9   [        R                  " USXeS	-  -  5      nS
S
S
5        U(       d  U[        R                  La  U[        R                  La  U R                  U5      n	U) U	S:  -  n
U
R                  5       (       a  [        R                  " X5      n	[        R                  " X5      n[        R                  " X5      nSU	S-
  -  U	S-
  -  X-  S-
  U-  US	-  -  SU	S-
  S	-  -  -
  -  n[        R                  " WXS-   5        U(       a  WS-
  $ W$ ! , (       d  f       N= f)aq  
Computes the kurtosis (Fisher or Pearson) of a dataset.

Kurtosis is the fourth central moment divided by the square of the
variance. If Fisher's definition is used, then 3.0 is subtracted from
the result to give 0.0 for a normal distribution.

If bias is False then the kurtosis is calculated using k statistics to
eliminate bias coming from biased moment estimators

Use `kurtosistest` to see if result is close enough to normal.

Parameters
----------
a : array
    data for which the kurtosis is calculated
axis : int or None, optional
    Axis along which the kurtosis is calculated. Default is 0.
    If None, compute over the whole array `a`.
fisher : bool, optional
    If True, Fisher's definition is used (normal ==> 0.0). If False,
    Pearson's definition is used (normal ==> 3.0).
bias : bool, optional
    If False, then the calculations are corrected for statistical bias.

Returns
-------
kurtosis : array
    The kurtosis of values along an axis. If all values are equal,
    return -3 for Fisher's definition and 0 for Pearson's definition.

Notes
-----
For more details about `kurtosis`, see `scipy.stats.kurtosis`.

Tr  ra   r  r   r   r(  r<   r   Nr  r   rA   r@  )rQ   r   r  rf   r+  rp   r,  r-  r   rJ   r   r>   r   r   r.  r/  )rM   rN   fisherr0  r   r1  m4r3  r4  r   r5  r6  s               rP   r   r   0  sp   J 1#GA66$6&D	At	'B	At	'B288BHH%004<<3EEIID		"xxa#g. 
# D		)b		.AGGDMeq1uo??

;*AK,BK,B!9ac?QSWbLS$8AaC#:$EFDHHT;S1ax 
#	"s   
F!!
F/DescribeResult)nobsminmaxr   varianceskewnessr   c                 4   [        X5      u  pU R                  U5      n[        R                  R	                  XS9[        R
                  R	                  XS94nU R                  U5      nU R                  XS9n[        XUS9n[        XUS9n	[        XEXgX5      $ )a  
Computes several descriptive statistics of the passed array.

Parameters
----------
a : array_like
    Data array
axis : int or None, optional
    Axis along which to calculate statistics. Default 0. If None,
    compute over the whole array `a`.
ddof : int, optional
    degree of freedom (default 0); note that default ddof is different
    from the same routine in stats.describe
bias : bool, optional
    If False, then the skewness and kurtosis calculations are corrected for
    statistical bias.

Returns
-------
nobs : int
    (size of the data (discarding missing values)

minmax : (int, int)
    min, max

mean : float
    arithmetic mean

variance : float
    unbiased variance

skewness : float
    biased skewness

kurtosis : float
    biased kurtosis

Examples
--------
>>> import numpy as np
>>> from scipy.stats.mstats import describe
>>> ma = np.ma.array(range(6), mask=[0, 0, 0, 1, 1, 1])
>>> describe(ma)
DescribeResult(nobs=np.int64(3), minmax=(masked_array(data=0,
             mask=False,
       fill_value=999999), masked_array(data=2,
             mask=False,
       fill_value=999999)), mean=np.float64(1.0),
       variance=np.float64(0.6666666666666666),
       skewness=masked_array(data=0., mask=False, fill_value=1e+20),
        kurtosis=np.float64(-1.5))

r   r  )r0  )rQ   r   rJ   r  r  r  r   r  r"   r   r:  )
rM   rN   r  r0  r   mmr   r   skkurts
             rP   r   r   q  s    l 1#GA	A
**

A

)2::+<+<Q+<+J	KB	tA	dA	aD	!BA$'D!r00rR   c                     S n[         R                  " U SSS9n Uc  U" U 5      $ U R                  S:  a  [        SU R                  -  5      e[         R                  " X!U 5      $ )a7  Returns the McKean-Schrader estimate of the standard error of the sample
median along the given axis. masked values are discarded.

Parameters
----------
data : ndarray
    Data to trim.
axis : {None,int}, optional
    Axis along which to perform the trimming.
    If None, the input array is first flattened.

c           
         [         R                  " U R                  5       5      n [        U 5      nSn[	        [         R
                  " US-   S-  U[         R                  " US-  5      -  -
  S5      5      nXU-
     XS-
     -
  SU-  -  $ )Ng`dL@rA   r         @r<   )rf   sortr   rs   r   r  r   )r   r   r/  r   s       rP   _stdemed_1D stde_median.<locals>._stdemed_1D  sx    wwt()I!A#rA"$55a89cTA#Y&A./rR   FTr  ra   zDArray 'data' must be at most two dimensional, but got data.ndim = %d)rJ   rw   rh   rY   r   )r   rN   rG  s      rP   stde_medianrI    sj    0 88DuD1D4  99q= 68<		B C C"";d;;rR   SkewtestResultc                    [        X5      u  pUc  U R                  5       n Sn[        X5      nU R                  U5      n[        R
                  " U5      S:  a"  [        S[        R
                  " U5      -  5      eU[        R                  " US-   US-   -  SUS-
  -  -  5      -  nSXD-  S	U-  -   S
-
  -  US-   -  US-   -  US-
  US-   -  US-   -  US-   -  -  nS[        R                  " SUS-
  -  5      -   nS[        R                  " S[        R                  " U5      -  5      -  n[        R                  " SUS-
  -  5      n	[        R                  " US:H  SU5      nU[        R                  " XY-  [        R                  " XY-  S-  S-   5      -   5      -  n
[        R                  R                  R                  U
[        R                   U5      n[#        U
S   US   5      $ )a#  
Tests whether the skew is different from the normal distribution.

Parameters
----------
a : array_like
    The data to be tested
axis : int or None, optional
   Axis along which statistics are calculated. Default is 0.
   If None, compute over the whole array `a`.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis. Default is 'two-sided'.
    The following options are available:

    * 'two-sided': the skewness of the distribution underlying the sample
      is different from that of the normal distribution (i.e. 0)
    * 'less': the skewness of the distribution underlying the sample
      is less than that of the normal distribution
    * 'greater': the skewness of the distribution underlying the sample
      is greater than that of the normal distribution

    .. versionadded:: 1.7.0

Returns
-------
statistic : array_like
    The computed z-score for this test.
pvalue : array_like
    A p-value for the hypothesis test

Notes
-----
For more details about `skewtest`, see `scipy.stats.skewtest`.

r<      zFskewtest is not valid with less than 8 samples; %i samples were given.rA   r        @ra   r@     F   r   r     	   r  r  rb   )rQ   rL   r"   r   rf   r   rY   rJ   r   logr   r   r   r   r  rB   r  rJ  )rM   rN   rk   b2r   r   beta2W2deltars  Zr   s               rP   r#   r#     s   H 1#GA|GGI	aB	A	vvay1}VVAY'( 	( 	RWWqsQqSkc1Q3i011A!#bd(2+!$ac*#!}ac/BAaC/HIE	bggaqk"	"Bbggc"&&*n%%EGGCAJE
aAAbffQWrww!|A~6677A[[""..q-2D2DkRF!B%,,rR   KurtosistestResultc           	      Z   [        X5      u  pU R                  US9n[        R                  " U5      S:  a"  [	        S[        R                  " U5      -  5      e[        R                  " U5      S:  a,  [
        R                  " S[        R                  " U5      -  SS9  [        XSS	9nS
US-
  -  US-   -  nSU-  US-
  -  US-
  -  US-   US-   -  US-   -  US-   -  -  nXE-
  [        R                  " U5      -  nSX3-  SU-  -
  S-   -  US-   US-   -  -  [        R                  " SUS-   -  US-   -  X3S-
  -  US-
  -  -  5      -  nSSU-  SU-  [        R                  " SSUS-  -  -   5      -   -  -   n	SSSU	-  -  -
  n
SU[        R                  " SU	S-
  -  5      -  -   n[        R                  R                  U5      (       a  [        XS:H  '   OUS:X  a  [        n[        R                  R                  US:  [        R                  " SSU	-  -
  U-  S5      [        R                  " SSU	-  -
  * U-  S5      * 5      nX-
  [        R                  " SSU	-  -  5      -  n[        R                  R                   R#                  U[$        R&                  U5      n[)        US   US   5      $ )a  
Tests whether a dataset has normal kurtosis

Parameters
----------
a : array_like
    array of the sample data
axis : int or None, optional
   Axis along which to compute test. Default is 0. If None,
   compute over the whole array `a`.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis.
    The following options are available (default is 'two-sided'):

    * 'two-sided': the kurtosis of the distribution underlying the sample
      is different from that of the normal distribution
    * 'less': the kurtosis of the distribution underlying the sample
      is less than that of the normal distribution
    * 'greater': the kurtosis of the distribution underlying the sample
      is greater than that of the normal distribution

    .. versionadded:: 1.7.0

Returns
-------
statistic : array_like
    The computed z-score for this test.
pvalue : array_like
    The p-value for the hypothesis test

Notes
-----
For more details about `kurtosistest`, see `scipy.stats.kurtosistest`.

r   r  zJkurtosistest requires at least 5 observations; %i observations were given.   z=kurtosistest only valid for n>=20 ... continuing anyway, n=%ira   )
stacklevelF)r8  r@  rA   g      8@r   r  r   rM  rP  rQ  g       @rE  r  r  r<   gUUUUUU?rb   )rQ   r   rf   r   rY   warningswarnr   rJ   r   isMaskedArrayr>   r   powerr   r   r   r  rB   r  rX  )rM   rN   rk   r   rS  Evarb2r   	sqrtbeta1Aterm1r*  term2rW  r   s                  rP   r   r     s   H 1#GA	TA	vvay1}VVAY'( 	( 
vvay2~KbffUViW	

 
!%	(BQqS	QqSAFAbDM1Q3AaC!B$<1#5qs#;<E	rwwu~AQS1WQY!A#!-acAaC9:aC!A#9H 1I IIc)ms9}rwwqil9K7K/LLMMACE
NE"''!QsU)$$$E	uu5!!$sl	#EEKK	288Qs1uWeOU#CAc!eG*U"2E::<E	"''!SU),,A[[""..q-2D2DkRFaeVBZ00rR   NormaltestResultc                     [        X5      u  p[        X5      u  p#[        X5      u  pCX"-  XD-  -   n[        U[        R
                  R                  US5      5      $ )ac  
Tests whether a sample differs from a normal distribution.

Parameters
----------
a : array_like
    The array containing the data to be tested.
axis : int or None, optional
    Axis along which to compute test. Default is 0. If None,
    compute over the whole array `a`.

Returns
-------
statistic : float or array
    ``s^2 + k^2``, where ``s`` is the z-score returned by `skewtest` and
    ``k`` is the z-score returned by `kurtosistest`.
pvalue : float or array
   A 2-sided chi squared probability for the hypothesis test.

Notes
-----
For more details about `normaltest`, see `scipy.stats.normaltest`.

ra   )rQ   r#   r   rf  rB   r  r  )rM   rN   r%  r   r   k2s         rP   r   r   [  sU    2 1#GAADA DA	
qsBB 2 2 5 5b! <==rR   c                 |   S n[         R                  " U SS9nUR                  S:  a  [        S5      eU(       a(  US   U:  XuS   :  -  n[        XxR                  S5      ) '   [        R                  " [        R                  " U5      5      n	X)S	U-
  U-
  -  -   n
Uc	  U" XzU	5      $ [         R                  " XdXzU	5      $ )
a  
Computes empirical quantiles for a data array.

Samples quantile are defined by ``Q(p) = (1-gamma)*x[j] + gamma*x[j+1]``,
where ``x[j]`` is the j-th order statistic, and gamma is a function of
``j = floor(n*p + m)``, ``m = alphap + p*(1 - alphap - betap)`` and
``g = n*p + m - j``.

Reinterpreting the above equations to compare to **R** lead to the
equation: ``p(k) = (k - alphap)/(n + 1 - alphap - betap)``

Typical values of (alphap,betap) are:
    - (0,1)    : ``p(k) = k/n`` : linear interpolation of cdf
      (**R** type 4)
    - (.5,.5)  : ``p(k) = (k - 1/2.)/n`` : piecewise linear function
      (**R** type 5)
    - (0,0)    : ``p(k) = k/(n+1)`` :
      (**R** type 6)
    - (1,1)    : ``p(k) = (k-1)/(n-1)``: p(k) = mode[F(x[k])].
      (**R** type 7, **R** default)
    - (1/3,1/3): ``p(k) = (k-1/3)/(n+1/3)``: Then p(k) ~ median[F(x[k])].
      The resulting quantile estimates are approximately median-unbiased
      regardless of the distribution of x.
      (**R** type 8)
    - (3/8,3/8): ``p(k) = (k-3/8)/(n+1/4)``: Blom.
      The resulting quantile estimates are approximately unbiased
      if x is normally distributed
      (**R** type 9)
    - (.4,.4)  : approximately quantile unbiased (Cunnane)
    - (.35,.35): APL, used with PWM

Parameters
----------
a : array_like
    Input data, as a sequence or array of dimension at most 2.
prob : array_like, optional
    List of quantiles to compute.
alphap : float, optional
    Plotting positions parameter, default is 0.4.
betap : float, optional
    Plotting positions parameter, default is 0.4.
axis : int, optional
    Axis along which to perform the trimming.
    If None (default), the input array is first flattened.
limit : tuple, optional
    Tuple of (lower, upper) values.
    Values of `a` outside this open interval are ignored.

Returns
-------
mquantiles : MaskedArray
    An array containing the calculated quantiles.

Notes
-----
This formulation is very similar to **R** except the calculation of
``m`` from ``alphap`` and ``betap``, where in **R** ``m`` is defined
with each type.

References
----------
.. [1] *R* statistical software: https://www.r-project.org/
.. [2] *R* ``quantile`` function:
        http://stat.ethz.ch/R-manual/R-devel/library/stats/html/quantile.html

Examples
--------
>>> import numpy as np
>>> from scipy.stats.mstats import mquantiles
>>> a = np.array([6., 47., 49., 15., 42., 41., 7., 39., 43., 40., 36.])
>>> mquantiles(a)
array([ 19.2,  40. ,  42.8])

Using a 2D array, specifying axis and limit.

>>> data = np.array([[   6.,    7.,    1.],
...                  [  47.,   15.,    2.],
...                  [  49.,   36.,    3.],
...                  [  15.,   39.,    4.],
...                  [  42.,   40., -999.],
...                  [  41.,   41., -999.],
...                  [   7., -999., -999.],
...                  [  39., -999., -999.],
...                  [  43., -999., -999.],
...                  [  40., -999., -999.],
...                  [  36., -999., -999.]])
>>> print(mquantiles(data, axis=0, limit=(0, 50)))
[[19.2  14.6   1.45]
 [40.   37.5   2.5 ]
 [42.8  40.05  3.55]]

>>> data[:, 2] = -999.
>>> print(mquantiles(data, axis=0, limit=(0, 50)))
[[19.200000000000003 14.6 --]
 [40.0 37.5 --]
 [42.800000000000004 40.05 --]]

c                 `   [         R                  " U R                  5       5      n[        U5      nUS:X  a5  [        R
                  " [         R                  " [        U5      [        S9SS9$ US:X  a7  [        R
                  " [         R                  " X2R                  5      [        S9$ XB-  U-   n[         R                  " UR                  SUS-
  5      5      R                  [        5      nXV-
  R                  SS5      nSU-
  X6S-
  R                  5          -  XsUR                  5          -  -   $ )Nr<   ro   Trq   rA   r   )rf   rF  r   rs   rJ   rw   rx   ry   resizer   r?   floorr   r\  r   tolist)r   r   pr   r   alephr   gammas           rP   _quantiles1D mquantiles.<locals>._quantiles1D  s    GGDOO%&F688BHHSV59EE!V88BIIa1??qHHUZZ1Q3'(//4q#5!qSLLN++eahhjM.AAArR   Fr   ra   zArray should be 2D at most !r<   rA   Tr   )
rJ   rw   rh   r  r>   r   rf   
atleast_1dru   r   )rM   r   alphapbetaprN   limitrq  r   r   rn  r   s              rP   r   r   |  s    H
B 88AE"Dyy1}6771X_a9	(.t$$%
bjj&'ABvIeO$$ADQ''|4A>>rR   c           	      t    US:  d  US:  a  [        SU S35      e[        XS-  /X4USS9R                  5       $ )zCalculate the score at the given 'per' percentile of the
sequence a.  For example, the score at per=50 is the median.

This function is a shortcut to mquantile

r<   g      Y@z4The percentile should be between 0. and 100. ! (got rW   )r   rt  ru  rv  rN   )rY   r   r-  )r   perrv  rt  ru  s        rP   r   r     sK     	aS4ZOPSuTUVWWdd(F!++2795rR   c                 l   [         R                  " U SS9R                  SS5      n U R                  5       n[        R
                  " U R                  [        S9nSXCS& [        R                  " SUS-   5      U-
  US-   U-
  U-
  -  X@R                  SS	9SU '   [         R                  " X@R                  S
9$ )a  
Returns plotting positions (or empirical percentile points) for the data.

Plotting positions are defined as ``(i-alpha)/(n+1-alpha-beta)``, where:
    - i is the rank order statistics
    - n is the number of unmasked values along the given axis
    - `alpha` and `beta` are two parameters.

Typical values for `alpha` and `beta` are:
    - (0,1)    : ``p(k) = k/n``, linear interpolation of cdf (R, type 4)
    - (.5,.5)  : ``p(k) = (k-1/2.)/n``, piecewise linear function
      (R, type 5)
    - (0,0)    : ``p(k) = k/(n+1)``, Weibull (R type 6)
    - (1,1)    : ``p(k) = (k-1)/(n-1)``, in this case,
      ``p(k) = mode[F(x[k])]``. That's R default (R type 7)
    - (1/3,1/3): ``p(k) = (k-1/3)/(n+1/3)``, then
      ``p(k) ~ median[F(x[k])]``.
      The resulting quantile estimates are approximately median-unbiased
      regardless of the distribution of x. (R type 8)
    - (3/8,3/8): ``p(k) = (k-3/8)/(n+1/4)``, Blom.
      The resulting quantile estimates are approximately unbiased
      if x is normally distributed (R type 9)
    - (.4,.4)  : approximately quantile unbiased (Cunnane)
    - (.35,.35): APL, used with PWM
    - (.3175, .3175): used in scipy.stats.probplot

Parameters
----------
data : array_like
    Input data, as a sequence or array of dimension at most 2.
alpha : float, optional
    Plotting positions parameter. Default is 0.4.
beta : float, optional
    Plotting positions parameter. Default is 0.4.

Returns
-------
positions : MaskedArray
    The calculated plotting positions.

Fr   rA   r  ro   r<   Nr   r   rq   )rJ   rw   r   r   rf   rx   rX   ry   r   r   rt  )r   rs  betar   plposs        rP   r   r     s    T 88Du%--a3D

AHHTYYe,EE"I+-99Q!+<u+D+,s7U?T+A+CE,,D,
!"1
%&88E

++rR   c                  z   [        U 6 R                  nUR                  SSS9nUR                  S5      nUR	                  S5      R                  [        5      nX-  nUS-  nXS-
  U-  -  nUSU-  US-
  -  -  nXS-
  US-
  -  -  n[        R                  " X!R                  S5      5      (       d  [        S	5      eU$ )
aj  
Computes a transform on input data (any number of columns).  Used to
test for homogeneity of variance prior to running one-way stats.  Each
array in ``*args`` is one level of a factor.  If an `f_oneway()` run on
the transformed data and found significant, variances are unequal.   From
Maxwell and Delaney, p.112.

Returns: transformed data for use in an ANOVA
r<   rA   r  ra   r*  r  r   r   z'Lack of convergence in obrientransform.)
r   r   r  r   r   r\  ry   rJ   allcloserY   )r~   r   r   r   r   s        rP   r   r   A  s     DaQA		!A

1U#AIDQJDsUAIDCE1Q3KDrTAbDMD;;q1&&BCCKrR   c                     [        X5      u  pU R                  US9nU R                  XS9[        R                  " U5      -  nU$ )a  
Calculates the standard error of the mean of the input array.

Also sometimes called standard error of measurement.

Parameters
----------
a : array_like
    An array containing the values for which the standard error is
    returned.
axis : int or None, optional
    If axis is None, ravel `a` first. If axis is an integer, this will be
    the axis over which to operate. Defaults to 0.
ddof : int, optional
    Delta degrees-of-freedom. How many degrees of freedom to adjust
    for bias in limited samples relative to the population estimate
    of variance. Defaults to 1.

Returns
-------
s : ndarray or float
    The standard error of the mean in the sample(s), along the input axis.

Notes
-----
The default value for `ddof` changed in scipy 0.15.0 to be consistent with
`scipy.stats.sem` as well as with the most common definition used (like in
the R documentation).

Examples
--------
Find standard error along the first axis:

>>> import numpy as np
>>> from scipy import stats
>>> a = np.arange(20).reshape(5,4)
>>> print(stats.mstats.sem(a))
[2.8284271247461903 2.8284271247461903 2.8284271247461903
 2.8284271247461903]

Find standard error across the whole array, using n degrees of freedom:

>>> print(stats.mstats.sem(a, axis=None, ddof=0))
1.2893796958227628

r   r  )rQ   r   r^  rJ   r   )rM   rN   r  r   r%  s        rP   r    r    [  sC    ^ 1#GA	TA	4#bggaj0AHrR   F_onewayResultc                     [        U 6 n[        U5      nUR                  5       nUS-  R                  5       UR                  5       S-  [	        U5      -  -
  nUR                  S5      UR                  S5      UR                  5       -
  S-  -  R                  5       nXE-
  nUS-
  nX2-
  nU[	        U5      -  n	U[	        U5      -  n
X-  n[        R                  " XxU5      n[        X5      $ )aZ  
Performs a 1-way ANOVA, returning an F-value and probability given
any number of groups.  From Heiman, pp.394-7.

Usage: ``f_oneway(*args)``, where ``*args`` is 2 or more arrays,
one per treatment group.

Returns
-------
statistic : float
    The computed F-value of the test.
pvalue : float
    The associated p-value from the F-distribution.

ra   r  rA   )	r   rs   r   r   ry   r   rc   fdtrcr  )r~   r   ngroupsr  sstotssbgsswgdfbgdfwgmsbmswfr   s                rP   r   r     s    " D$iG::<D1WMMOtxxzAoeDk99EJJrNdiimDIIK7!;;@@BD:D19D>D
uT{
C
uT{
CA==Q'D!""rR   FriedmanchisquareResultc                     [        U 6 R                  [        5      n[        U5      nUS:  a  [	        SU-  S-   5      e[
        R                  " [        USS9S5      nUR                  [        LaJ  [
        R                  " U5      nUR                  5       R                  US5      R                  [        5      nOUR                  nUR                   u  p$UR"                   Vs/ s H  n[%        U5      PM     nn[&        R(                  " U VVs/ s H  u  pxUR*                  S:  d  M  UPM     snn5      n	SU	S-  U	-
  R-                  5       [        XBS-  U-
  -  5      -  -
  n
[&        R,                  " UR-                  S5      XBS-   -  S-  -
  S	-  5      nUS
-  XB-  US-   -  -  S-  U
-  n[/        U[0        R2                  R5                  XS-
  5      5      $ s  snf s  snnf )a   Friedman Chi-Square is a non-parametric, one-way within-subjects ANOVA.
This function calculates the Friedman Chi-square test for repeated measures
and returns the result, along with the associated probability value.

Each input is considered a given group. Ideally, the number of treatments
among each group should be equal. If this is not the case, only the first
n treatments are taken into account, where n is the number of treatments
of the smallest group.
If a group has some missing values, the corresponding treatments are masked
in the other groups.
The test statistic is corrected for ties.

Masked values in one group are propagated to the other groups.

Returns
-------
statistic : float
    the test statistic.
pvalue : float
    the associated p-value.

r  zLess than 3 groups (%i): z%the Friedman test is NOT appropriate.r<   r   r  rA   r   ra   r  r   )r   r\  ry   rs   rY   rJ   masked_valuesr   rt  r?   	mask_colsr   r   r   r=   r}   r   r   r   rf   rw   rX   r   r  rB   r  r  )r~   r   r   rankedr   rowr   r   r   r   tie_correctionr  chisqs                rP   r   r     s   . $$U+DD	A1u4q8@A B 	B ht!4a8F||6!f%""$,,Qr277@LLEQ,2HH5HS|C HG58879741affqjQ79:D$'$,++-eA!tAvJ.???N666::b>AsGBJ.23D3JQqS	"R'6E"5#0#5#5#8#8!#DF F 69s   "GG
(G
BrunnerMunzelResultc                    [         R                  " U 5      R                  5       R                  [        5      n [         R                  " U5      R                  5       R                  [        5      n[        U 5      n[        U5      nUS:X  d  US:X  a(  [        [        R                  [        R                  5      $ [        [        R                  " X45      5      nUSU nXdXE-    n[        R                  " U5      n	[        R                  " U5      n
[        U 5      n[        U5      n[        R                  " U5      n[        R                  " U5      n[        R                  " [        R                  " X{-
  U	-
  U-   S5      5      nXS-
  -  n[        R                  " [        R                  " X-
  U
-
  U-   S5      5      nUUS-
  -  nXE-  X-
  -  nUXE-   [        R                  " XO-  UU-  -   5      -  -  nUS:X  a  [        R                  " XO-  UU-  -   S5      n[        R                  " XO-  S5      US-
  -  nU[        R                  " UU-  S5      US-
  -  -  nUU-  n[        R                   R#                  UU5      nO1US:X  a   [        R$                  R#                  U5      nO['        S5      eUS:X  a  O<US:X  a  SU-
  nO0US	:X  a  S
[        R(                  " USU-
  /5      -  nO['        S5      e[        UU5      $ )a  
Compute the Brunner-Munzel test on samples x and y.

Any missing values in `x` and/or `y` are discarded.

The Brunner-Munzel test is a nonparametric test of the null hypothesis that
when values are taken one by one from each group, the probabilities of
getting large values in both groups are equal.
Unlike the Wilcoxon-Mann-Whitney's U test, this does not require the
assumption of equivariance of two groups. Note that this does not assume
the distributions are same. This test works on two independent samples,
which may have different sizes.

Parameters
----------
x, y : array_like
    Array of samples, should be one-dimensional.
alternative : 'less', 'two-sided', or 'greater', optional
    Whether to get the p-value for the one-sided hypothesis ('less'
    or 'greater') or for the two-sided hypothesis ('two-sided').
    Defaults value is 'two-sided' .
distribution : 't' or 'normal', optional
    Whether to get the p-value by t-distribution or by standard normal
    distribution.
    Defaults value is 't' .

Returns
-------
statistic : float
    The Brunner-Munzer W statistic.
pvalue : float
    p-value assuming an t distribution. One-sided or
    two-sided, depending on the choice of `alternative` and `distribution`.

See Also
--------
mannwhitneyu : Mann-Whitney rank test on two samples.

Notes
-----
For more details on `brunnermunzel`, see `scipy.stats.brunnermunzel`.

Examples
--------
>>> from scipy.stats.mstats import brunnermunzel
>>> import numpy as np
>>> x1 = [1, 2, np.nan, np.nan, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1]
>>> x2 = [3, 3, 4, 3, 1, 2, 3, 1, 1, 5, 4]
>>> brunnermunzel(x1, x2)
BrunnerMunzelResult(statistic=1.4723186918922935, pvalue=0.15479415300426624)  # may vary

r<   r   rA   rj   normalz&distribution should be 't' or 'normal'r_   r^   r`   ra   z6alternative should be 'less', 'greater' or 'two-sided')rJ   ru   r   r   r=   rs   r  rf   r   r   r  r   r   r_  r   rB   rj   r  r  rY   r   )r   r   rk   distributionr  r  rankcrankcxrankcyrankcx_meanrankcy_meanrankxranky
rankx_mean
ranky_meanSxSywbfndf_numerdf_denomri   rn  s                         rP   r;   r;     s   j 	

1  "''0A


1  "''0A	QB	QB	Qw"'"26626622R^^QE*+E1R[Fbe_F''&/K''&/KQKEQKEJJ	+5
BCH	IBq&LB	+5
BCH	IB"q&LB7k/0DRW"r' 1222Ds88BGb2g-s388BGS)R!V4BHHR"Wc*b1f55 OOb)		!""4(46 	6 i		E		#1Q3x  DF 	F tQ''rR   r   )NF)r<   )r<   T)NTN	propagater`   )r`   )TFr  r`   r?  )Ngffffff?separate)Nhierarchical)r<   r`   )r<   Tr`   )T)rb   r`   r  )r`   r  )NTT)Nr  N)Nr  FN)皙?r  N)r  leftr  N)皙?r  rA   rA   TN)r  r  TNr<   )r  r  N)Nr  r<   rA   )Nr<   T)Nr  FNr  r   r   )r<   TT)r<   r<   T))g      ?r  g      ?皙?r  Nrb   )rb   r  r  )r  r  )r<   rA   )r`   rj   )t__doc____all__numpyrf   r=   numpy.marJ   r>   r?   r  r   r\  collectionsr@    rB   scipy._lib._utilrC   rD   scipy._lib._bunchrE   scipy.specialrc   scipy.stats._stats_pyr   r   r   _stats_mstats_commonrF   r&   ru  r%   rw  rQ   rU   r\   rm   r   r   r   r   r   r   r   r   r   r   r$   r  r   r	   rY  r   r   rx  r!   r  r4   r5   r  r6   r  r7   r  r   r  r
   r   r   r   r   r   r-   r.   trimdocr*   r+   r,   trim1r/   r2   r0   r1   r  r(   r8   r)   r'   r3   r:   r   r  r9   r"   r   r:  r   rI  rJ  r#   rX  r   rf  r   r   r   r   r   r   r    r  r   r  r   r  r;   rb   rR   rP   <module>r     s  2    #    "  = /   ) )
 
	,<~* Z1h-P` &78
!.HB$$
i9X ?J%Xv@F ?E&|~=@ ""8 ;E F 0+fOdC?L63r ,,E-:M,JL q<h 24KL 5&p  .0GHK$\ .0GH7$t   4 7A B ,'^ ?,CD:"z  68$$C %$CN 68$%9 %%9P 
 68$P %P*8v@OFD<0 <<<<')DL1: @K'FT 	 AEJ '//'9L @D !)* %--7K @D !(( %--7KK<\*Z0Hf*/Z-'`1'h*$Z ?D$/qDh-(b &* (V2/j*Z9x , /; <
>1B<< ,.EF8-v   46MN D1N 02IJ >B BF~?B50,f 	42j ,.EF#B %%>%<> -F` !!68OP c(rR   