Ë
    £�Dj­'  ã                   óH   — d Z ddlZddlZdd„Zdd„Z G d„ d«      Z	 	 d	d„Zy)
zqAnova k-sample comparison without and with trimming

Created on Sun Jun 09 23:51:34 2013

Author: Josef Perktold
é    Nc                 ó$  — t        j                  | «      } |€| j                  «       } d}| j                  |   }t	        ||z  «      }||z
  }||k\  rt        d«      ‚t        d«      g| j                  z  }t        ||«      ||<   | t        |«         S )a  
    Slices off a proportion of items from both ends of an array.

    Slices off the passed proportion of items from both ends of the passed
    array (i.e., with `proportiontocut` = 0.1, slices leftmost 10% **and**
    rightmost 10% of scores).  You must pre-sort the array if you want
    'proper' trimming.  Slices off less if proportion results in a
    non-integer slice index (i.e., conservatively slices off
    `proportiontocut`).

    Parameters
    ----------
    a : array_like
        Data to trim.
    proportiontocut : float or int
        Proportion of data to trim at each end.
    axis : int or None
        Axis along which the observations are trimmed. The default is to trim
        along axis=0. If axis is None then the array will be flattened before
        trimming.

    Returns
    -------
    out : array-like
        Trimmed version of array `a`.

    Examples
    --------
    >>> from scipy import stats
    >>> a = np.arange(20)
    >>> b = stats.trimboth(a, 0.1)
    >>> b.shape
    (16,)

    Nr   úProportion too big.)	ÚnpÚasarrayÚravelÚshapeÚintÚ
ValueErrorÚsliceÚndimÚtuple)ÚaÚproportiontocutÚaxisÚnobsÚlowercutÚuppercutÚsls          údC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\statsmodels\stats\robust_compare.pyÚtrimbothr      s’   € ôH 	�
‰
�1‹€AØ€|Ø�G‰G‹IˆØˆØ�7‰7�4‰=€DÜ�? TÑ)Ó*€HØ�h‰€HØ�HÒÜÐ.Ó/Ð/ä
�‹+ˆ˜Ÿ™Ñ	€BÜ�X˜xÓ(€B€t�HØŒU�2‹Y‰<Ðó    c                 ót   — t        t        j                  | |«      ||¬«      }t        j                  ||¬«      S )aá  
    Return mean of array after trimming observations from both tails.

    If `proportiontocut` = 0.1, slices off 'leftmost' and 'rightmost' 10% of
    scores. Slices off LESS if proportion results in a non-integer slice
    index (i.e., conservatively slices off `proportiontocut` ).

    Parameters
    ----------
    a : array_like
        Input array
    proportiontocut : float
        Fraction to cut off at each tail of the sorted observations.
    axis : int or None
        Axis along which the trimmed means are computed. The default is axis=0.
        If axis is None then the trimmed mean will be computed for the
        flattened array.

    Returns
    -------
    trim_mean : ndarray
        Mean of trimmed array.

    ©r   )r   r   ÚsortÚmean)r   r   r   Únewas       r   Ú	trim_meanr   B   s.   € ô2 ”B—G‘G˜A˜tÓ$ o¸DÔA€DÜ�7‰7�4˜dÔ#Ð#r   c                   óš   — e Zd ZdZdd„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zed	„ «       Z	 	 dd
„Zd„ Zy)ÚTrimmedMeanaŸ  
    class for trimmed and winsorized one sample statistics

    axis is None, i.e. ravelling, is not supported

    Parameters
    ----------
    data : array-like
        The data, observations to analyze.
    fraction : float in (0, 0.5)
        The fraction of observations to trim at each tail.
        The number of observations trimmed at each tail is
        ``int(fraction * nobs)``
    is_sorted : boolean
        Indicator if data is already sorted. By default the data is sorted
        along ``axis``.
    axis : int
        The axis of reduce operations. By default axis=0, that is observations
        are along the zero dimension, i.e. rows if 2-dim.
    c                 ó  — t        j                  |«      | _        || _        || _        | j                  j
                  |   x| _        }t        ||z  «      x| _        }||z
  x| _	        }||k\  rt        d«      ‚|d|z  z
  | _        t        d «      g| j                  j                  z  | _        t        | j                  | j                  «      | j                  |<   t        | j                  «      | _        |s't        j                   | j                  |¬«      | _        n| j                  | _        t        j$                  | j"                  ||¬«      | _        t        j$                  | j"                  |dz
  |¬«      | _        y )Nr   é   r   é   )r   r   Údatar   Úfractionr   r   r	   r   r   r
   Únobs_reducedr   r   r   r   r   Údata_sortedÚtakeÚ
lowerboundÚ
upperbound)Úselfr#   r$   Ú	is_sortedr   r   r   r   s           r   Ú__init__zTrimmedMean.__init__u   s*  € Ü—J‘J˜tÓ$ˆŒ	ð ˆŒ	Ø ˆŒØŸ9™9Ÿ?™?¨4Ñ0Ð0ˆŒ	�DÜ#& x°$¡Ó#7Ð7ˆŒ˜Ø#'¨(¡?Ð2ˆŒ˜Ø˜Ò ÜÐ2Ó3Ð3Ø  1 x¡<Ñ/ˆÔä˜“;�- $§)¡)§.¡.Ñ0ˆŒÜ˜dŸm™m¨T¯]©]Ó;ˆ�‰�‰ä˜Ÿ™“.ˆŒÙÜ!Ÿw™w t§y¡y°tÔ<ˆDÕà#Ÿy™yˆDÔô Ÿ'™' $×"2Ñ"2°HÀ4ÔHˆŒÜŸ'™' $×"2Ñ"2°H¸q±LÀtÔLˆ�r   c                 ó4   — | j                   | j                     S )z/numpy array of trimmed and sorted data
        )r&   r   ©r*   s    r   Údata_trimmedzTrimmedMean.data_trimmed‘   s   € ð
 ×Ñ §¡Ñ(Ð(r   c                 óì   — t        j                  | j                  | j                  «      }t        j                  | j                  | j                  «      }t        j
                  | j                  ||«      S )zwinsorized data
        )r   Úexpand_dimsr(   r   r)   Úclipr&   )r*   ÚlbÚubs      r   Údata_winsorizedzTrimmedMean.data_winsorized˜   sM   € ô �^‰^˜DŸO™O¨T¯Y©YÓ7ˆÜ�^‰^˜DŸO™O¨T¯Y©YÓ7ˆÜ�w‰w�t×'Ñ'¨¨RÓ0Ð0r   c                 ó‚   — t        j                  | j                  t        | j                  «         | j
                  «      S )zmean of trimmed data
        )r   r   r&   r   r   r   r.   s    r   Úmean_trimmedzTrimmedMean.mean_trimmed    s,   € ô �w‰w�t×'Ñ'¬¨d¯g©g«Ñ7¸¿¹ÓCÐCr   c                 óV   — t        j                  | j                  | j                  «      S )z mean of winsorized data
        )r   r   r5   r   r.   s    r   Úmean_winsorizedzTrimmedMean.mean_winsorized¦   s   € ô �w‰w�t×+Ñ+¨T¯Y©YÓ7Ð7r   c                 óZ   — t        j                  | j                  d| j                  ¬«      S )z$variance of winsorized data
        r"   )Úddofr   )r   Úvarr5   r   r.   s    r   Úvar_winsorizedzTrimmedMean.var_winsorized¬   s!   € ô
 �v‰v�d×*Ñ*°¸¿¹ÔCÐCr   c                 ó¼   — t        j                  | j                  | j                  z  «      }|t        j                  | j                  | j                  z  «      z  }|S )z'standard error of trimmed mean
        )r   Úsqrtr=   r%   r   )r*   Úses     r   Ústd_mean_trimmedzTrimmedMean.std_mean_trimmed³   sL   € ô �W‰W�T×(Ñ(¨4×+<Ñ+<Ñ<Ó=ˆð 	Œb�g‰g�d—i‘i $×"3Ñ"3Ñ3Ó4Ñ4ˆØˆ	r   c                 ó¢   — t        j                  | j                  | j                  z  «      }|| j                  dz
  | j                  dz
  z  z  }|S )z*standard error of winsorized mean
        r"   )r   r?   r=   r   r%   )r*   Ústd_s     r   Ústd_mean_winsorizedzTrimmedMean.std_mean_winsorized¾   sJ   € ô
 �w‰w�t×*Ñ*¨T¯Y©YÑ6Ó7ˆØ�—‘˜Q‘ 4×#4Ñ#4°qÑ#8Ñ9Ñ9ˆð ˆr   c                 óú   — ddl mc m} | j                  dz
  }|dk(  r| j                  }| j
                  }n)|dk(  r| j                  }| j                  }nt        d«      ‚|j                  |d||||¬«      }||fz   S )aF  
        One sample t-test for trimmed or Winsorized mean

        Parameters
        ----------
        value : float
            Value of the mean under the Null hypothesis
        transform : {'trimmed', 'winsorized'}
            Specified whether the mean test is based on trimmed or winsorized
            data.
        alternative : {'two-sided', 'larger', 'smaller'}


        Notes
        -----
        p-value is based on the approximate t-distribution of the test
        statistic. The approximation is valid if the underlying distribution
        is symmetric.
        r   Nr"   ÚtrimmedÚ
winsorizedz/transform can only be 'trimmed' or 'winsorized')ÚalternativeÚdiff)
Ústatsmodels.stats.weightstatsÚstatsÚweightstatsr%   r7   rA   r9   rD   r
   Ú_tstat_generic)	r*   ÚvalueÚ	transformrH   ÚsmwsÚdfÚmean_rC   Úress	            r   Ú
ttest_meanzTrimmedMean.ttest_meanÌ   s‘   € ÷* 	5Ð4Ø×Ñ Ñ"ˆØ˜	Ò!Ø×%Ñ%ˆEØ×(Ñ(‰DØ˜,Ò&Ø×(Ñ(ˆEØ×+Ñ+‰DäÐNÓOÐOà×!Ñ! %¨¨DØ"$°+ÀEð "ó Kˆà�b�U‰{Ðr   c                 ón   — t        | j                  |d| j                  ¬«      }| j                  |_        |S )z„create a TrimmedMean instance with a new trimming fraction

        This reuses the sorted array from the current instance.
        T)r+   r   )r   r&   r   r#   )r*   ÚfracÚtms      r   Úreset_fractionzTrimmedMean.reset_fractionð   s3   € ô
 ˜×)Ñ)¨4¸4Ø"Ÿi™iô)ˆà—)‘)ˆŒð ˆ	r   N)Fr   )r   rF   z	two-sided)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   Úpropertyr/   r5   r7   r9   r=   rA   rD   rT   rX   © r   r   r   r   _   s°   „ ñó*Mð8 ñ)ó ð)ð ñ1ó ð1ð ñDó ðDð
 ñ8ó ð8ð
 ñDó ðDð ñó ðð ñó ðð -6Ø*ó"óHr   r   c           	      óf  — t        j                  | «      }|dk(  rt         j                  }n+|dk(  rd„ }n"|dk(  rd„ }nt        |«      r|}nt	        d«      ‚|dk(  r6 ||t        j
                  t        j                  ||¬«      |«      z
  «      }|S |d	k(  r6 ||t        j
                  t        j                  ||¬«      |«      z
  «      }|S |d
k(  r/t        |||¬«      } ||t        j
                  ||«      z
  «      }|S t        |t        j                  «      r |||z
  «      }|S t	        d«      ‚)a  Transform data for variance comparison for Levene type tests

    Parameters
    ----------
    data : array_like
        Observations for the data.
    center : "median", "mean", "trimmed" or float
        Statistic used for centering observations. If a float, then this
        value is used to center. Default is median.
    transform : 'abs', 'square', 'identity' or a callable
        The transform for the centered data.
    trim_frac : float in [0, 0.5)
        Fraction of observations that are trimmed on each side of the sorted
        observations. This is only used if center is `trimmed`.
    axis : int
        Axis along which the data are transformed when centering.

    Returns
    -------
    res : ndarray
        transformed data in the same shape as the original data.

    ÚabsÚsquarec                 ó   — | | z  S ©Nr^   ©Úxs    r   ú<lambda>z!scale_transform.<locals>.<lambda>  s
   € ˜!˜a™%€ r   Úidentityc                 ó   — | S rc   r^   rd   s    r   rf   z!scale_transform.<locals>.<lambda>  s   € ˜!€ r   z&transform should be abs, square or expÚmedianr   r   rF   z(center should be median, mean or trimmed)r   r   r`   Úcallabler
   r1   ri   r   r   Ú
isinstanceÚnumbersÚNumber)r#   ÚcenterrO   Ú	trim_fracr   re   ÚtfuncrS   s           r   Úscale_transformrq   þ   s,  € ô2 	�
‰
�4Ó€Aà�EÒÜ—‘‰Ø	�hÒ	Ù‰Ø	�jÒ	 Ù‰Ü	�)Ô	Ø‰äÐAÓBÐBà�ÒÙ�AœŸ™¤r§y¡y°¸Ô'>ÀÓEÑEÓFˆð €Jð 
�6Ò	Ù�AœŸ™¤r§w¡w¨q°tÔ'<¸dÓCÑCÓDˆð €Jð 
�9Ò	Ü˜1˜i¨dÔ3ˆÙ�AœŸ™ v¨tÓ4Ñ4Ó5ˆð €Jô 
�FœGŸN™NÔ	+Ù�A˜‘JÓˆð €Jô ÐCÓDÐDr   )r   )ri   r`   gš™™™™™É?r   )r\   rl   Únumpyr   r   r   r   rq   r^   r   r   ú<module>rs      s9   ðñó Û ó0óf$÷:\ñ \ð~ GJØô2r   