
&]\c        >   @` sD  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z d d l	 Z
 d d l	 m Z m Z m Z d d l m Z m Z d d l m Z d d l m Z d d l j Z d	 d
 l m Z d	 d l m Z d	 d l m Z m Z m Z m Z d	 d l m  Z  m! Z! m" Z" d	 d l# m$ Z$ d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL g> Z% dM   Z& dN   Z' dO dP  Z( d d dQ  Z* d d dR  Z+ e dS d  Z, d dO dU  Z- dV   Z. d e/ e/ f d dW  Z0 d e/ e/ f d d	 dX  Z1 d d e/ dO dY  Z2 d d e/ dO dZ  Z3 d e/ e/ f d d	 d[  Z4 d e/ e/ f d d	 d\  Z5 d	 d dO d]  Z6 d^   Z7 d dO d_  Z8 d e/ dO d`  Z9 d e/ e/ dO da  Z: e db d  Z; d d	 e/ dO dh  Z< e di d  Z= d dO dl  Z> e dm d  Z? d dO dn  Z@ e do d  ZA d dO dp  ZB dq   ZC e
 jD dr ds  dt    ZE d du d dv  ZF dw   ZG dx dy  ZH e dz d  ZI d~ d d eJ d  ZK e d d  ZL d~ d d d  ZM e d d  ZN d~ d d d  ZO d   ZP d d	 dO d  ZQ d d d  ZR d d d  ZS i d d 6e jT d  d e jU d  d 6ZV d d d dO d eJ d  ZW d d eJ eJ d  ZX d d eJ eJ d  ZY e d d  ZZ d d d  Z[ d d  Z\ d d d  Z] d d  Z^ e d d  Z_ d   Z` d   Za d d  Zb e d d  Zc d d dO d  Zd e d d  Ze d   Zf e d d  Zg d dO d d  Zh e d d  Zi e/ d e/ d  Zj e d d  Zk d dO d  Zl d   Zm d   Zn d   Zo d   Zp e d d  Zq e/ d  Zr d e/ dO d  Zs e d d  Zt d dO d  Zu e d d  Zv d d d d d  Zw i d	 d 6d d 6d d 6d d 6d d 6d d 6Zx d d  Zy e d d  Zz d d d d d  Z{ d d d d  Z| e d d  Z} d   Z~ d   Z e d d  Z e/ d d  Z e d d Z d   Z e d d Z d   Z e d d Z d   Z e d d Z d d dO d  Z d d d  Z d d d  Z d d d  Z d d d  Z d   Z e d d Z d   Z d d  Z d d  Z d d  Z d S(  s	  
A collection of basic statistical functions for Python.  The function
names appear below.

 Some scalar functions defined here are also available in the scipy.special
 package where they work on arbitrary sized arrays.

Disclaimers:  The function list is obviously incomplete and, worse, the
functions are not optimized.  All functions have been tested (some more
so than others), but they are far from bulletproof.  Thus, as with any
free software, no warranty or guarantee is expressed or implied. :-)  A
few extra functions that don't appear in the list below can be found by
interested treasure-hunters.  These functions don't necessarily have
both list and array versions but were deemed useful.

Central Tendency
----------------
.. autosummary::
   :toctree: generated/

    gmean
    hmean
    mode

Moments
-------
.. autosummary::
   :toctree: generated/

    moment
    variation
    skew
    kurtosis
    normaltest

Altered Versions
----------------
.. autosummary::
   :toctree: generated/

    tmean
    tvar
    tstd
    tsem
    describe

Frequency Stats
---------------
.. autosummary::
   :toctree: generated/

    itemfreq
    scoreatpercentile
    percentileofscore
    cumfreq
    relfreq

Variability
-----------
.. autosummary::
   :toctree: generated/

    obrientransform
    sem
    zmap
    zscore
    iqr

Trimming Functions
------------------
.. autosummary::
   :toctree: generated/

   trimboth
   trim1

Correlation Functions
---------------------
.. autosummary::
   :toctree: generated/

   pearsonr
   fisher_exact
   spearmanr
   pointbiserialr
   kendalltau
   weightedtau
   linregress
   theilslopes

Inferential Stats
-----------------
.. autosummary::
   :toctree: generated/

   ttest_1samp
   ttest_ind
   ttest_ind_from_stats
   ttest_rel
   chisquare
   power_divergence
   ks_2samp
   mannwhitneyu
   ranksums
   wilcoxon
   kruskal
   friedmanchisquare
   brunnermunzel
   combine_pvalues

Statistical Distances
---------------------
.. autosummary::
   :toctree: generated/

   wasserstein_distance
   energy_distance

ANOVA Functions
---------------
.. autosummary::
   :toctree: generated/

   f_oneway

Support Functions
-----------------
.. autosummary::
   :toctree: generated/

   rankdata
   rvs_ratio_uniforms

References
----------
.. [CRCProbStat2000] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
   Probability and Statistics Tables and Formulae. Chapman & Hall: New
   York. 2000.

i    (   t   divisiont   print_functiont   absolute_importN(   t
   namedtuple(   t   arrayt   asarrayt   ma(   t   callablet   string_types(   t   NumpyVersion(   t
   _lazywherei   (   t   distributions(   t   mstats_basic(   t   _find_repeatst
   linregresst   theilslopest   siegelslopes(   t   _kendall_dist   _toint64t   _weightedrankedtau(   t   rvs_ratio_uniformst   find_repeatst   gmeant   hmeant   modet   tmeant   tvart   tmint   tmaxt   tstdt   tsemt   momentt	   variationt   skewt   kurtosist   describet   skewtestt   kurtosistestt
   normaltestt   jarque_berat   itemfreqt   scoreatpercentilet   percentileofscoret   cumfreqt   relfreqt   obrientransformt   semt   zmapt   zscoret   iqrt	   sigmaclipt   trimbotht   trim1t	   trim_meant   f_onewayt   pearsonrt   fisher_exactt	   spearmanrt   pointbiserialrt
   kendalltaut   weightedtauR   R   R   t   ttest_1sampt	   ttest_indt   ttest_ind_from_statst	   ttest_relt   kstestt	   chisquaret   power_divergencet   ks_2sampt   mannwhitneyut
   tiecorrectt   ranksumst   kruskalt   friedmanchisquaret   rankdataR   t   combine_pvaluest   wasserstein_distancet   energy_distancet   brunnermunzelc         C` sd   | d  k r$ t j |   }  d } n t j |   }  | } |  j d k rZ t j |   }  n  |  | f S(   Ni    (   t   Nonet   npt   ravelR   t   ndimt
   atleast_1d(   t   at   axist   outaxis(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _chk_asarray   s    	c         C` s   | d  k r3 t j |   }  t j |  } d } n$ t j |   }  t j |  } | } |  j d k rx t j |   }  n  | j d k r t j |  } n  |  | | f S(   Ni    (   RO   RP   RQ   R   RR   RS   (   RT   t   bRU   RV   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _chk2_asarray   s    	t	   propagatec         C` s   d d d g } | | k rA t  d d j d   | D    n  y5 t j d d   t j t j |    } Wd  QXWn- t k
 r t } d } t j	 d	 t
  n X| r | d k r t  d
   n  | | f S(   NRZ   t   raiset   omits   nan_policy must be one of {%s}s   , c         s` s   |  ] } d  | Vq d S(   s   '%s'N(    (   t   .0t   s(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pys	   <genexpr>   s    t   invalidt   ignoresY   The input array could not be properly checked for nan values. nan values will be ignored.s   The input contains nan values(   t
   ValueErrort   joinRP   t   errstatet   isnant   sumt	   TypeErrort   Falset   warningst   warnt   RuntimeWarning(   RT   t
   nan_policyt   policiest   contains_nan(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _contains_nan   s     "	c         C` s   t  |  t j  s3 t j t j |  d |  } no | r t  |  t j j  rr t j t j j |  d |  } q t j t j |  d |  } n t j |   } t j | j	 d |   S(   sA  
    Compute the geometric mean along the specified axis.

    Return the geometric average of the array elements.
    That is:  n-th root of (x1 * x2 * ... * xn)

    Parameters
    ----------
    a : array_like
        Input array or object that can be converted to an array.
    axis : int or None, optional
        Axis along which the geometric mean is computed. Default is 0.
        If None, compute over the whole array `a`.
    dtype : dtype, optional
        Type of the returned array and of the accumulator in which the
        elements are summed. If dtype is not specified, it defaults to the
        dtype of a, unless a has an integer dtype with a precision less than
        that of the default platform integer. In that case, the default
        platform integer is used.

    Returns
    -------
    gmean : ndarray
        see dtype parameter above

    See Also
    --------
    numpy.mean : Arithmetic average
    numpy.average : Weighted average
    hmean : Harmonic mean

    Notes
    -----
    The geometric average is computed over a single dimension of the input
    array, axis=0 by default, or all values in the array if axis=None.
    float64 intermediate and return values are used for integer inputs.

    Use masked arrays to ignore any non-finite values in the input or that
    arise in the calculations such as Not a Number and infinity because masked
    arrays automatically mask any non-finite values.

    Examples
    --------
    >>> from scipy.stats import gmean
    >>> gmean([1, 4])
    2.0
    >>> gmean([1, 2, 3, 4, 5, 6, 7])
    3.3800151591412964
    t   dtypeRU   (
   t
   isinstanceRP   t   ndarrayt   logR   R   t   MaskedArrayR   t   expt   mean(   RT   RU   Ro   t   log_a(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR      s    2!$!c         C` s   t  |  t j  s* t j |  d | }  n  t j |  d k  r t  |  t j j  rf |  j |  } n5 | d k r |  j	   }  |  j
 d } n |  j
 | } | t j d |  d | d | St d   d S(   s  
    Calculate the harmonic mean along the specified axis.

    That is:  n / (1/x1 + 1/x2 + ... + 1/xn)

    Parameters
    ----------
    a : array_like
        Input array, masked array or object that can be converted to an array.
    axis : int or None, optional
        Axis along which the harmonic mean is computed. Default is 0.
        If None, compute over the whole array `a`.
    dtype : dtype, optional
        Type of the returned array and of the accumulator in which the
        elements are summed. If `dtype` is not specified, it defaults to the
        dtype of `a`, unless `a` has an integer `dtype` with a precision less
        than that of the default platform integer. In that case, the default
        platform integer is used.

    Returns
    -------
    hmean : ndarray
        see `dtype` parameter above

    See Also
    --------
    numpy.mean : Arithmetic average
    numpy.average : Weighted average
    gmean : Geometric mean

    Notes
    -----
    The harmonic mean is computed over a single dimension of the input
    array, axis=0 by default, or all values in the array if axis=None.
    float64 intermediate and return values are used for integer inputs.

    Use masked arrays to ignore any non-finite values in the input or that
    arise in the calculations such as Not a Number and infinity.

    Examples
    --------
    >>> from scipy.stats import hmean
    >>> hmean([1, 4])
    1.6000000000000001
    >>> hmean([1, 2, 3, 4, 5, 6, 7])
    2.6997245179063363
    Ro   i    g      ?RU   s<   Harmonic mean only defined if all elements greater than zeroN(   Rp   RP   Rq   R   t   allR   Rs   t   countRO   RQ   t   shapeRe   Ra   (   RT   RU   Ro   t   size(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR   @  s    0!t
   ModeResultRx   c         C` s  t  |  |  \ }  } |  j d k rC t t j g   t j g    St |  |  \ } } | r | d k r t j |   }  t j	 |  |  St
 t j  d k  s |  j t k rt j t |   k rt t j |    } t |  j  } d | | <t j | d |  j } t j | d t } xk | D]c } |  | k }	 t j t j |	 |  |  }
 t j |
 | k | |  } t j |
 |  } | } q$Wt | |  Sd   } t t |  j   } t j |  | |  | | d | g  } t j | j d   } t j | j d  d |  j } t j | j d  d t j }
 x, | D]$ } | | |  \ | | <|
 | <q:Wt |  j  } d | | <t | j |  |
 j |   S(   s  
    Return an array of the modal (most common) value in the passed array.

    If there is more than one such value, only the smallest is returned.
    The bin-count for the modal bins is also returned.

    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`.
    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'.

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

    Examples
    --------
    >>> a = np.array([[6, 8, 3, 0],
    ...               [3, 2, 1, 7],
    ...               [8, 1, 8, 4],
    ...               [5, 3, 0, 5],
    ...               [4, 7, 5, 9]])
    >>> from scipy import stats
    >>> stats.mode(a)
    (array([[3, 1, 0, 0]]), array([[1, 1, 1, 1]]))

    To get mode of whole array, specify ``axis=None``:

    >>> stats.mode(a, axis=None)
    (array([3]), array([3]))

    i    R\   s   1.9.0i   Ro   c         S` s5   t  j |  d t \ } } | | j   | j   f S(   Nt   return_counts(   RP   t   uniquet   Truet   argmaxt   max(   RT   t   valst   cnts(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _mode1D  s    i(   RW   Rz   R{   RP   R   Rn   R   t   masked_invalidR   R   R	   t   __version__Ro   t   objectt   nant   setRQ   t   listRy   t   zerost   intt   expand_dimsRe   t   wheret   maximumt   rangeRR   t	   transposet   ndindext   emptyt   reshape(   RT   RU   Rk   Rm   t   scorest	   testshapet   oldmostfreqt	   oldcountst   scoret   templatet   countst   mostfrequentR   t   in_dimst   a_viewt   indst   modest   indt   newshape(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR     s>    +9

	)"
c         C` s   | \ } } | \ } } t  j |   } | d k	 rc | rN t  j | |  } qc t  j | |  } n  | d k	 r | r t  j | |  } q t  j | |  } n  | j   d k r t d   n  | S(   s  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.
    i    s#   No array values within given limitsN(	   R   Rs   RO   t   masked_lesst   masked_less_equalt   masked_greatert   masked_greater_equalRx   Ra   (   RT   t   limitst	   inclusivet   lower_limitt   upper_limitt   lower_includet   upper_includet   am(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _mask_to_limits  s    c         C` sP   t  |   }  | d k r( t j |  d  St |  j   | |  } | j d |  S(   s  
    Compute the trimmed mean.

    This function finds the arithmetic mean of 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 (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 compute test. Default is None.

    Returns
    -------
    tmean : float

    See also
    --------
    trim_mean : returns mean after trimming a proportion from both tails.

    Examples
    --------
    >>> from scipy import stats
    >>> x = np.arange(20)
    >>> stats.tmean(x)
    9.5
    >>> stats.tmean(x, (3,17))
    10.0

    RU   N(   R   RO   RP   Ru   R   RQ   (   RT   R   R   RU   R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR     s
    )c         C` s}   t  |   }  |  j t  j   }  | d k rO t |   } |  j   | | d St |  | |  } t j	 j | d | d | S(   s  
    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. Default is 0. If None, compute over the
        whole array `a`.
    ddof : int, optional
        Delta degrees of freedom.  Default is 1.

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

    Notes
    -----
    `tvar` computes the unbiased sample variance, i.e. it uses a correction
    factor ``n / (n - 1)``.

    Examples
    --------
    >>> from scipy import stats
    >>> x = np.arange(20)
    >>> stats.tvar(x)
    35.0
    >>> stats.tvar(x, (3,17))
    20.0

    g      ?t   ddofRU   N(
   R   t   astypet   floatRQ   RO   t   lent   varR   RP   R   (   RT   R   R   RU   R   t   nR   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR   >  s    .c         C` s   t  |  |  \ }  } t |  | d f | t f  } t | |  \ } } | rl | d k rl t j |  } n  t j j | |  j	 } | j
 d k r | d S| S(   s  
    Compute the trimmed minimum.

    This function finds the miminum value of an array `a` along the
    specified axis, but only considering values greater than a specified
    lower limit.

    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.
    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'.

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

    Examples
    --------
    >>> from scipy import stats
    >>> x = np.arange(20)
    >>> stats.tmin(x)
    0

    >>> stats.tmin(x, 13)
    13

    >>> stats.tmin(x, 13, inclusive=False)
    14

    R\   i    N(    (   RW   R   RO   Rg   Rn   R   R   t   minimumt   reducet   dataRR   (   RT   t
   lowerlimitRU   R   Rk   R   Rm   t   res(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR   u  s    -c         C` s   t  |  |  \ }  } t |  d | f t | f  } t | |  \ } } | rl | d k rl t j |  } n  t j j | |  j	 } | j
 d k r | d S| S(   s  
    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.
    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'.

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

    Examples
    --------
    >>> from scipy import stats
    >>> x = np.arange(20)
    >>> stats.tmax(x)
    19

    >>> stats.tmax(x, 13)
    13

    >>> stats.tmax(x, 13, inclusive=False)
    12

    R\   i    N(    (   RW   R   RO   Rg   Rn   R   R   R   R   R   RR   (   RT   t
   upperlimitRU   R   Rk   R   Rm   R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR     s    ,c         C` s   t  j t |  | | | |   S(   s  
    Compute the trimmed sample standard deviation.

    This function finds the sample standard deviation of 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. Default is 0. If None, compute over the
        whole array `a`.
    ddof : int, optional
        Delta degrees of freedom.  Default is 1.

    Returns
    -------
    tstd : float

    Notes
    -----
    `tstd` computes the unbiased sample standard deviation, i.e. it uses a
    correction factor ``n / (n - 1)``.

    Examples
    --------
    >>> from scipy import stats
    >>> x = np.arange(20)
    >>> stats.tstd(x)
    5.9160797830996161
    >>> stats.tstd(x, (3,17))
    4.4721359549995796

    (   RP   t   sqrtR   (   RT   R   R   RU   R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR     s    -c         C` s   t  j |   j   }  | d k rA |  j d |  t  j |  j  St |  | |  } t  j t  j j	 | d | d |  } | t  j | j
    S(   s  
    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. Default is 0. If None, compute over the
        whole array `a`.
    ddof : int, optional
        Delta degrees of freedom.  Default is 1.

    Returns
    -------
    tsem : float

    Notes
    -----
    `tsem` uses unbiased sample standard deviation, i.e. it uses a
    correction factor ``n / (n - 1)``.

    Examples
    --------
    >>> from scipy import stats
    >>> x = np.arange(20)
    >>> stats.tsem(x)
    1.3228756555322954
    >>> stats.tsem(x, (3,17))
    1.1547005383792515

    R   RU   N(   RP   R   RQ   RO   t   stdR   Rz   R   R   R   Rx   (   RT   R   R   RU   R   R   t   sd(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR     s    - 'c         C` s  t  |  |  \ }  } t |  |  \ } } | r^ | d k r^ t j |   }  t j |  | |  S|  j d k r t j |  r t j	 St j
 t j |  j t j	 d t j Sn  t j |  s g  | D] } t |  | |  ^ q } t j |  St |  | |  Sd S(   s  
    Calculate the nth moment about the mean for a sample.

    A moment is a specific quantitative measure of the shape of a set of
    points. It is often used to calculate coefficients of skewness and kurtosis
    due to its close relationship with them.


    Parameters
    ----------
    a : array_like
       data
    moment : int or array_like of ints, optional
       order of central moment that is returned. Default is 1.
    axis : int or None, optional
       Axis along which the central moment is computed. Default is 0.
       If None, compute over the whole array `a`.
    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'.

    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.

    See also
    --------
    kurtosis, skew, describe

    Notes
    -----
    The k-th central moment of a data sample is:

    .. math::

        m_k = \frac{1}{n} \sum_{i = 1}^n (x_i - \bar{x})^k

    Where n is the number of samples and x-bar is the mean. This function uses
    exponentiation by squares [1]_ for efficiency.

    References
    ----------
    .. [1] https://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms

    Examples
    --------
    >>> from scipy.stats import moment
    >>> moment([1, 2, 3, 4, 5], moment=1)
    0.0
    >>> moment([1, 2, 3, 4, 5], moment=2)
    2.0
    R\   i    Ro   N(   RW   Rn   R   R   R   R   Rz   RP   t   isscalarR   t   fullR   Ry   t   float64t   _momentR   (   RT   R   RU   Rk   Rm   t   it   mmnt(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR   T  s    9+%c   	      C` s  t  j | t  j |   d k r1 t d   n  | d k rs t |  j  } | | =| rl t  j | d t Sd Sn9| d k r t |  j  } | | =| r t  j | d t St  j	 d  Sn | g } | } xB | d k r| d r | d d } n
 | d } | j
 |  q W|  t  j t  j |  |  |  } | d d k rS| j   } n
 | d } x< | d	 d  d  D]' } | d } | d rq| | 9} qqqqWt  j | |  Sd  S(
   Ni    s&   All moment parameters must be integersRo   g      ?i   g        i   ii(   RP   t   abst   roundRa   R   Ry   t   onesR   R   R   t   appendR   Ru   t   copy(	   RT   R   RU   Ry   t   n_listt	   current_nt   a_zero_meanR^   R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR     s<    "	

"


c         C` su   t  |  |  \ }  } t |  |  \ } } | r[ | d k r[ t j |   }  t j |  |  S|  j |  |  j |  S(   s  
    Compute the coefficient of variation, the ratio of the biased standard
    deviation to the mean.

    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`.
    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'.

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

    References
    ----------
    .. [1] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
       Probability and Statistics Tables and Formulae. Chapman & Hall: New
       York. 2000.

    Examples
    --------
    >>> from scipy.stats import variation
    >>> variation([1, 2, 3, 4, 5])
    0.47140452079103173
    R\   (   RW   Rn   R   R   R   R    R   Ru   (   RT   RU   Rk   Rm   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR      s    "c         C` sg  t  |  |  \ }  } |  j | } t |  |  \ } } | rk | d k rk t j |   }  t j |  | |  St |  d |  } t |  d |  } | d k } t | | | f d   d  }	 | sJ| d k | d k @}
 |
 j	   rJt
 j |
 |  } t
 j |
 |  } t
 j | d |  | d | | d	 } t
 j |	 |
 |  qJn  |	 j d k rc|	 j   S|	 S(
   s  
    Compute the skewness of a data set.

    For normally distributed data, the skewness should be about 0. For
    unimodal continuous distributions, a skewness value > 0 means that
    there is more weight in the right tail of the distribution. The
    function `skewtest` can be used to determine if the skewness value
    is close enough to 0, statistically speaking.

    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.
    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'.

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

    References
    ----------

    .. [1] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
       Probability and Statistics Tables and Formulae. Chapman & Hall: New
       York. 2000.
       Section 2.2.24.1

    Examples
    --------
    >>> from scipy.stats import skew
    >>> skew([1, 2, 3, 4, 5])
    0.0
    >>> skew([2, 8, 0, 4, 1, 9, 9, 0])
    0.2650554122698573
    R\   i   i   i    c         S` s   | |  d S(   Ng      ?(    (   t   m2t   m3(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   <lambda>?  s    g        g      ?g       @g      ?(   RW   Ry   Rn   R   R   R   R!   R   R
   t   anyRP   t   extractR   t   placeRR   t   item(   RT   RU   t   biasRk   R   Rm   R   R   t   zeroR   t   can_correctt   nval(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR!     s,    .	+
c         C` s  t  |  |  \ }  } t |  |  \ } } | ra | d k ra t j |   }  t j |  | | |  S|  j | } t |  d |  } t |  d |  } | d k }	 t j	 d d  }
 z! t j
 |	 d | | d  } Wd t j	 |
   X| s| d	 k | d k @} | j   rt j | |  } t j | |  } d
 | d | d	 | d d
 | | d d	 | d d } t j | | | d  qn  | j d k r| j   } n  | r| d	 S| S(   s  
    Compute 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.
    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'.

    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.

    References
    ----------
    .. [1] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
       Probability and Statistics Tables and Formulae. Chapman & Hall: New
       York. 2000.

    Examples
    --------
    >>> from scipy.stats import kurtosis
    >>> kurtosis([1, 2, 3, 4, 5])
    -1.3
    R\   i   i   i    Rw   R`   g       @Ni   g      ?i   g      @(   RW   Rn   R   R   R   R"   Ry   R   RP   t   seterrR   R   R   R   RR   R   (   RT   RU   t   fisherR   Rk   Rm   R   R   t   m4R   t   olderrR   R   R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR"   O  s.    0!>t   DescribeResultt   nobst   minmaxRu   t   variancet   skewnessc         C` s)  t  |  |  \ }  } t |  |  \ } } | ra | d k ra t j |   }  t j |  | | |  S|  j d k r t d   n  |  j | } t	 j
 |  d | t	 j |  d | f } t	 j |  d | } t	 j |  d | d | }	 t |  | d | }
 t |  | d | } t | | | |	 |
 |  S(   s  
    Compute several descriptive statistics of the passed array.

    Parameters
    ----------
    a : array_like
       Input data.
    axis : int or None, optional
       Axis along which statistics are calculated. Default is 0.
       If None, compute over the whole array `a`.
    ddof : int, optional
        Delta degrees of freedom (only for variance).  Default is 1.
    bias : bool, optional
        If False, then the skewness and kurtosis calculations are corrected for
        statistical bias.
    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'.

    Returns
    -------
    nobs : int or ndarray of ints
       Number of observations (length of data along `axis`).
       When 'omit' is chosen as nan_policy, each column is counted separately.
    minmax: tuple of ndarrays or floats
       Minimum and maximum value of data array.
    mean : ndarray or float
       Arithmetic mean of data along axis.
    variance : ndarray or float
       Unbiased variance of the data along axis, denominator is number of
       observations minus one.
    skewness : ndarray or float
       Skewness, based on moment calculations with denominator equal to
       the number of observations, i.e. no degrees of freedom correction.
    kurtosis : ndarray or float
       Kurtosis (Fisher).  The kurtosis is normalized so that it is
       zero for the normal distribution.  No degrees of freedom are used.

    See Also
    --------
    skew, kurtosis

    Examples
    --------
    >>> from scipy import stats
    >>> a = np.arange(10)
    >>> stats.describe(a)
    DescribeResult(nobs=10, minmax=(0, 9), mean=4.5, variance=9.166666666666666,
                   skewness=0.0, kurtosis=-1.2242424242424244)
    >>> b = [[1, 2], [3, 4]]
    >>> stats.describe(b)
    DescribeResult(nobs=2, minmax=(array([1, 2]), array([3, 4])),
                   mean=array([2., 3.]), variance=array([2., 2.]),
                   skewness=array([0., 0.]), kurtosis=array([-2., -2.]))

    R\   i    s   The input must not be empty.RU   R   R   (   RW   Rn   R   R   R   R#   Rz   Ra   Ry   RP   t   minR   Ru   R   R!   R"   R   (   RT   RU   R   R   Rk   Rm   R   t   mmt   mt   vt   skt   kurt(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR#     s    :*t   SkewtestResultt	   statistict   pvaluec         C` s  t  |  |  \ }  } t |  |  \ } } | r[ | d k r[ t j |   }  t j |  |  S| d k r t j |   }  d } n  t	 |  |  } |  j
 | } | d k  r t d t |    n  | t j | d | d d | d  } d	 | d d
 | d | d | d | d | d | d | d } d t j d | d  } d t j d t j |   }	 t j d | d  }
 t j | d k d |  } |	 t j | |
 t j | |
 d d   } t | d t j j t j |    S(   s  
    Test whether the skew is different from the normal distribution.

    This function tests the null hypothesis that the skewness of
    the population that the sample was drawn from is the same
    as that of a corresponding normal distribution.

    Parameters
    ----------
    a : array
        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`.
    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'.

    Returns
    -------
    statistic : float
        The computed z-score for this test.
    pvalue : float
        a 2-sided p-value for the hypothesis test

    Notes
    -----
    The sample size must be at least 8.

    References
    ----------
    .. [1] R. B. D'Agostino, A. J. Belanger and R. B. D'Agostino Jr.,
            "A suggestion for using powerful and informative tests of
            normality", American Statistician 44, pp. 316-321, 1990.

    Examples
    --------
    >>> from scipy.stats import skewtest
    >>> skewtest([1, 2, 3, 4, 5, 6, 7, 8])
    SkewtestResult(statistic=1.0108048609177787, pvalue=0.3121098361421897)
    >>> skewtest([2, 8, 0, 4, 1, 9, 9, 0])
    SkewtestResult(statistic=0.44626385374196975, pvalue=0.6554066631275459)
    >>> skewtest([1, 2, 3, 4, 5, 6, 7, 8000])
    SkewtestResult(statistic=3.571773510360407, pvalue=0.0003545719905823133)
    >>> skewtest([100, 100, 100, 100, 100, 100, 100, 101])
    SkewtestResult(statistic=3.5717766638478072, pvalue=0.000354567720281634)
    R\   i    i   sF   skewtest is not valid with less than 8 samples; %i samples were given.i   i   g      @i   g      @i   iF   g       @i   i   i	   ig      ?N(   RW   Rn   R   R   R   R$   RO   RP   RQ   R!   Ry   Ra   R   t   mathR   Rr   R   R   R   t   normt   sfR   (   RT   RU   Rk   Rm   t   b2R   t   yt   beta2t   W2t   deltat   alphat   Z(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR$     s.    1	+'# 0t   KurtosistestResultc         C` s  t  |  |  \ }  } t |  |  \ } } | r[ | d k r[ t j |   }  t j |  |  S|  j | } | d k  r t d t |    n  | d k  r t	 j
 d t |   n  t |  | d t } d | d | d } d	 | | d
 | d | d | d | d | d } | | t j |  } d | | d | d
 | d | d t j d | d | d | | d
 | d  }	 d d |	 d |	 t j d d |	 d
  }
 d d
 d |
 } d | t j d
 |
 d  } t j |  t j | d k t j t j d d |
 t j |  d   } t j | d k  rdd } t	 j
 | t  n  | | t j d
 d |
  } | j d k r| d } n  t | d
 t j j t j |    S(   s  
    Test whether a dataset has normal kurtosis.

    This function tests the null hypothesis that the kurtosis
    of the population from which the sample was drawn is that
    of the normal distribution: ``kurtosis = 3(n-1)/(n+1)``.

    Parameters
    ----------
    a : array
        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`.
    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'.

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

    Notes
    -----
    Valid only for n>20. This function uses the method described in [1]_.

    References
    ----------
    .. [1] see e.g. F. J. Anscombe, W. J. Glynn, "Distribution of the kurtosis
       statistic b2 for normal samples", Biometrika, vol. 70, pp. 227-234, 1983.

    Examples
    --------
    >>> from scipy.stats import kurtosistest
    >>> kurtosistest(list(range(20)))
    KurtosistestResult(statistic=-1.7058104152122062, pvalue=0.08804338332528348)

    >>> np.random.seed(28041990)
    >>> s = np.random.normal(0, 1, 1000)
    >>> kurtosistest(s)
    KurtosistestResult(statistic=1.2317590987707365, pvalue=0.21803908613450895)
    R\   i   sJ   kurtosistest requires at least 5 observations; %i observations were given.i   s=   kurtosistest only valid for n>=20 ... continuing anyway, n=%iR   g      @i   g      8@i   i   g      ?g      @i   i	   g       @g       @g      @g      "@g        i    s\   Test statistic not defined in some cases due to division by zero. Return nan in that case...gUUUUUU?(    (   RW   Rn   R   R   R   R%   Ry   Ra   R   Rh   Ri   R"   Rg   RP   R   t   signR   R   t   powerR   R   Rj   RR   R   R   R   R   (   RT   RU   Rk   Rm   R   R   t   Et   varb2t   xt	   sqrtbeta1t   At   term1t   denomt   term2t   msgR   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR%   J  s>    /	:@/!+t   NormaltestResultc         C` s   t  |  |  \ }  } t |  |  \ } } | r[ | d k r[ t j |   }  t j |  |  St |  |  \ } } t |  |  \ } } | | | | } t | t	 j
 j | d   S(   s  
    Test whether a sample differs from a normal distribution.

    This function tests the null hypothesis that a sample comes
    from a normal distribution.  It is based on D'Agostino and
    Pearson's [1]_, [2]_ test that combines skew and kurtosis to
    produce an omnibus test of normality.


    Parameters
    ----------
    a : array_like
        The array containing the sample 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`.
    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'.

    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.

    References
    ----------
    .. [1] D'Agostino, R. B. (1971), "An omnibus test of normality for
           moderate and large sample size", Biometrika, 58, 341-348

    .. [2] D'Agostino, R. and Pearson, E. S. (1973), "Tests for departure from
           normality", Biometrika, 60, 613-622

    Examples
    --------
    >>> from scipy import stats
    >>> pts = 1000
    >>> np.random.seed(28041990)
    >>> a = np.random.normal(0, 1, size=pts)
    >>> b = np.random.normal(2, 1, size=pts)
    >>> x = np.concatenate((a, b))
    >>> k2, p = stats.normaltest(x)
    >>> alpha = 1e-3
    >>> print("p = {:g}".format(p))
    p = 3.27207e-11
    >>> if p < alpha:  # null hypothesis: x comes from a normal distribution
    ...     print("The null hypothesis can be rejected")
    ... else:
    ...     print("The null hypothesis cannot be rejected")
    The null hypothesis can be rejected
    R\   i   (   RW   Rn   R   R   R   R&   R$   R%   R   R   t   chi2R   (   RT   RU   Rk   Rm   R^   t   _t   kt   k2(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR&     s    8c         C` s   t  j |   }  |  j } | d k r3 t d   n  |  j   } |  | } d | t  j | d  d | t  j | d  d	 } d | t  j | d  d | t  j | d  d } | d | d | d d d } d t j j | d  } | | f S(
   sy  
    Perform the Jarque-Bera goodness of fit test on sample data.

    The Jarque-Bera test tests whether the sample data has the skewness and
    kurtosis matching a normal distribution.

    Note that this test only works for a large enough number of data samples
    (>2000) as the test statistic asymptotically has a Chi-squared distribution
    with 2 degrees of freedom.

    Parameters
    ----------
    x : array_like
        Observations of a random variable.

    Returns
    -------
    jb_value : float
        The test statistic.
    p : float
        The p-value for the hypothesis test.

    References
    ----------
    .. [1] Jarque, C. and Bera, A. (1980) "Efficient tests for normality,
           homoscedasticity and serial independence of regression residuals",
           6 Econometric Letters 255-259.

    Examples
    --------
    >>> from scipy import stats
    >>> np.random.seed(987654321)
    >>> x = np.random.normal(0, 1, 100000)
    >>> y = np.random.rayleigh(1, 100000)
    >>> stats.jarque_bera(x)
    (4.7165707989581342, 0.09458225503041906)
    >>> stats.jarque_bera(y)
    (6713.7098548143422, 0.0)

    i    s%   At least one observation is required.i   i   i   g       @i   i   g      ?(	   RP   R   Rz   Ra   Ru   Re   R   R   t   cdf(   R   R   t   mut   diffxR   R"   t   jb_valuet   p(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR'     s    )	
88"t   messagesr   `itemfreq` is deprecated and will be removed in a future version. Use instead `np.unique(..., return_counts=True)`c         C` s@   t  j |  d t \ } } t  j |  } t  j | | g  j S(   s
  
    Return a 2-D array of item frequencies.

    Parameters
    ----------
    a : (N,) array_like
        Input array.

    Returns
    -------
    itemfreq : (K, 2) ndarray
        A 2-D frequency table.  Column 1 contains sorted, unique values from
        `a`, column 2 contains their respective counts.

    Examples
    --------
    >>> from scipy import stats
    >>> a = np.array([1, 1, 5, 0, 1, 2, 2, 0, 1, 4])
    >>> stats.itemfreq(a)
    array([[ 0.,  2.],
           [ 1.,  4.],
           [ 2.,  2.],
           [ 4.,  1.],
           [ 5.,  1.]])
    >>> np.bincount(a)
    array([2, 4, 2, 0, 1, 1])

    >>> stats.itemfreq(a/10.)
    array([[ 0. ,  2. ],
           [ 0.1,  4. ],
           [ 0.2,  2. ],
           [ 0.4,  1. ],
           [ 0.5,  1. ]])

    t   return_inverse(   RP   R}   R~   t   bincountR   t   T(   RT   t   itemst   invt   freq(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR(   *  s    &t   fractionc         C` s   t  j |   }  |  j d k r_ t  j |  r4 t  j St  j t  j |  j t  j d t  j Sn  | r |  | d |  k |  | d k @}  n  t  j |  d | } | d k r d } n  t
 | | | |  S(   s  
    Calculate the score at a given percentile of the input sequence.

    For example, the score at `per=50` is the median. If the desired quantile
    lies between two data points, we interpolate between them, according to
    the value of `interpolation`. If the parameter `limit` is provided, it
    should be a tuple (lower, upper) of two values.

    Parameters
    ----------
    a : array_like
        A 1-D array of values from which to extract score.
    per : array_like
        Percentile(s) at which to extract score.  Values should be in range
        [0,100].
    limit : tuple, optional
        Tuple of two scalars, the lower and upper limits within which to
        compute the percentile. Values of `a` outside
        this (closed) interval will be ignored.
    interpolation_method : {'fraction', 'lower', 'higher'}, optional
        This optional parameter specifies the interpolation method to use,
        when the desired quantile lies between two data points `i` and `j`

          - fraction: ``i + (j - i) * fraction`` where ``fraction`` is the
            fractional part of the index surrounded by ``i`` and ``j``.
          - lower: ``i``.
          - higher: ``j``.

    axis : int, optional
        Axis along which the percentiles are computed. Default is None. If
        None, compute over the whole array `a`.

    Returns
    -------
    score : float or ndarray
        Score at percentile(s).

    See Also
    --------
    percentileofscore, numpy.percentile

    Notes
    -----
    This function will become obsolete in the future.
    For Numpy 1.9 and higher, `numpy.percentile` provides all the functionality
    that `scoreatpercentile` provides.  And it's significantly faster.
    Therefore it's recommended to use `numpy.percentile` for users that have
    numpy >= 1.9.

    Examples
    --------
    >>> from scipy import stats
    >>> a = np.arange(100)
    >>> stats.scoreatpercentile(a, 50)
    49.5

    i    Ro   i   RU   N(   RP   R   Rz   R   R   R   Ry   R   t   sortRO   t   _compute_qth_percentile(   RT   t   pert   limitt   interpolation_methodRU   t   sorted_(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR)   U  s    =+%	c         C` s  t  j |  sD g  | D] } t |  | | |  ^ q } t  j |  Sd | k o[ d k n so t d   n  t d   g |  j } | d |  j | d } t	 |  | k r| d k r t	 t  j
 |   } q| d k r t	 t  j |   } q| d k rqt d	   n  t	 |  } | | k rZt | | d  | | <t d  } d
 }	 nm t | | d  | | <| d }
 t |
 | | | g t  } d g |  j } d | | <| | _ | j   }	 t  j j |  t |  | d | |	 S(   Ni    id   s(   percentile must be in the range [0, 100]g      Y@i   t   lowert   higherR  s@   interpolation_method can only be 'fraction', 'lower' or 'higher'g      ?i   RU   (   RP   R   R  R   Ra   t   sliceRO   RR   Ry   R   t   floort   ceilR   Re   t   addR   t   tuple(   R  R  R  RU   R   R   t   indexert   idxt   weightst   sumvalt   jt   wshape(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR    s:    %	

	t   rankc         C` sA  t  j |  r t  j St  j |   }  t |   } | d k rA d S| d k r t  j |  | k   } t  j |  | k  } | | | | k r d n d d | } | S| d k r t  j |  | k   | d S| d k r t  j |  | k  | d S| d	 k r1t  j |  | k   t  j |  | k  | d
 } | St d   d S(   s  
    The percentile rank of a score relative to a list of scores.

    A `percentileofscore` of, for example, 80% means that 80% of the
    scores in `a` are below the given score. In the case of gaps or
    ties, the exact definition depends on the optional keyword, `kind`.

    Parameters
    ----------
    a : array_like
        Array of scores to which `score` is compared.
    score : int or float
        Score that is compared to the elements in `a`.
    kind : {'rank', 'weak', 'strict', 'mean'}, optional
        This optional parameter specifies the interpretation of the
        resulting score:

        - "rank": Average percentage ranking of score.  In case of
                  multiple matches, average the percentage rankings of
                  all matching scores.
        - "weak": This kind corresponds to the definition of a cumulative
                  distribution function.  A percentileofscore of 80%
                  means that 80% of values are less than or equal
                  to the provided score.
        - "strict": Similar to "weak", except that only values that are
                    strictly less than the given score are counted.
        - "mean": The average of the "weak" and "strict" scores, often used in
                  testing.  See

                  https://en.wikipedia.org/wiki/Percentile_rank

    Returns
    -------
    pcos : float
        Percentile-position of score (0-100) relative to `a`.

    See Also
    --------
    numpy.percentile

    Examples
    --------
    Three-quarters of the given values lie below a given score:

    >>> from scipy import stats
    >>> stats.percentileofscore([1, 2, 3, 4], 3)
    75.0

    With multiple matches, note how the scores of the two matches, 0.6
    and 0.8 respectively, are averaged:

    >>> stats.percentileofscore([1, 2, 3, 3, 4], 3)
    70.0

    Only 2/5 values are strictly less than 3:

    >>> stats.percentileofscore([1, 2, 3, 3, 4], 3, kind='strict')
    40.0

    But 4/5 values are less than or equal to 3:

    >>> stats.percentileofscore([1, 2, 3, 3, 4], 3, kind='weak')
    80.0

    The average between the weak and the strict scores is

    >>> stats.percentileofscore([1, 2, 3, 3, 4], 3, kind='mean')
    60.0

    i    g      Y@R#  i   g      I@t   strictid   t   weakRu   i2   s3   kind can only be 'rank', 'strict', 'weak' or 'mean'N(   RP   Rd   R   R   R   t   count_nonzeroRa   (   RT   R   t   kindR   t   leftt   rightt   pct(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR*     s&    G(0t   HistogramResultR   t   binsizet   extrapointsi
   c         C` sB  t  j |   }  | d
 k rx |  j d k r3 d } qx |  j   } |  j   } | | d | d } | | | | f } n  t  j |  d | d | d | \ } }	 t  j | d t } |	 d |	 d }
 t	 g  |  D], } | d | k s | | d k r | ^ q  } | d k r+| r+t
 j d	 |  n  t | | d |
 |  S(   s  
    Separate the range into several bins and return the number of instances
    in each bin.

    Parameters
    ----------
    a : array_like
        Array of scores which will be put into bins.
    numbins : int, optional
        The number of bins to use for the histogram. Default is 10.
    defaultlimits : tuple (lower, upper), optional
        The lower and upper values for the range of the histogram.
        If no value is given, a range slightly larger than the range of the
        values in a is used. Specifically ``(a.min() - s, a.max() + s)``,
        where ``s = (1/2)(a.max() - a.min()) / (numbins - 1)``.
    weights : array_like, optional
        The weights for each value in `a`. Default is None, which gives each
        value a weight of 1.0
    printextras : bool, optional
        If True, if there are extra points (i.e. the points that fall outside
        the bin limits) a warning is raised saying how many of those points
        there are.  Default is False.

    Returns
    -------
    count : ndarray
        Number of points (or sum of weights) in each bin.
    lowerlimit : float
        Lowest value of histogram, the lower limit of the first bin.
    binsize : float
        The size of the bins (all bins have the same size).
    extrapoints : int
        The number of points outside the range of the histogram.

    See Also
    --------
    numpy.histogram

    Notes
    -----
    This histogram is based on numpy's histogram but has a larger range by
    default if default limits is not set.

    i    i   g       @g      ?t   binsR   R  Ro   s)   Points outside given histogram range = %sN(   i    i   (   RP   RQ   RO   Rz   R   R   t	   histogramR   R   R   Rh   Ri   R+  (   RT   t   numbinst   defaultlimitsR  t   printextrast   data_mint   data_maxR^   t   histt	   bin_edgesR,  R   R-  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt
   _histogram2  s$    -	/	t   CumfreqResultt   cumcountc   	      C` sP   t  |  | | d | \ } } } } t j | d d d } t | | | |  S(   s  
    Return a cumulative frequency histogram, using the histogram function.

    A cumulative histogram is a mapping that counts the cumulative number of
    observations in all of the bins up to the specified bin.

    Parameters
    ----------
    a : array_like
        Input array.
    numbins : int, optional
        The number of bins to use for the histogram. Default is 10.
    defaultreallimits : tuple (lower, upper), optional
        The lower and upper values for the range of the histogram.
        If no value is given, a range slightly larger than the range of the
        values in `a` is used. Specifically ``(a.min() - s, a.max() + s)``,
        where ``s = (1/2)(a.max() - a.min()) / (numbins - 1)``.
    weights : array_like, optional
        The weights for each value in `a`. Default is None, which gives each
        value a weight of 1.0

    Returns
    -------
    cumcount : ndarray
        Binned values of cumulative frequency.
    lowerlimit : float
        Lower real limit
    binsize : float
        Width of each bin.
    extrapoints : int
        Extra points.

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from scipy import stats
    >>> x = [1, 4, 2, 1, 3, 1]
    >>> res = stats.cumfreq(x, numbins=4, defaultreallimits=(1.5, 5))
    >>> res.cumcount
    array([ 1.,  2.,  3.,  3.])
    >>> res.extrapoints
    3

    Create a normal distribution with 1000 random values

    >>> rng = np.random.RandomState(seed=12345)
    >>> samples = stats.norm.rvs(size=1000, random_state=rng)

    Calculate cumulative frequencies

    >>> res = stats.cumfreq(samples, numbins=25)

    Calculate space of values for x

    >>> x = res.lowerlimit + np.linspace(0, res.binsize*res.cumcount.size,
    ...                                  res.cumcount.size)

    Plot histogram and cumulative histogram

    >>> fig = plt.figure(figsize=(10, 4))
    >>> ax1 = fig.add_subplot(1, 2, 1)
    >>> ax2 = fig.add_subplot(1, 2, 2)
    >>> ax1.hist(samples, bins=25)
    >>> ax1.set_title('Histogram')
    >>> ax2.bar(x, res.cumcount, width=res.binsize)
    >>> ax2.set_title('Cumulative histogram')
    >>> ax2.set_xlim([x.min(), x.max()])

    >>> plt.show()

    R  i   RU   i    (   R7  RP   t   cumsumR8  (	   RT   R0  t   defaultreallimitsR  t   ht   lRX   t   et   cumhist(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR+     s    H$t   RelfreqResultt	   frequencyc         C` sW   t  j |   }  t |  | | d | \ } } } } | |  j d } t | | | |  S(   sq  
    Return a relative frequency histogram, using the histogram function.

    A relative frequency  histogram is a mapping of the number of
    observations in each of the bins relative to the total of observations.

    Parameters
    ----------
    a : array_like
        Input array.
    numbins : int, optional
        The number of bins to use for the histogram. Default is 10.
    defaultreallimits : tuple (lower, upper), optional
        The lower and upper values for the range of the histogram.
        If no value is given, a range slightly larger than the range of the
        values in a is used. Specifically ``(a.min() - s, a.max() + s)``,
        where ``s = (1/2)(a.max() - a.min()) / (numbins - 1)``.
    weights : array_like, optional
        The weights for each value in `a`. Default is None, which gives each
        value a weight of 1.0

    Returns
    -------
    frequency : ndarray
        Binned values of relative frequency.
    lowerlimit : float
        Lower real limit
    binsize : float
        Width of each bin.
    extrapoints : int
        Extra points.

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from scipy import stats
    >>> a = np.array([2, 4, 1, 2, 3, 2])
    >>> res = stats.relfreq(a, numbins=4)
    >>> res.frequency
    array([ 0.16666667, 0.5       , 0.16666667,  0.16666667])
    >>> np.sum(res.frequency)  # relative frequencies should add up to 1
    1.0

    Create a normal distribution with 1000 random values

    >>> rng = np.random.RandomState(seed=12345)
    >>> samples = stats.norm.rvs(size=1000, random_state=rng)

    Calculate relative frequencies

    >>> res = stats.relfreq(samples, numbins=25)

    Calculate space of values for x

    >>> x = res.lowerlimit + np.linspace(0, res.binsize*res.frequency.size,
    ...                                  res.frequency.size)

    Plot relative frequency histogram

    >>> fig = plt.figure(figsize=(5, 4))
    >>> ax = fig.add_subplot(1, 1, 1)
    >>> ax.bar(x, res.frequency, width=res.binsize)
    >>> ax.set_title('Relative frequency histogram')
    >>> ax.set_xlim([x.min(), x.max()])

    >>> plt.show()

    R  i    (   RP   t
   asanyarrayR7  Ry   R@  (   RT   R0  R;  R  R<  R=  RX   R>  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR,     s    E$c          G` s   t  j t  j t  j  } g  } x |  D] } t  j |  } t |  } t  j |  } | | d } | j   } | d | | d | | d | d }	 | | d }
 t	 |
 t  j |	   | k r t
 d   n  | j |	  q( Wt  j |  S(   sq  
    Compute the O'Brien transform on input data (any number of arrays).

    Used to test for homogeneity of variance prior to running one-way stats.
    Each array in ``*args`` is one level of a factor.
    If `f_oneway` is run on the transformed data and found significant,
    the variances are unequal.  From Maxwell and Delaney [1]_, p.112.

    Parameters
    ----------
    args : tuple of array_like
        Any number of arrays.

    Returns
    -------
    obrientransform : ndarray
        Transformed data for use in an ANOVA.  The first dimension
        of the result corresponds to the sequence of transformed
        arrays.  If the arrays given are all 1-D of the same length,
        the return value is a 2-D array; otherwise it is a 1-D array
        of type object, with each element being an ndarray.

    References
    ----------
    .. [1] S. E. Maxwell and H. D. Delaney, "Designing Experiments and
           Analyzing Data: A Model Comparison Perspective", Wadsworth, 1990.

    Examples
    --------
    We'll test the following data sets for differences in their variance.

    >>> x = [10, 11, 13, 9, 7, 12, 12, 9, 10]
    >>> y = [13, 21, 5, 10, 8, 14, 10, 12, 7, 15]

    Apply the O'Brien transform to the data.

    >>> from scipy.stats import obrientransform
    >>> tx, ty = obrientransform(x, y)

    Use `scipy.stats.f_oneway` to apply a one-way ANOVA test to the
    transformed data.

    >>> from scipy.stats import f_oneway
    >>> F, p = f_oneway(tx, ty)
    >>> p
    0.1314139477040335

    If we require that ``p < 0.05`` for significance, we cannot conclude
    that the variances are different.
    i   g      ?g      ?i   s'   Lack of convergence in obrientransform.(   RP   R   t   finfoR   t   epsR   R   Ru   Re   R   Ra   R   R   (   t   argst   TINYt   arrayst   argRT   R   R  t   sqt   sumsqt   tR   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR-   %  s    3*c         C` s   t  |  |  \ }  } t |  |  \ } } | r^ | d k r^ t j |   }  t j |  | |  S|  j | } t j |  d | d | t j	 |  } | S(   s  
    Calculate the standard error of the mean (or standard error of
    measurement) of the values in the input array.

    Parameters
    ----------
    a : array_like
        An array containing the values for which the standard error is
        returned.
    axis : int or None, optional
        Axis along which to operate. Default is 0. If None, compute over
        the whole array `a`.
    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.
    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'.

    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` is different to the default (0) used by other
    ddof containing routines, such as np.std and np.nanstd.

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

    >>> from scipy import stats
    >>> a = np.arange(20).reshape(5,4)
    >>> stats.sem(a)
    array([ 2.8284,  2.8284,  2.8284,  2.8284])

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

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

    R\   RU   R   (
   RW   Rn   R   R   R   R.   Ry   RP   R   R   (   RT   RU   R   Rk   Rm   R   R^   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR.   r  s    /(c         C` s   t  j |   }  |  j d |  } |  j d | d |  } | r{ | j |  j k  r{ |  t  j | d | t  j | d | S|  | | Sd S(   s  
    Calculate the z score of each value in the sample, relative to the
    sample mean and standard deviation.

    Parameters
    ----------
    a : array_like
        An array like object containing the sample data.
    axis : int or None, optional
        Axis along which to operate. Default is 0. If None, compute over
        the whole array `a`.
    ddof : int, optional
        Degrees of freedom correction in the calculation of the
        standard deviation. Default is 0.

    Returns
    -------
    zscore : array_like
        The z-scores, standardized by mean and standard deviation of
        input array `a`.

    Notes
    -----
    This function preserves ndarray subclasses, and works also with
    matrices and masked arrays (it uses `asanyarray` instead of
    `asarray` for parameters).

    Examples
    --------
    >>> a = np.array([ 0.7972,  0.0767,  0.4383,  0.7866,  0.8091,
    ...                0.1954,  0.6307,  0.6599,  0.1065,  0.0508])
    >>> from scipy import stats
    >>> stats.zscore(a)
    array([ 1.1273, -1.247 , -0.0552,  1.0923,  1.1664, -0.8559,  0.5786,
            0.6748, -1.1488, -1.3324])

    Computing along a specified axis, using n-1 degrees of freedom
    (``ddof=1``) to calculate the standard deviation:

    >>> b = np.array([[ 0.3148,  0.0478,  0.6243,  0.4608],
    ...               [ 0.7149,  0.0775,  0.6072,  0.9656],
    ...               [ 0.6341,  0.1403,  0.9759,  0.4064],
    ...               [ 0.5918,  0.6948,  0.904 ,  0.3721],
    ...               [ 0.0921,  0.2481,  0.1188,  0.1366]])
    >>> stats.zscore(b, axis=1, ddof=1)
    array([[-0.19264823, -1.28415119,  1.07259584,  0.40420358],
           [ 0.33048416, -1.37380874,  0.04251374,  1.00081084],
           [ 0.26796377, -1.12598418,  1.23283094, -0.37481053],
           [-0.22095197,  0.24468594,  1.19042819, -1.21416216],
           [-0.82780366,  1.4457416 , -0.43867764, -0.1792603 ]])
    RU   R   N(   RP   RB  Ru   R   RR   R   (   RT   RU   R   t   mnst   sstd(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR0     s    4c         C` s   t  t j |  | g  \ }  } | j d |  } | j d | d |  } | r | j | j k  r |  t j | d | t j | d | S|  | | Sd S(   s  
    Calculate the relative z-scores.

    Return an array of z-scores, i.e., scores that are standardized to
    zero mean and unit variance, where mean and variance are calculated
    from the comparison array.

    Parameters
    ----------
    scores : array_like
        The input for which z-scores are calculated.
    compare : array_like
        The input from which the mean and standard deviation of the
        normalization are taken; assumed to have the same dimension as
        `scores`.
    axis : int or None, optional
        Axis over which mean and variance of `compare` are calculated.
        Default is 0. If None, compute over the whole array `scores`.
    ddof : int, optional
        Degrees of freedom correction in the calculation of the
        standard deviation. Default is 0.

    Returns
    -------
    zscore : array_like
        Z-scores, in the same shape as `scores`.

    Notes
    -----
    This function preserves ndarray subclasses, and works also with
    matrices and masked arrays (it uses `asanyarray` instead of
    `asarray` for parameters).

    Examples
    --------
    >>> from scipy.stats import zmap
    >>> a = [0.5, 2.0, 2.5, 3]
    >>> b = [0, 1, 2, 3, 4]
    >>> zmap(a, b)
    array([-1.06066017,  0.        ,  0.35355339,  0.70710678])
    RU   R   N(   t   mapRP   RB  Ru   R   RR   R   (   R   t   compareRU   R   RL  RM  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR/     s    *g      ?t   rawg      ?g       @t   normali   iK   t   linearc         C` s)  t  |   }  |  j s t j St | t  rh | j   } | t k r[ t d j	 |    n  t | } n  t
 |  |  \ } } | r | d k r t }	 n t }	 t |  d k r t d   n  t |  } |	 |  | d | d | d | d | }
 t j |
 d	 |
 d
  } | d k r%| | } n  | S(   s  
    Compute the interquartile range of the data along the specified axis.

    The interquartile range (IQR) is the difference between the 75th and
    25th percentile of the data. It is a measure of the dispersion
    similar to standard deviation or variance, but is much more robust
    against outliers [2]_.

    The ``rng`` parameter allows this function to compute other
    percentile ranges than the actual IQR. For example, setting
    ``rng=(0, 100)`` is equivalent to `numpy.ptp`.

    The IQR of an empty array is `np.nan`.

    .. versionadded:: 0.18.0

    Parameters
    ----------
    x : array_like
        Input array or object that can be converted to an array.
    axis : int or sequence of int, optional
        Axis along which the range is computed. The default is to
        compute the IQR for the entire array.
    rng : Two-element sequence containing floats in range of [0,100] optional
        Percentiles over which to compute the range. Each must be
        between 0 and 100, inclusive. The default is the true IQR:
        `(25, 75)`. The order of the elements is not important.
    scale : scalar or str, optional
        The numerical value of scale will be divided out of the final
        result. The following string values are recognized:

          'raw' : No scaling, just return the raw IQR.
          'normal' : Scale by :math:`2 \sqrt{2} erf^{-1}(\frac{1}{2}) \approx 1.349`.

        The default is 'raw'. Array-like scale is also allowed, as long
        as it broadcasts correctly to the output such that
        ``out / scale`` is a valid operation. The output dimensions
        depend on the input array, `x`, the `axis` argument, and the
        `keepdims` flag.
    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'.
    interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}, optional
        Specifies the interpolation method to use when the percentile
        boundaries lie between two data points `i` and `j`:

          * 'linear' : `i + (j - i) * fraction`, where `fraction` is the
              fractional part of the index surrounded by `i` and `j`.
          * 'lower' : `i`.
          * 'higher' : `j`.
          * 'nearest' : `i` or `j` whichever is nearest.
          * 'midpoint' : `(i + j) / 2`.

        Default is 'linear'.
    keepdims : bool, optional
        If this is set to `True`, the reduced axes are left in the
        result as dimensions with size one. With this option, the result
        will broadcast correctly against the original array `x`.

    Returns
    -------
    iqr : scalar or ndarray
        If ``axis=None``, a scalar is returned. If the input contains
        integers or floats of smaller precision than ``np.float64``, then the
        output data-type is ``np.float64``. Otherwise, the output data-type is
        the same as that of the input.

    See Also
    --------
    numpy.std, numpy.var

    Examples
    --------
    >>> from scipy.stats import iqr
    >>> x = np.array([[10, 7, 4], [3, 2, 1]])
    >>> x
    array([[10,  7,  4],
           [ 3,  2,  1]])
    >>> iqr(x)
    4.0
    >>> iqr(x, axis=0)
    array([ 3.5,  2.5,  1.5])
    >>> iqr(x, axis=1)
    array([ 3.,  1.])
    >>> iqr(x, axis=1, keepdims=True)
    array([[ 3.],
           [ 1.]])

    Notes
    -----
    This function is heavily dependent on the version of `numpy` that is
    installed. Versions greater than 1.11.0b3 are highly recommended, as they
    include a number of enhancements and fixes to `numpy.percentile` and
    `numpy.nanpercentile` that affect the operation of this function. The
    following modifications apply:

    Below 1.10.0 : `nan_policy` is poorly defined.
        The default behavior of `numpy.percentile` is used for 'propagate'. This
        is a hybrid of 'omit' and 'propagate' that mostly yields a skewed
        version of 'omit' since NaNs are sorted to the end of the data. A
        warning is raised if there are NaNs in the data.
    Below 1.9.0: `numpy.nanpercentile` does not exist.
        This means that `numpy.percentile` is used regardless of `nan_policy`
        and a warning is issued. See previous item for a description of the
        behavior.
    Below 1.9.0: `keepdims` and `interpolation` are not supported.
        The keywords get ignored with a warning if supplied with non-default
        values. However, multiple axes are still supported.

    References
    ----------
    .. [1] "Interquartile range" https://en.wikipedia.org/wiki/Interquartile_range
    .. [2] "Robust measures of scale" https://en.wikipedia.org/wiki/Robust_measures_of_scale
    .. [3] "Quantile" https://en.wikipedia.org/wiki/Quantile
    s   {0} not a valid scale for `iqr`R\   i   s+   quantile range must be two element sequenceRU   t   interpolationt   keepdimsRm   i   i    g      ?(   R   Rz   RP   R   Rp   R   R  t   _scale_conversionsRa   t   formatRn   t   _iqr_nanpercentilet   _iqr_percentileR   Rf   t   sortedt   subtract(   R   RU   t   rngt   scaleRk   RS  RT  t	   scale_keyRm   t   percentile_funcR*  t   out(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR1   &	  s*    v		c   
   	   C` s  | r4 t  t j  d k  r4 d } t j | t  n  y( t j |  | d | d | d | } WnWt k
 r| d k s~ | r t j d t  n  y t |  } Wn t k
 r n Xt j	 t j
 |  |  j  } | | j k r t d   n  | j |  j k rd } n | j d	 k r)| d
 } nq x3 | d d d  D] }	 t j |  |	 |  j  }  q=W|  j |  j | j  t j |  j | j  f  }  d } t j |  | d | } n X| S(   s   
    Private wrapper that works around older versions of `numpy`.

    While this function is pretty much necessary for the moment, it
    should be removed as soon as the minimum supported numpy version
    allows.
    s   1.10.0as   Keyword nan_policy='propagate' not correctly supported for numpy versions < 1.10.x. The default behavior of `numpy.percentile` will be used.RU   RT  RS  RR  sK   Keywords interpolation and keepdims not supported for your version of numpys   duplicate value in axisi   i    Ni(   R	   RP   R   Rh   Ri   Rj   t
   percentileRf   R   R}   R   RR   Rz   Ra   RO   t   rollaxisR   Ry   t   prod(
   R   t   qRU   RS  RT  Rm   R   t   resultt   original_sizet   ax(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRX  	  s8    	
	!c      	   C` s   t  t d  r t j |  | d | d | d | } | j d k r t t j  d k  r t j |  } | j d k r | j d k r | d
 } n  t j	 | | d  } q t j	 | d  } q n+ d	 } t
 j | t  t |  | d | } | S(   s  
    Private wrapper that works around the following:

      1. A bug in `np.nanpercentile` that was around until numpy version
         1.11.0.
      2. A bug in `np.percentile` NaN handling that was fixed in numpy
         version 1.10.0.
      3. The non-existence of `np.nanpercentile` before numpy version
         1.9.0.

    While this function is pretty much necessary for the moment, it
    should be removed as soon as the minimum supported numpy version
    allows.
    t   nanpercentileRU   RS  RT  i   s   1.11.0ai    is   Keyword nan_policy='omit' not correctly supported for numpy versions < 1.9.x. The default behavior of  numpy.percentile will be used.N(   t   hasattrRP   Rg  RR   R	   R   R   Rz   RO   Ra  Rh   Ri   Rj   RX  (   R   Rc  RU   RS  RT  Rm   Rd  R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRW  	  s    	$t   SigmaclipResultt   clippedR  t   upperg      @c   
      C` s   t  j |   j   } d } xn | r | j   } | j   } | j } | | | } | | | }	 | | | k | |	 k @} | | j } q Wt | | |	  S(   s  
    Iterative sigma-clipping of array elements.

    Starting from the full sample, all elements outside the critical range are
    removed, i.e. all elements of the input array `c` that satisfy either of
    the following conditions ::

        c < mean(c) - std(c)*low
        c > mean(c) + std(c)*high

    The iteration continues with the updated sample until no
    elements are outside the (updated) range.

    Parameters
    ----------
    a : array_like
        Data array, will be raveled if not 1-D.
    low : float, optional
        Lower bound factor of sigma clipping. Default is 4.
    high : float, optional
        Upper bound factor of sigma clipping. Default is 4.

    Returns
    -------
    clipped : ndarray
        Input array with clipped elements removed.
    lower : float
        Lower threshold value use for clipping.
    upper : float
        Upper threshold value use for clipping.

    Examples
    --------
    >>> from scipy.stats import sigmaclip
    >>> a = np.concatenate((np.linspace(9.5, 10.5, 31),
    ...                     np.linspace(0, 20, 5)))
    >>> fact = 1.5
    >>> c, low, upp = sigmaclip(a, fact, fact)
    >>> c
    array([  9.96666667,  10.        ,  10.03333333,  10.        ])
    >>> c.var(), c.std()
    (0.00055555555555555165, 0.023570226039551501)
    >>> low, c.mean() - fact*c.std(), c.min()
    (9.9646446609406727, 9.9646446609406727, 9.9666666666666668)
    >>> upp, c.mean() + fact*c.std(), c.max()
    (10.035355339059327, 10.035355339059327, 10.033333333333333)

    >>> a = np.concatenate((np.linspace(9.5, 10.5, 11),
    ...                     np.linspace(-100, -50, 3)))
    >>> c, low, upp = sigmaclip(a, 1.8, 1.8)
    >>> (c == np.linspace(9.5, 10.5, 11)).all()
    True

    i   (   RP   R   RQ   R   Ru   Rz   Ri  (
   RT   t   lowt   hight   cR   t   c_stdt   c_meanRz   t	   critlowert	   critupper(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR2   0
  s    7		c         C` s   t  j |   }  |  j d k r" |  S| d k rC |  j   }  d } n  |  j | } t | |  } | | } | | k r t d   n  t  j |  | | d f |  } t	 d  g | j
 } t	 | |  | | <| t |  S(   s,  
    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). The trimmed values are the lowest and
    highest ones.
    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
        Proportion (in range 0-1) of total data set to trim of each end.
    axis : int or None, optional
        Axis along which to trim data. Default is 0. If None, compute over
        the whole array `a`.

    Returns
    -------
    out : ndarray
        Trimmed version of array `a`. The order of the trimmed content
        is undefined.

    See Also
    --------
    trim_mean

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

    i    s   Proportion too big.i   N(   RP   R   Rz   RO   RQ   Ry   R   Ra   t	   partitionR  RR   R  (   RT   t   proportiontocutRU   R   t   lowercutt   uppercutt   atmpt   sl(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR3   u
  s    (	
R)  c         C` s   t  j |   }  | d k r0 |  j   }  d } n  |  j | } | d k rM g  S| j   d k r| d } | t | |  } n+ | j   d k r t | |  } | } n  t  j |  | | d f |  } | | | !S(   sk  
    Slices off a proportion from ONE end of the passed array distribution.

    If `proportiontocut` = 0.1, slices off 'leftmost' or 'rightmost'
    10% of scores. The lowest or highest values are trimmed (depending on
    the tail).
    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 of 'left' or 'right' of distribution
    tail : {'left', 'right'}, optional
        Defaults to 'right'.
    axis : int or None, optional
        Axis along which to trim data. Default is 0. If None, compute over
        the whole array `a`.

    Returns
    -------
    trim1 : ndarray
        Trimmed version of array `a`. The order of the trimmed content is
        undefined.

    i    i   R)  R(  N(   RP   R   RO   RQ   Ry   R  R   Rs  (   RT   Rt  t   tailRU   R   Ru  Rv  Rw  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR4   
  s    		c         C` s   t  j |   }  |  j d k r% t  j S| d k rF |  j   }  d } n  |  j | } t | |  } | | } | | k r t d   n  t  j	 |  | | d f |  } t
 d  g | j } t
 | |  | | <t  j | t |  d | S(   s!  
    Return mean of array after trimming distribution from both tails.

    If `proportiontocut` = 0.1, slices off 'leftmost' and 'rightmost' 10% of
    scores. The input is sorted before slicing. 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 of both tails of the distribution
    axis : int or None, optional
        Axis along which the trimmed means are computed. Default is 0.
        If None, compute over the whole array `a`.

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

    See Also
    --------
    trimboth
    tmean : compute the trimmed mean ignoring values outside given `limits`.

    Examples
    --------
    >>> from scipy import stats
    >>> x = np.arange(20)
    >>> stats.trim_mean(x, 0.1)
    9.5
    >>> x2 = x.reshape(5, 4)
    >>> x2
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15],
           [16, 17, 18, 19]])
    >>> stats.trim_mean(x2, 0.25)
    array([  8.,   9.,  10.,  11.])
    >>> stats.trim_mean(x2, 0.25, axis=1)
    array([  1.5,   5.5,   9.5,  13.5,  17.5])

    i    s   Proportion too big.i   RU   N(   RP   R   Rz   R   RO   RQ   Ry   R   Ra   Rs  R  RR   Ru   R  (   RT   Rt  RU   R   Ru  Rv  Rw  Rx  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR5   
  s    0	
t   F_onewayResultc          G` s&  g  |  D] } t  j | d t ^ q }  t |   } t  j |   } t |  } | j   } | | 8} t |  t |  | } d } x, |  D]$ } | t | |  t |  7} q W| t |  | 8} | | }	 | d }
 | | } | |
 } |	 | } | | } t j	 |
 | |  } t
 | |  S(   s
  
    Performs a 1-way ANOVA.

    The one-way ANOVA tests the null hypothesis that two or more groups have
    the same population mean.  The test is applied to samples from two or
    more groups, possibly with differing sizes.

    Parameters
    ----------
    sample1, sample2, ... : array_like
        The sample measurements for each group.

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

    Notes
    -----
    The ANOVA test has important assumptions that must be satisfied in order
    for the associated p-value to be valid.

    1. The samples are independent.
    2. Each sample is from a normally distributed population.
    3. The population standard deviations of the groups are all equal.  This
       property is known as homoscedasticity.

    If these assumptions are not true for a given set of data, it may still be
    possible to use the Kruskal-Wallis H-test (`scipy.stats.kruskal`) although
    with some loss of power.

    The algorithm is from Heiman[2], pp.394-7.


    References
    ----------
    .. [1] Lowry, Richard.  "Concepts and Applications of Inferential
           Statistics". Chapter 14.
           https://web.archive.org/web/20171027235250/http://vassarstats.net:80/textbook/ch14pt1.html

    .. [2] Heiman, G.W.  Research Methods in Statistics. 2002.

    .. [3] McDonald, G. H. "Handbook of Biological Statistics", One-way ANOVA.
           http://www.biostathandbook.com/onewayanova.html

    Examples
    --------
    >>> import scipy.stats as stats

    [3]_ Here are some data on a shell measurement (the length of the anterior
    adductor muscle scar, standardized by dividing by length) in the mussel
    Mytilus trossulus from five locations: Tillamook, Oregon; Newport, Oregon;
    Petersburg, Alaska; Magadan, Russia; and Tvarminne, Finland, taken from a
    much larger data set used in McDonald et al. (1991).

    >>> tillamook = [0.0571, 0.0813, 0.0831, 0.0976, 0.0817, 0.0859, 0.0735,
    ...              0.0659, 0.0923, 0.0836]
    >>> newport = [0.0873, 0.0662, 0.0672, 0.0819, 0.0749, 0.0649, 0.0835,
    ...            0.0725]
    >>> petersburg = [0.0974, 0.1352, 0.0817, 0.1016, 0.0968, 0.1064, 0.105]
    >>> magadan = [0.1033, 0.0915, 0.0781, 0.0685, 0.0677, 0.0697, 0.0764,
    ...            0.0689]
    >>> tvarminne = [0.0703, 0.1026, 0.0956, 0.0973, 0.1039, 0.1045]
    >>> stats.f_oneway(tillamook, newport, petersburg, magadan, tvarminne)
    (7.1210194716424473, 0.00028122423145345439)

    Ro   i    i   (   RP   R   R   R   t   concatenateRu   t   _sum_of_squarest   _square_of_sumst   specialt   fdtrcRz  (   RE  RH  t
   num_groupst   alldatat   bignt   offsett   sstott   ssbnRT   t   sswnt   dfbnt   dfwnt   msbt   mswt   ft   prob(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR6   1  s&    F(
"





c         C` s1  t  j |   }  t  j |  } t |   } |  j   } | j   } |  | | | } } t  j j | |  } t  j t |  t |   } | | }	 t t	 |	 d  d  }	 | d }
 t
 |	  d k r d } nT |	 d |
 d |	 d |	 } t j d |
 d t  j t  j |
 |
 |  d   } |	 | f S(   sk  
    Calculate a Pearson correlation coefficient and the p-value for testing
    non-correlation.

    The Pearson correlation coefficient measures the linear relationship
    between two datasets. Strictly speaking, Pearson's correlation requires
    that each dataset be normally distributed, and not necessarily zero-mean.
    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. Positive correlations imply that as x increases, so
    does y. Negative correlations imply that as x increases, y decreases.

    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. The p-values are not entirely
    reliable but are probably reasonable for datasets larger than 500 or so.

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

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

    Notes
    -----

    The correlation coefficient is calculated as follows:

    .. math::

        r_{pb} = \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 :math:`x` and :math:`m_y` is
    the mean of the vector :math:`y`.


    References
    ----------
    http://www.statsoft.com/textbook/glosp.html#Pearson%20Correlation

    Examples
    --------
    >>> from scipy import stats
    >>> a = np.array([0, 0, 0, 1, 1, 1, 1])
    >>> b = np.arange(7)
    >>> stats.pearsonr(a, b)
    (0.8660254037844386, 0.011724811003954654)

    >>> stats.pearsonr([1,2,3,4,5], [5,6,7,8,7])
    (0.83205029433784372, 0.080509573298498519)
    g      ?g      i   g        g      ?(   RP   R   R   Ru   R  R   R   R|  R   R   R   R~  t   betainct   fmin(   R   R   R   t   mxt   myt   xmt   ymt   r_numt   r_dent   rt   dfR  t	   t_squared(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR7     s"    >

	0s	   two-sidedc         ` s  t  j  t j |  d t j } | j d k s? t d   n  t j | d k   rc t d   n  d | j d d  k s d | j d d  k r t j	 d f S| d d k r | d d k r | d | d | d | d } n	 t j
 } | d | d } | d | d } | d | d }      f d	   } | d
 k rk j | d | | | |  } n| d k r j | d | | | | d  | d!  } n| d k rwt | d | d | | d    j | d" | | | |    j  | | | |  }	 d#   t j  |	  t j  |	  d   k rO| d f S| d$  k  r j | d% | | | |  }
  j | | | | |     k r| |
 f S| | | | d  } |
  j | d | | | |  } q j | d& d | | | |  }  j d | | | |     k r?| | f S| | | | d  } |  j | | | | |  } n d } t |   t | d  } | | f S('   s  Performs a Fisher exact test on a 2x2 contingency table.

    Parameters
    ----------
    table : array_like of ints
        A 2x2 contingency table.  Elements should be non-negative integers.
    alternative : {'two-sided', 'less', 'greater'}, optional
        Which alternative hypothesis to the null hypothesis the test uses.
        Default is 'two-sided'.

    Returns
    -------
    oddsratio : float
        This is prior odds ratio and not a posterior estimate.
    p_value : float
        P-value, the probability of obtaining a distribution at least as
        extreme as the one that was actually observed, assuming that the
        null hypothesis is true.

    See Also
    --------
    chi2_contingency : Chi-square test of independence of variables in a
        contingency table.

    Notes
    -----
    The calculated odds ratio is different from the one R uses. This scipy
    implementation returns the (more common) "unconditional Maximum
    Likelihood Estimate", while R uses the "conditional Maximum Likelihood
    Estimate".

    For tables with large numbers, the (inexact) chi-square test implemented
    in the function `chi2_contingency` can also be used.

    Examples
    --------
    Say we spend a few days counting whales and sharks in the Atlantic and
    Indian oceans. In the Atlantic ocean we find 8 whales and 1 shark, in the
    Indian ocean 2 whales and 5 sharks. Then our contingency table is::

                Atlantic  Indian
        whales     8        2
        sharks     1        5

    We use this table to find the p-value:

    >>> import scipy.stats as stats
    >>> oddsratio, pvalue = stats.fisher_exact([[8, 2], [1, 5]])
    >>> pvalue
    0.0349...

    The probability that we would observe this or an even more imbalanced ratio
    by chance is about 3.5%.  A commonly used significance level is 5%--if we
    adopt that, we can therefore conclude that our observed imbalance is
    statistically significant; whales prefer the Atlantic while sharks prefer
    the Indian ocean.

    Ro   i   s*   The input `table` must be of shape (2, 2).i    s*   All values in `table` must be nonnegative.RU   i   g      ?c   	      ` s#  | d k r  } |  } n d }  } d } x | | d k r| | d k re | | k re | } n | | d }  j  | | | | |   } | d k r | d } n
 | d } |  k o  j  | | | | |   k  n r Pq0 |  k  r | } q0 | } q0 W| d k r| } n  | d k rx@ | d k rj j  | | | | |      k  rj| d 8} q+Wx  j  | | | | |      k r| d 7} qnWnz x4  j  | | | | |      k  r| d 7} qWx@ | d k r j  | | | | |      k r| d 8} qW| S(   sW   Binary search for where to begin lower/upper halves in two-sided
        test.
        Rk  i    ii   i   (   t   pmf(	   R   t   n1t   n2t   sidet   minvalt   maxvalt   guesst   pguesst   ng(   t   epsilont	   hypergeomR   t   pexact(    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   binary_search@  s>    		
2	
	5))5t   lesst   greaters	   two-sidedg-C6?Rk  R  s?   `alternative` should be one of {'two-sided', 'less', 'greater'}(   i   i   (   i   i    (   i    i   (   i    i    (   i   i   (   i   i    (   i    i   (   i    i    (   i    i   (   i   i    (   i   i   (   i    i    (   i   i    (   i    i    (   i    i   (   i    i   (   i   i   (   i    i    gH.?(   i    i    (   i    i    (   i    i    (   R   R  RP   R   t   int64Ry   Ra   R   Re   R   t   infR  R   R  R   R   R   R   (   t   tablet   alternativeRn  t	   oddsratioR  R  R   R  R   t   pmodet   plowerR  t   pupperR   (    (   R  R  R   R  s0   lib/python2.7/site-packages/scipy/stats/stats.pyR8     sR    ;	0 %	)#/$ -
 &
'$&
#t   SpearmanrResultt   correlationc         C` s  t  |  |  \ }  } |  j d k r3 t d   n  | d k r` |  j d k  r t d   q nN t  | |  \ } } | d k r t j |  | f  }  n t j |  | f  }  |  j d | } |  j | } | d k r t t j	 t j	  St
 |  |  \ } } t j | d t }	 | r| d k r@t j |  d | d	 | S| d
 k r|  j d k sg| d k rzt t j	 t j	  St j |   j d |  }	 qn  t j t | |   }
 t j |
 d | } | d } t j d d  } z0 | t j | | d d | j d   } Wd t j |   Xd t j j t j |  |  } | j d k rht | d | d  St j	 | |	 d d  f <t j	 | d d  |	 f <t | |  Sd S(   s  
    Calculate a Spearman rank-order correlation coefficient and the p-value
    to test for non-correlation.

    The Spearman correlation is a nonparametric measure of the monotonicity
    of the 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 an exact monotonic relationship. Positive correlations imply that
    as x increases, so does y. Negative correlations imply that as x
    increases, y decreases.

    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
    ----------
    a, b : 1D or 2D array_like, b 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.
        Both arrays need to have the same length in the ``axis`` dimension.
    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'.

    Returns
    -------
    correlation : 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 two-sided p-value for a hypothesis test whose null hypothesis is
        that two sets of data are uncorrelated, has same dimension as rho.

    References
    ----------

    .. [1] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
       Probability and Statistics Tables and Formulae. Chapman & Hall: New
       York. 2000.
       Section  14.7

    Examples
    --------
    >>> from scipy import stats
    >>> stats.spearmanr([1,2,3,4,5], [5,6,7,8,7])
    (0.82078268166812329, 0.088587005313543798)
    >>> np.random.seed(1234321)
    >>> x2n = np.random.randn(100, 2)
    >>> y2n = np.random.randn(100, 2)
    >>> stats.spearmanr(x2n)
    (0.059969996999699973, 0.55338590803773591)
    >>> stats.spearmanr(x2n[:,0], x2n[:,1])
    (0.059969996999699973, 0.55338590803773591)
    >>> rho, pval = stats.spearmanr(x2n, y2n)
    >>> rho
    array([[ 1.        ,  0.05997   ,  0.18569457,  0.06258626],
           [ 0.05997   ,  1.        ,  0.110003  ,  0.02534653],
           [ 0.18569457,  0.110003  ,  1.        ,  0.03488749],
           [ 0.06258626,  0.02534653,  0.03488749,  1.        ]])
    >>> pval
    array([[ 0.        ,  0.55338591,  0.06435364,  0.53617935],
           [ 0.55338591,  0.        ,  0.27592895,  0.80234077],
           [ 0.06435364,  0.27592895,  0.        ,  0.73039992],
           [ 0.53617935,  0.80234077,  0.73039992,  0.        ]])
    >>> rho, pval = stats.spearmanr(x2n.T, y2n.T, axis=1)
    >>> rho
    array([[ 1.        ,  0.05997   ,  0.18569457,  0.06258626],
           [ 0.05997   ,  1.        ,  0.110003  ,  0.02534653],
           [ 0.18569457,  0.110003  ,  1.        ,  0.03488749],
           [ 0.06258626,  0.02534653,  0.03488749,  1.        ]])
    >>> stats.spearmanr(x2n, y2n, axis=None)
    (0.10816770419260482, 0.1273562188027364)
    >>> stats.spearmanr(x2n.ravel(), y2n.ravel())
    (0.10816770419260482, 0.1273562188027364)

    >>> xint = np.random.randint(10, size=(100, 2))
    >>> stats.spearmanr(xint)
    (0.052760927029710199, 0.60213045837062351)

    i   s(   spearmanr only handles 1-D or 2-D arrayss1   `spearmanr` needs at least 2 variables to comparei    i   Ro   R\   RU   Rk   RZ   t   rowvart   divideR`   g      ?N(   i   i   (   i   i    (   i   i    (   RW   RR   Ra   RO   RP   t   column_stackt	   row_stackRy   R  R   Rn   R   t   boolR   R9   Rd   Re   t   apply_along_axisRJ   t   corrcoefR   R   t   clipR   RK  R   R   (   RT   RX   RU   Rk   t   axisoutR   t   n_varst   n_obst   a_contains_nant   variable_has_nant   a_rankedt   rst   dofR   RK  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR9     sH    _!
0"t   PointbiserialrResultc         C` s"   t  |  |  \ } } t | |  S(   s  
    Calculate a point biserial correlation coefficient and its p-value.

    The point biserial correlation is used to measure the relationship
    between a binary variable, x, and a continuous variable, y. Like other
    correlation coefficients, this one varies between -1 and +1 with 0
    implying no correlation. Correlations of -1 or +1 imply a determinative
    relationship.

    This function uses a shortcut formula but produces the same result as
    `pearsonr`.

    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
    -----
    `pointbiserialr` uses a t-test with ``n-1`` degrees of freedom.
    It is equivalent to `pearsonr.`

    The value of the point-biserial correlation can be calculated from:

    .. math::

        r_{pb} = \frac{\overline{Y_{1}} -
                 \overline{Y_{0}}}{s_{y}}\sqrt{\frac{N_{1} N_{2}}{N (N - 1))}}

    Where :math:`Y_{0}` and :math:`Y_{1}` are means of the metric
    observations coded 0 and 1 respectively; :math:`N_{0}` and :math:`N_{1}`
    are number of observations coded 0 and 1 respectively; :math:`N` is the
    total number of observations and :math:`s_{y}` is the standard
    deviation of all the metric observations.

    A value of :math:`r_{pb}` that is significantly different from zero is
    completely equivalent to a significant difference in means between the two
    groups. Thus, an independent groups t Test with :math:`N-2` degrees of
    freedom may be used to test whether :math:`r_{pb}` is nonzero. The
    relation between the t-statistic for comparing two independent groups and
    :math:`r_{pb}` is given by:

    .. math::

        t = \sqrt{N - 2}\frac{r_{pb}}{\sqrt{1 - r^{2}_{pb}}}

    References
    ----------
    .. [1] J. Lev, "The Point Biserial Coefficient of Correlation", Ann. Math.
           Statist., Vol. 20, no.1, pp. 125-126, 1949.

    .. [2] R.F. Tate, "Correlation Between a Discrete and a Continuous
           Variable. Point-Biserial Correlation.", Ann. Math. Statist., Vol. 25,
           np. 3, pp. 603-607, 1954.

    .. [3] D. Kornbrot "Point Biserial Correlation", In Wiley StatsRef:
           Statistics Reference Online (eds N. Balakrishnan, et al.), 2014.
           https://doi.org/10.1002/9781118445112.stat06227

    Examples
    --------
    >>> from scipy import stats
    >>> a = np.array([0, 0, 0, 1, 1, 1, 1])
    >>> b = np.arange(7)
    >>> stats.pointbiserialr(a, b)
    (0.8660254037844386, 0.011724811003954652)
    >>> stats.pearsonr(a, b)
    (0.86602540378443871, 0.011724811003954626)
    >>> np.corrcoef(a, b)
    array([[ 1.       ,  0.8660254],
           [ 0.8660254,  1.       ]])

    (   R7   R  (   R   R   t   rpbR  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR:   /  s    St   KendalltauResultt   autoc   !   	   C` s  t  j |   j   }  t  j |  j   } |  j | j k r[ t d |  j | j f   n' |  j so | j r t t  j t  j  St |  |  \ } } t | |  \ } } | p | }	 | d k s | d k r d } n  |	 r | d k r t t  j t  j  S|	 rD| d k rDt j	 |   }  t j	 |  } t
 j |  | d | S| d k	 r`t j d  n  d   }
 |  j } t  j |  } |  | | | }  } t  j t | d | d  k f j d	 t  j  } t  j |  d
 d } |  | | | }  } t  j t |  d |  d  k f j d	 t  j  }  t |  |  } t  j t |  d |  d  k | d | d  k Bt f } t  j t  j |  d  j d d t } | | d d j   } |
 |   \ } } } |
 |  \ } } } | | d d } | | k s| | k rt t  j t  j  S| | | | d | } | t  j | |  t  j | |  } t d t d |   } | d k r| d k s| d k rt d   n  | d k r| d k r| d k r| d k st | | |  d k rd } qd } n  | d k r| d k r| d k rt | | |  } | d k rCt  q| d k  sgd | | | d k rpt  q| d k rd } q| d k rd } q| d k rd t  j j |  } q| d k rd t  j j | d  } qd g | d } d g | d } d | d <d | d <x t d | d  D] } | } x< t d t | | d   D] } | | c | | d 7<q\Wx? t | | d  D]* } | | c | | d | | | 7<qWq2Wd t |  t  j j |  } n | d k r| | d d | d | | d d | | | | d | | d | | d | d }  t  j! t  j" |  t  j |   t  j d   } n t d t# |  d   t | |  S(    s  
    Calculate Kendall's tau, a correlation measure for ordinal data.

    Kendall's tau is a measure of the correspondence between two rankings.
    Values close to 1 indicate strong agreement, values close to -1 indicate
    strong disagreement.  This is the 1945 "tau-b" version of Kendall's
    tau [2]_, which can account for ties and which reduces to the 1938 "tau-a"
    version [1]_ in absence of ties.

    Parameters
    ----------
    x, y : array_like
        Arrays of rankings, of the same shape. If arrays are not 1-D, they will
        be flattened to 1-D.
    initial_lexsort : bool, optional
        Unused (deprecated).
    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'. Note that if the input contains nan
        'omit' delegates to mstats_basic.kendalltau(), which has a different
        implementation.
    method: {'auto', 'asymptotic', 'exact'}, optional
        Defines which method is used to calculate the p-value [5]_.
        '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. 'auto' is the default and selects the appropriate
        method based on a trade-off between speed and accuracy.

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

    See also
    --------
    spearmanr : Calculates a Spearman rank-order correlation coefficient.
    theilslopes : Computes the Theil-Sen estimator for a set of points (x, y).
    weightedtau : Computes a weighted version of Kendall's tau.

    Notes
    -----
    The definition of Kendall's tau that is used is [2]_::

      tau = (P - Q) / sqrt((P + Q + T) * (P + Q + U))

    where P is the number of concordant pairs, Q the number of discordant
    pairs, T the number of ties only in `x`, and U the number of ties only in
    `y`.  If a tie occurs for the same pair in both `x` and `y`, it is not
    added to either T or U.

    References
    ----------
    .. [1] Maurice G. Kendall, "A New Measure of Rank Correlation", Biometrika
           Vol. 30, No. 1/2, pp. 81-93, 1938.
    .. [2] Maurice G. Kendall, "The treatment of ties in ranking problems",
           Biometrika Vol. 33, No. 3, pp. 239-251. 1945.
    .. [3] Gottfried E. Noether, "Elements of Nonparametric Statistics", John
           Wiley & Sons, 1967.
    .. [4] Peter M. Fenwick, "A new data structure for cumulative frequency
           tables", Software: Practice and Experience, Vol. 24, No. 3,
           pp. 327-336, 1994.
    .. [5] Maurice G. Kendall, "Rank Correlation Methods" (4th Edition),
           Charles Griffin & Co., 1970.

    Examples
    --------
    >>> from scipy import stats
    >>> x1 = [12, 2, 1, 12, 2]
    >>> x2 = [1, 4, 7, 1, 0]
    >>> tau, p_value = stats.kendalltau(x1, x2)
    >>> tau
    -0.47140452079103173
    >>> p_value
    0.2827454599327748

    sR   All inputs to `kendalltau` must be of the same size, found x-size %s and y-size %sR\   RZ   t   methods   "initial_lexsort" is gone!c         S` s}   t  j |   j d d t } | | d k } | | d d j   | | d | d j   | | d d | d j   f S(   NR  R   i   i   g      ?i   (   RP   R
  R   Rg   Re   (   t   rankst   cnt(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   count_rank_tie  s
    i   iRo   R'  t	   mergesorti    R  R   i   g      ?g      t   exacts(   Ties found, exact method cannot be used.R  i!   t
   asymptoticg       @g        i   i   g      2@g      "@s   Unknown method s1    specified, please use auto, exact or asymptotic.N($   RP   R   RQ   Rz   Ra   R  R   Rn   R   R   R   R;   RO   Rh   Ri   t   argsortt   r_R~   R:  t   intpR   t   difft   nonzeroR   Rg   Re   R   R   R   R   t	   factorialR   R~  t   erfcR   t   str(!   R   R   t   initial_lexsortRk   R  t   cnxt   npxt   cnyt   npyRm   R  Rz   t   permt   dist   obsR  t   ntiet   xtiet   x0t   x1t   ytiet   y0t   y1t   tott   con_minus_dist   tauRn  R   t   oldt   newR!  R  R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR;     s    Q			006+($=		$	$			

#,#B5t   WeightedTauResultc         C` sG  t  j |   j   }  t  j |  j   } |  j | j k r[ t d |  j | j f   n  |  j sw t t  j t  j  St  j t  j |    r t	 |   }  n  t  j t  j |    r t	 |  } n  |  j
 | j
 k r|  j
 t  j k r t	 |   }  n  | j
 t  j k r^t	 |  } q^nB |  j
 t  j t  j t  j t  j f k r^t	 |   }  t	 |  } n  | t k rt t |  | d | |  t | |  d | |  d t  j  S| t k rt  j |  j d t  j } nU | d k	 r%t  j |  j   } | j |  j k r%t d |  j | j f   q%n  t t |  | | | |  t  j  S(   s9  
    Compute a weighted version of Kendall's :math:`\tau`.

    The weighted :math:`\tau` is a weighted version of Kendall's
    :math:`\tau` in which exchanges of high weight are more influential than
    exchanges of low weight. The default parameters compute the additive
    hyperbolic version of the index, :math:`\tau_\mathrm h`, which has
    been shown to provide the best balance between important and
    unimportant elements [1]_.

    The weighting is defined by means of a rank array, which assigns a
    nonnegative rank to each element, and a weigher function, which
    assigns a weight based from the rank to each element. The weight of an
    exchange is then the sum or the product of the weights of the ranks of
    the exchanged elements. The default parameters compute
    :math:`\tau_\mathrm h`: an exchange between elements with rank
    :math:`r` and :math:`s` (starting from zero) has weight
    :math:`1/(r+1) + 1/(s+1)`.

    Specifying a rank array is meaningful only if you have in mind an
    external criterion of importance. If, as it usually happens, you do
    not have in mind a specific rank, the weighted :math:`\tau` is
    defined by averaging the values obtained using the decreasing
    lexicographical rank by (`x`, `y`) and by (`y`, `x`). This is the
    behavior with default parameters.

    Note that if you are computing the weighted :math:`\tau` on arrays of
    ranks, rather than of scores (i.e., a larger value implies a lower
    rank) you must negate the ranks, so that elements of higher rank are
    associated with a larger value.

    Parameters
    ----------
    x, y : array_like
        Arrays of scores, of the same shape. If arrays are not 1-D, they will
        be flattened to 1-D.
    rank: array_like of ints or bool, optional
        A nonnegative rank assigned to each element. If it is None, the
        decreasing lexicographical rank by (`x`, `y`) will be used: elements of
        higher rank will be those with larger `x`-values, using `y`-values to
        break ties (in particular, swapping `x` and `y` will give a different
        result). If it is False, the element indices will be used
        directly as ranks. The default is True, in which case this
        function returns the average of the values obtained using the
        decreasing lexicographical rank by (`x`, `y`) and by (`y`, `x`).
    weigher : callable, optional
        The weigher function. Must map nonnegative integers (zero
        representing the most important element) to a nonnegative weight.
        The default, None, provides hyperbolic weighing, that is,
        rank :math:`r` is mapped to weight :math:`1/(r+1)`.
    additive : bool, optional
        If True, the weight of an exchange is computed by adding the
        weights of the ranks of the exchanged elements; otherwise, the weights
        are multiplied. The default is True.

    Returns
    -------
    correlation : float
       The weighted :math:`\tau` correlation index.
    pvalue : float
       Presently ``np.nan``, as the null statistics is unknown (even in the
       additive hyperbolic case).

    See also
    --------
    kendalltau : Calculates Kendall's tau.
    spearmanr : Calculates a Spearman rank-order correlation coefficient.
    theilslopes : Computes the Theil-Sen estimator for a set of points (x, y).

    Notes
    -----
    This function uses an :math:`O(n \log n)`, mergesort-based algorithm
    [1]_ that is a weighted extension of Knight's algorithm for Kendall's
    :math:`\tau` [2]_. It can compute Shieh's weighted :math:`\tau` [3]_
    between rankings without ties (i.e., permutations) by setting
    `additive` and `rank` to False, as the definition given in [1]_ is a
    generalization of Shieh's.

    NaNs are considered the smallest possible score.

    .. versionadded:: 0.19.0

    References
    ----------
    .. [1] Sebastiano Vigna, "A weighted correlation index for rankings with
           ties", Proceedings of the 24th international conference on World
           Wide Web, pp. 1166-1176, ACM, 2015.
    .. [2] W.R. Knight, "A Computer Method for Calculating Kendall's Tau with
           Ungrouped Data", Journal of the American Statistical Association,
           Vol. 61, No. 314, Part 1, pp. 436-439, 1966.
    .. [3] Grace S. Shieh. "A weighted Kendall's tau statistic", Statistics &
           Probability Letters, Vol. 39, No. 1, pp. 17-24, 1998.

    Examples
    --------
    >>> from scipy import stats
    >>> x = [12, 2, 1, 12, 2]
    >>> y = [1, 4, 7, 1, 0]
    >>> tau, p_value = stats.weightedtau(x, y)
    >>> tau
    -0.56694968153682723
    >>> p_value
    nan
    >>> tau, p_value = stats.weightedtau(x, y, additive=False)
    >>> tau
    -0.62205716951801038

    NaNs are considered the smallest possible score:

    >>> x = [12, 2, 1, 12, 2]
    >>> y = [1, 4, 7, 1, np.nan]
    >>> tau, _ = stats.weightedtau(x, y)
    >>> tau
    -0.56694968153682723

    This is exactly Kendall's tau:

    >>> x = [12, 2, 1, 12, 2]
    >>> y = [1, 4, 7, 1, 0]
    >>> tau, _ = stats.weightedtau(x, y, weigher=lambda x: 1)
    >>> tau
    -0.47140452079103173

    >>> x = [12, 2, 1, 12, 2]
    >>> y = [1, 4, 7, 1, 0]
    >>> stats.weightedtau(x, y, rank=None)
    WeightedTauResult(correlation=-0.4157652301037516, pvalue=nan)
    >>> stats.weightedtau(y, x, rank=None)
    WeightedTauResult(correlation=-0.7181341329699028, pvalue=nan)

    sS   All inputs to `weightedtau` must be of the same size, found x-size %s and y-size %si   Ro   sV   All inputs to `weightedtau` must be of the same size, found x-size %s and rank-size %sN(   RP   R   RQ   Rz   Ra   R  R   Rd   Re   R   Ro   R  t   int32t   float32R   R~   R   RO   Rg   t   arangeR  (   R   R   R#  t   weighert   additive(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR<   O  s@    	't   Ttest_1sampResultc         C` s	  t  |  |  \ }  } t |  |  \ } } | r^ | d k r^ t j |   }  t j |  | |  S|  j | } | d } t j |  |  | } t j	 |  | d d } t j
 | |  }	 t j d d d d   t j | |	  }
 Wd QXt | |
  \ }
 } t |
 |  S(   sg  
    Calculate the T-test for the mean of ONE group of scores.

    This is a two-sided test for the null hypothesis that the expected value
    (mean) of a sample of independent observations `a` is equal to the given
    population mean, `popmean`.

    Parameters
    ----------
    a : array_like
        sample observation
    popmean : float or array_like
        expected value in null hypothesis. If array_like, then 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`.
    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'.

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

    Examples
    --------
    >>> from scipy import stats

    >>> np.random.seed(7654567)  # fix seed to get the same result
    >>> rvs = stats.norm.rvs(loc=5, scale=10, size=(50,2))

    Test if mean of random sample is equal to true mean, and different mean.
    We reject the null hypothesis in the second case and don't reject it in
    the first case.

    >>> stats.ttest_1samp(rvs,5.0)
    (array([-0.68014479, -0.04323899]), array([ 0.49961383,  0.96568674]))
    >>> stats.ttest_1samp(rvs,0.0)
    (array([ 2.77025808,  4.11038784]), array([ 0.00789095,  0.00014999]))

    Examples using axis and non-scalar dimension for population mean.

    >>> stats.ttest_1samp(rvs,[5.0,0.0])
    (array([-0.68014479,  4.11038784]), array([  4.99613833e-01,   1.49986458e-04]))
    >>> stats.ttest_1samp(rvs.T,[5.0,0.0],axis=1)
    (array([-0.68014479,  4.11038784]), array([  4.99613833e-01,   1.49986458e-04]))
    >>> stats.ttest_1samp(rvs,[[5.0],[0.0]])
    (array([[-0.68014479, -0.04323899],
           [ 2.77025808,  4.11038784]]), array([[  4.99613833e-01,   9.65686743e-01],
           [  7.89094663e-03,   1.49986458e-04]]))

    R\   i   R   R  R`   R_   N(   RW   Rn   R   R   R   R=   Ry   RP   Ru   R   R   Rc   R  t   _ttest_finishR  (   RT   t   popmeanRU   Rk   Rm   R   R  t   dR   R   RK  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR=     s    :
c         C` sH   t  j j t j |  |   d } | j d k r> | d } n  | | f S(   s+   Common code between all 3 t-test functions.i   i    (    (   R   RK  R   RP   R   RR   (   R  RK  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR  U  s    "c         C` sZ   |  | } t  j d d d d   t  j | |  } Wd  QXt | |  \ } } | | f S(   NR  R`   R_   (   RP   Rc   R  R  (   t   mean1t   mean2R   R  R  RK  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _ttest_ind_from_stats^  s
    
c      	   C` s   |  | } | | } t  j d d d d  3 | | d | d | d | d | d } Wd  QXt  j t  j |  d |  } t  j | |  } | | f S(   NR  R`   R_   i   i   (   RP   Rc   R   Rd   R   (   t   v1R  t   v2R  t   vn1t   vn2R  R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _unequal_var_ttest_denomh  s    

4c         C` sU   | | d } | d |  | d | | } t  j | d | d |  } | | f S(   Ng       @i   g      ?(   RP   R   (   R  R  R  R  R  t   svarR   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _equal_var_ttest_denomu  s    t   Ttest_indResultc   
      C` sn   | r, t  | d | | d |  \ } } n# t | d | | d |  \ } } t |  | | |  }	 t |	   S(   si	  
    T-test for means of two independent samples from descriptive statistics.

    This is a two-sided test for the null hypothesis that two independent
    samples have identical average (expected) values.

    Parameters
    ----------
    mean1 : array_like
        The mean(s) of sample 1.
    std1 : array_like
        The standard deviation(s) of sample 1.
    nobs1 : array_like
        The number(s) of observations of sample 1.
    mean2 : array_like
        The mean(s) of sample 2
    std2 : array_like
        The standard deviations(s) of sample 2.
    nobs2 : array_like
        The number(s) of observations of sample 2.
    equal_var : bool, optional
        If True (default), perform a standard independent 2 sample test
        that assumes equal population variances [1]_.
        If False, perform Welch's t-test, which does not assume equal
        population variance [2]_.

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

    See Also
    --------
    scipy.stats.ttest_ind

    Notes
    -----

    .. versionadded:: 0.16.0

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/T-test#Independent_two-sample_t-test

    .. [2] https://en.wikipedia.org/wiki/Welch%27s_t-test

    Examples
    --------
    Suppose we have the summary data for two samples, as follows::

                         Sample   Sample
                   Size   Mean   Variance
        Sample 1    13    15.0     87.5
        Sample 2    11    12.0     39.0

    Apply the t-test to this data (with the assumption that the population
    variances are equal):

    >>> from scipy.stats import ttest_ind_from_stats
    >>> ttest_ind_from_stats(mean1=15.0, std1=np.sqrt(87.5), nobs1=13,
    ...                      mean2=12.0, std2=np.sqrt(39.0), nobs2=11)
    Ttest_indResult(statistic=0.9051358093310269, pvalue=0.3751996797581487)

    For comparison, here is the data from which those summary statistics
    were taken.  With this data, we can compute the same result using
    `scipy.stats.ttest_ind`:

    >>> a = np.array([1, 3, 4, 6, 11, 13, 15, 19, 22, 24, 25, 26, 26])
    >>> b = np.array([2, 4, 6, 9, 11, 13, 14, 15, 18, 19, 21])
    >>> from scipy.stats import ttest_ind
    >>> ttest_ind(a, b)
    Ttest_indResult(statistic=0.905135809331027, pvalue=0.3751996797581486)

    i   (   R  R  R  R  (
   R  t   std1t   nobs1R  t   std2t   nobs2t	   equal_varR  R   R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR?     s    N&c         C` s  t  |  | |  \ }  } } t |  |  \ } } t | |  \ } } | pN | }	 | d k si | d k rr d } n  |	 r | d k r t j |   }  t j |  } t j |  | | |  S|  j d k s | j d k r t t j	 t j	  St j
 |  | d d }
 t j
 | | d d } |  j | } | j | } | rWt |
 | | |  \ } } n t |
 | | |  \ } } t t j |  |  t j | |  | |  } t |   S(   sc  
    Calculate the T-test for the means of *two independent* samples of scores.

    This is a two-sided test for the null hypothesis that 2 independent samples
    have identical average (expected) values. This test assumes that the
    populations have identical variances by default.

    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 (default), perform a standard independent 2 sample test
        that assumes equal population variances [1]_.
        If False, perform Welch's t-test, which does not assume equal
        population variance [2]_.

        .. versionadded:: 0.11.0
    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'.


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

    Notes
    -----
    We can use this test, if we observe two independent samples from
    the same or different population, e.g. exam scores of boys and
    girls or of two ethnic groups. The test measures whether the
    average (expected) value differs significantly across samples. If
    we observe a large p-value, for example larger than 0.05 or 0.1,
    then we cannot reject the null hypothesis of identical average scores.
    If the p-value is smaller than the threshold, e.g. 1%, 5% or 10%,
    then we reject the null hypothesis of equal averages.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/T-test#Independent_two-sample_t-test

    .. [2] https://en.wikipedia.org/wiki/Welch%27s_t-test

    Examples
    --------
    >>> from scipy import stats
    >>> np.random.seed(12345678)

    Test with sample with identical means:

    >>> rvs1 = stats.norm.rvs(loc=5,scale=10,size=500)
    >>> rvs2 = stats.norm.rvs(loc=5,scale=10,size=500)
    >>> stats.ttest_ind(rvs1,rvs2)
    (0.26833823296239279, 0.78849443369564776)
    >>> stats.ttest_ind(rvs1,rvs2, equal_var = False)
    (0.26833823296239279, 0.78849452749500748)

    `ttest_ind` underestimates p for unequal variances:

    >>> rvs3 = stats.norm.rvs(loc=5, scale=20, size=500)
    >>> stats.ttest_ind(rvs1, rvs3)
    (-0.46580283298287162, 0.64145827413436174)
    >>> stats.ttest_ind(rvs1, rvs3, equal_var = False)
    (-0.46580283298287162, 0.64149646246569292)

    When n1 != n2, the equal variance t-statistic is no longer equal to the
    unequal variance t-statistic:

    >>> rvs4 = stats.norm.rvs(loc=5, scale=20, size=100)
    >>> stats.ttest_ind(rvs1, rvs4)
    (-0.99882539442782481, 0.3182832709103896)
    >>> stats.ttest_ind(rvs1, rvs4, equal_var = False)
    (-0.69712570584654099, 0.48716927725402048)

    T-test with different means, variance, and n:

    >>> rvs5 = stats.norm.rvs(loc=8, scale=20, size=100)
    >>> stats.ttest_ind(rvs1, rvs5)
    (-1.4679669854490653, 0.14263895620529152)
    >>> stats.ttest_ind(rvs1, rvs5, equal_var = False)
    (-0.94365973617132992, 0.34744170334794122)

    R\   i    R   i   (   RY   Rn   R   R   R   R>   Rz   R  RP   R   R   Ry   R  R  R  Ru   (   RT   RX   RU   R  Rk   t   cnat   npat   cnbt   npbRm   R  R  R  R  R  R   R   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR>     s*    ]	-t   Ttest_relResultc         C` s#  t  |  | |  \ }  } } t |  |  \ } } t | |  \ } } | pN | } | d k si | d k rr d } n  | r| d k rt j |   }  t j |  } t j t j |   t j |   }	 t j |  d |	 d t }
 t j | d |	 d t } t j	 |
 | |  S|  j
 | | j
 | k r8t d   n  |  j d k sV| j d k rft j t j f S|  j
 | } | d } |  | j t j  } t j | | d d } t j | |  } t j | |  } t j d d	 d
 d	   t j | |  } Wd QXt | |  \ } } t | |  S(   s5  
    Calculate the T-test on TWO RELATED samples of scores, a and b.

    This is a two-sided test for the null hypothesis that 2 related or
    repeated samples have identical average (expected) values.

    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`.
    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'.

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

    Notes
    -----
    Examples for the use are scores of the same set of student in
    different exams, or repeated sampling from the same units. The
    test measures whether the average score differs significantly
    across samples (e.g. exams). If we observe a large p-value, for
    example greater than 0.05 or 0.1 then we cannot reject the null
    hypothesis of identical average scores. If the p-value is smaller
    than the threshold, e.g. 1%, 5% or 10%, then we reject the null
    hypothesis of equal averages. Small p-values are associated with
    large t-statistics.

    References
    ----------
    https://en.wikipedia.org/wiki/T-test#Dependent_t-test_for_paired_samples

    Examples
    --------
    >>> from scipy import stats
    >>> np.random.seed(12345678) # fix random seed to get same numbers

    >>> rvs1 = stats.norm.rvs(loc=5,scale=10,size=500)
    >>> rvs2 = (stats.norm.rvs(loc=5,scale=10,size=500) +
    ...         stats.norm.rvs(scale=0.2,size=500))
    >>> stats.ttest_rel(rvs1,rvs2)
    (0.24101764965300962, 0.80964043445811562)
    >>> rvs3 = (stats.norm.rvs(loc=8,scale=10,size=500) +
    ...         stats.norm.rvs(scale=0.2,size=500))
    >>> stats.ttest_rel(rvs1,rvs3)
    (-3.9995108708727933, 7.3082402191726459e-005)

    R\   t   maskR   s   unequal length arraysi    i   R   R  R`   R_   N(   RY   Rn   R   R   t   mask_ort   getmaskR   R~   R   R@   Ry   Ra   Rz   RP   R   R   R   R   Ru   R   Rc   R  R  R  (   RT   RX   RU   Rk   R  R  R  R  Rm   R   t   aat   bbR   R  R  R   t   dmR   RK  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR@   W  s6    :	$
t   KstestResulti   t   approxc         C` sz  t  |  t  rX | s" | |  k rI t t |   j } t t |   j }  qX t d   n  t  | t  r| t t |  j } n  t |   r i | d 6} t j	 |  | |    } n t j	 |   } t
 |  } | | |  } | d k r d } n  | d k rJt j d | d  | | j   }	 | d k rJt |	 t j j |	 |   Sn  | d k r| t j d	 |  | j   }
 | d k rt |
 t j j |
 |   Sn  | d k rvt j |	 |
 g  } | d
 k rt | t j j | t j |    S| d k rvt j j | t j |   } | d k sC| d | d d k rPt | |  St | d t j j | |   Sqvn  d S(   s  
    Perform the Kolmogorov-Smirnov test for goodness of fit.

    This performs a test of the distribution G(x) of an observed
    random variable against a given distribution F(x). Under the null
    hypothesis the two distributions are identical, G(x)=F(x). The
    alternative hypothesis can be either 'two-sided' (default), 'less'
    or 'greater'. The KS test is only valid for continuous distributions.

    Parameters
    ----------
    rvs : str, array or callable
        If a string, it should be the name of a distribution in `scipy.stats`.
        If an array, it should be a 1-D array of observations of random
        variables.
        If a callable, it should be a function to generate random variables;
        it is required to have a keyword argument `size`.
    cdf : str or callable
        If a string, it should be the name of a distribution in `scipy.stats`.
        If `rvs` is a string then `cdf` can be False or the same as `rvs`.
        If a callable, that callable is used to calculate the cdf.
    args : tuple, sequence, optional
        Distribution parameters, used if `rvs` or `cdf` are strings.
    N : int, optional
        Sample size if `rvs` is string or callable.  Default is 20.
    alternative : {'two-sided', 'less','greater'}, optional
        Defines the alternative hypothesis (see explanation above).
        Default is 'two-sided'.
    mode : 'approx' (default) or 'asymp', optional
        Defines the distribution used for calculating the p-value.

          - 'approx' : use approximation to exact distribution of test statistic
          - 'asymp' : use asymptotic distribution of test statistic

    Returns
    -------
    statistic : float
        KS test statistic, either D, D+ or D-.
    pvalue :  float
        One-tailed or two-tailed p-value.

    Notes
    -----
    In the one-sided test, the alternative is that the empirical
    cumulative distribution function of the random variable is "less"
    or "greater" than the cumulative distribution function F(x) of the
    hypothesis, ``G(x)<=F(x)``, resp. ``G(x)>=F(x)``.

    Examples
    --------
    >>> from scipy import stats

    >>> x = np.linspace(-15, 15, 9)
    >>> stats.kstest(x, 'norm')
    (0.44435602715924361, 0.038850142705171065)

    >>> np.random.seed(987654321) # set random seed to get the same result
    >>> stats.kstest('norm', False, N=100)
    (0.058352892479417884, 0.88531190944151261)

    The above lines are equivalent to:

    >>> np.random.seed(987654321)
    >>> stats.kstest(stats.norm.rvs(size=100), 'norm')
    (0.058352892479417884, 0.88531190944151261)

    *Test against one-sided alternative hypothesis*

    Shift distribution to larger values, so that ``cdf_dgp(x) < norm.cdf(x)``:

    >>> np.random.seed(987654321)
    >>> x = stats.norm.rvs(loc=0.2, size=100)
    >>> stats.kstest(x,'norm', alternative = 'less')
    (0.12464329735846891, 0.040989164077641749)

    Reject equal distribution against alternative hypothesis: less

    >>> stats.kstest(x,'norm', alternative = 'greater')
    (0.0072115233216311081, 0.98531158590396395)

    Don't reject equal distribution against alternative hypothesis: greater

    >>> stats.kstest(x,'norm', mode='asymp')
    (0.12464329735846891, 0.08944488871182088)

    *Testing t distributed random variables against normal distribution*

    With 100 degrees of freedom the t distribution looks close to the normal
    distribution, and the K-S test does not reject the hypothesis that the
    sample came from the normal distribution:

    >>> np.random.seed(987654321)
    >>> stats.kstest(stats.t.rvs(100,size=100),'norm')
    (0.072018929165471257, 0.67630062862479168)

    With 3 degrees of freedom the t distribution looks sufficiently different
    from the normal distribution, that we can reject the hypothesis that the
    sample came from the normal distribution at the 10% level:

    >>> np.random.seed(987654321)
    >>> stats.kstest(stats.t.rvs(3,size=100),'norm')
    (0.131016895759829, 0.058826222555312224)

    s5   if rvs is string, cdf has to be the same distributionRz   t	   two_sideds	   two-sidedR  g      ?i   R  g        t   asympR  ij
  g?g333333?i  i   N(   s	   two-sidedR  (   s	   two-sidedR  (   Rp   R   t   getattrR   R  t   rvst   AttributeErrorR   RP   R  R   R  R   R  t   ksoneR   t	   kstwobignR   (   R  R  RE  t   NR  R   t   kwdsR   t   cdfvalst   Dplust   Dmint   Dt   pval_two(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRA     s@    i	$ &$t   pearsons   log-likelihoodg      s   freeman-tukeyis   mod-log-likelihoodit   neymani   i   s   cressie-readc         C` s}   t  |  d  rT |  j d |  } t | t j  ry | j d k ry t |  } qy n% | d k rl |  j } n |  j	 | } | S(   s   
    Count the number of non-masked elements of an array.

    This function behaves like np.ma.count(), but is much faster
    for ndarrays.
    Rx   RU   i    N(
   Rh  Rx   Rp   RP   Rq   RR   R   RO   Rz   Ry   (   RT   RU   t   num(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   _countY  s    !t   Power_divergenceResultc         C` s  t  | t  rb | t k rU t t t j     d d !} t d j | |    n  t | } n | d k rw d } n  t	 j
 |   }  | d k	 r t	 j t	 j
 |   } ne t	 j d d    t	 j |  j d |   } Wd QX| d k	 rt |  j  } d | | <| | _ n  | d k r3|  | d | } n~ | d	 k r\d
 t j |  |  |  } nU | d k rd
 t j | | |   } n, |  |  | | d } | d | | d } | j d |  } t | d | }	 t |  } t j j | |	 d |  }
 t | |
  S(   s  
    Cressie-Read power divergence statistic and goodness of fit test.

    This function tests the null hypothesis that the categorical data
    has the given frequencies, using the Cressie-Read power divergence
    statistic.

    Parameters
    ----------
    f_obs : array_like
        Observed frequencies in each category.
    f_exp : array_like, optional
        Expected frequencies in each category.  By default the categories are
        assumed to be equally likely.
    ddof : int, optional
        "Delta degrees of freedom": adjustment to the degrees of freedom
        for the p-value.  The p-value is computed using a chi-squared
        distribution with ``k - 1 - ddof`` degrees of freedom, where `k`
        is the number of observed frequencies.  The default value of `ddof`
        is 0.
    axis : int or None, optional
        The axis of the broadcast result of `f_obs` and `f_exp` along which to
        apply the test.  If axis is None, all values in `f_obs` are treated
        as a single data set.  Default is 0.
    lambda_ : float or str, optional
        `lambda_` gives the power in the Cressie-Read power divergence
        statistic.  The default is 1.  For convenience, `lambda_` may be
        assigned one of the following strings, in which case the
        corresponding numerical value is used::

            String              Value   Description
            "pearson"             1     Pearson's chi-squared statistic.
                                        In this case, the function is
                                        equivalent to `stats.chisquare`.
            "log-likelihood"      0     Log-likelihood ratio. Also known as
                                        the G-test [3]_.
            "freeman-tukey"      -1/2   Freeman-Tukey statistic.
            "mod-log-likelihood" -1     Modified log-likelihood ratio.
            "neyman"             -2     Neyman's statistic.
            "cressie-read"        2/3   The power recommended in [5]_.

    Returns
    -------
    statistic : float or ndarray
        The Cressie-Read power divergence test statistic.  The value is
        a float if `axis` is None or if` `f_obs` and `f_exp` are 1-D.
    pvalue : float or ndarray
        The p-value of the test.  The value is a float if `ddof` and the
        return value `stat` are scalars.

    See Also
    --------
    chisquare

    Notes
    -----
    This test is invalid when the observed or expected frequencies in each
    category are too small.  A typical rule is that all of the observed
    and expected frequencies should be at least 5.

    When `lambda_` is less than zero, the formula for the statistic involves
    dividing by `f_obs`, so a warning or error may be generated if any value
    in `f_obs` is 0.

    Similarly, a warning or error may be generated if any value in `f_exp` is
    zero when `lambda_` >= 0.

    The default degrees of freedom, k-1, are for the case when no parameters
    of the distribution are estimated. If p parameters are estimated by
    efficient maximum likelihood then the correct degrees of freedom are
    k-1-p. If the parameters are estimated in a different way, then the
    dof can be between k-1-p and k-1. However, it is also possible that
    the asymptotic distribution is not a chisquare, in which case this
    test is not appropriate.

    This function handles masked arrays.  If an element of `f_obs` or `f_exp`
    is masked, then data at that position is ignored, and does not count
    towards the size of the data set.

    .. versionadded:: 0.13.0

    References
    ----------
    .. [1] Lowry, Richard.  "Concepts and Applications of Inferential
           Statistics". Chapter 8.
           https://web.archive.org/web/20171015035606/http://faculty.vassar.edu/lowry/ch8pt1.html
    .. [2] "Chi-squared test", https://en.wikipedia.org/wiki/Chi-squared_test
    .. [3] "G-test", https://en.wikipedia.org/wiki/G-test
    .. [4] Sokal, R. R. and Rohlf, F. J. "Biometry: the principles and
           practice of statistics in biological research", New York: Freeman
           (1981)
    .. [5] Cressie, N. and Read, T. R. C., "Multinomial Goodness-of-Fit
           Tests", J. Royal Stat. Soc. Series B, Vol. 46, No. 3 (1984),
           pp. 440-464.

    Examples
    --------

    (See `chisquare` for more examples.)

    When just `f_obs` is given, it is assumed that the expected frequencies
    are uniform and given by the mean of the observed frequencies.  Here we
    perform a G-test (i.e. use the log-likelihood ratio statistic):

    >>> from scipy.stats import power_divergence
    >>> power_divergence([16, 18, 16, 14, 12, 12], lambda_='log-likelihood')
    (2.006573162632538, 0.84823476779463769)

    The expected frequencies can be given with the `f_exp` argument:

    >>> power_divergence([16, 18, 16, 14, 12, 12],
    ...                  f_exp=[16, 16, 16, 16, 16, 8],
    ...                  lambda_='log-likelihood')
    (3.3281031458963746, 0.6495419288047497)

    When `f_obs` is 2-D, by default the test is applied to each column.

    >>> obs = np.array([[16, 18, 16, 14, 12, 12], [32, 24, 16, 28, 20, 24]]).T
    >>> obs.shape
    (6, 2)
    >>> power_divergence(obs, lambda_="log-likelihood")
    (array([ 2.00657316,  6.77634498]), array([ 0.84823477,  0.23781225]))

    By setting ``axis=None``, the test is applied to all data in the array,
    which is equivalent to applying the test to the flattened array.

    >>> power_divergence(obs, axis=None)
    (23.31034482758621, 0.015975692534127565)
    >>> power_divergence(obs.ravel())
    (23.31034482758621, 0.015975692534127565)

    `ddof` is the change to make to the default degrees of freedom.

    >>> power_divergence([16, 18, 16, 14, 12, 12], ddof=1)
    (2.0, 0.73575888234288467)

    The calculation of the p-values is done by broadcasting the
    test statistic with `ddof`.

    >>> power_divergence([16, 18, 16, 14, 12, 12], ddof=[0,1,2])
    (2.0, array([ 0.84914504,  0.73575888,  0.5724067 ]))

    `f_obs` and `f_exp` are also broadcast.  In the following, `f_obs` has
    shape (6,) and `f_exp` has shape (2, 6), so the result of broadcasting
    `f_obs` and `f_exp` has shape (2, 6).  To compute the desired chi-squared
    statistics, we must use ``axis=1``:

    >>> power_divergence([16, 18, 16, 14, 12, 12],
    ...                  f_exp=[[16, 16, 16, 16, 16, 8],
    ...                         [8, 20, 20, 16, 12, 12]],
    ...                  axis=1)
    (array([ 3.5 ,  9.25]), array([ 0.62338763,  0.09949846]))

    i   is9   invalid string for lambda_: {0!r}.  Valid strings are {1}R_   R`   RU   Ni   i    g       @g      ?(   Rp   R   t   _power_div_lambda_namest   reprR   t   keysRa   RV  RO   RP   RB  RS   Rc   Ru   Ry   R~  t   xlogyRe   R   R   R   R   R   R!  (   t   f_obst   f_expR   RU   t   lambda_t   namest   reduced_shapet   termst   statt   num_obsR  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRC   q  s<    		!
c      
   C` s"   t  |  d | d | d | d d S(   s  
    Calculate a one-way chi square test.

    The chi square test tests the null hypothesis that the categorical data
    has the given frequencies.

    Parameters
    ----------
    f_obs : array_like
        Observed frequencies in each category.
    f_exp : array_like, optional
        Expected frequencies in each category.  By default the categories are
        assumed to be equally likely.
    ddof : int, optional
        "Delta degrees of freedom": adjustment to the degrees of freedom
        for the p-value.  The p-value is computed using a chi-squared
        distribution with ``k - 1 - ddof`` degrees of freedom, where `k`
        is the number of observed frequencies.  The default value of `ddof`
        is 0.
    axis : int or None, optional
        The axis of the broadcast result of `f_obs` and `f_exp` along which to
        apply the test.  If axis is None, all values in `f_obs` are treated
        as a single data set.  Default is 0.

    Returns
    -------
    chisq : float or ndarray
        The chi-squared test statistic.  The value is a float if `axis` is
        None or `f_obs` and `f_exp` are 1-D.
    p : float or ndarray
        The p-value of the test.  The value is a float if `ddof` and the
        return value `chisq` are scalars.

    See Also
    --------
    power_divergence
    mstats.chisquare

    Notes
    -----
    This test is invalid when the observed or expected frequencies in each
    category are too small.  A typical rule is that all of the observed
    and expected frequencies should be at least 5.

    The default degrees of freedom, k-1, are for the case when no parameters
    of the distribution are estimated. If p parameters are estimated by
    efficient maximum likelihood then the correct degrees of freedom are
    k-1-p. If the parameters are estimated in a different way, then the
    dof can be between k-1-p and k-1. However, it is also possible that
    the asymptotic distribution is not a chisquare, in which case this
    test is not appropriate.

    References
    ----------
    .. [1] Lowry, Richard.  "Concepts and Applications of Inferential
           Statistics". Chapter 8.
           https://web.archive.org/web/20171022032306/http://vassarstats.net:80/textbook/ch8pt1.html
    .. [2] "Chi-squared test", https://en.wikipedia.org/wiki/Chi-squared_test

    Examples
    --------
    When just `f_obs` is given, it is assumed that the expected frequencies
    are uniform and given by the mean of the observed frequencies.

    >>> from scipy.stats import chisquare
    >>> chisquare([16, 18, 16, 14, 12, 12])
    (2.0, 0.84914503608460956)

    With `f_exp` the expected frequencies can be given.

    >>> chisquare([16, 18, 16, 14, 12, 12], f_exp=[16, 16, 16, 16, 16, 8])
    (3.5, 0.62338762774958223)

    When `f_obs` is 2-D, by default the test is applied to each column.

    >>> obs = np.array([[16, 18, 16, 14, 12, 12], [32, 24, 16, 28, 20, 24]]).T
    >>> obs.shape
    (6, 2)
    >>> chisquare(obs)
    (array([ 2.        ,  6.66666667]), array([ 0.84914504,  0.24663415]))

    By setting ``axis=None``, the test is applied to all data in the array,
    which is equivalent to applying the test to the flattened array.

    >>> chisquare(obs, axis=None)
    (23.31034482758621, 0.015975692534127565)
    >>> chisquare(obs.ravel())
    (23.31034482758621, 0.015975692534127565)

    `ddof` is the change to make to the default degrees of freedom.

    >>> chisquare([16, 18, 16, 14, 12, 12], ddof=1)
    (2.0, 0.73575888234288467)

    The calculation of the p-values is done by broadcasting the
    chi-squared statistic with `ddof`.

    >>> chisquare([16, 18, 16, 14, 12, 12], ddof=[0,1,2])
    (2.0, array([ 0.84914504,  0.73575888,  0.5724067 ]))

    `f_obs` and `f_exp` are also broadcast.  In the following, `f_obs` has
    shape (6,) and `f_exp` has shape (2, 6), so the result of broadcasting
    `f_obs` and `f_exp` has shape (2, 6).  To compute the desired chi-squared
    statistics, we use ``axis=1``:

    >>> chisquare([16, 18, 16, 14, 12, 12],
    ...           f_exp=[[16, 16, 16, 16, 16, 8], [8, 20, 20, 16, 12, 12]],
    ...           axis=1)
    (array([ 3.5 ,  9.25]), array([ 0.62338763,  0.09949846]))

    R'  R   RU   R(  R  (   RC   (   R&  R'  R   RU   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRB   B  s    pt   Ks_2sampResultc   
      C` s  t  j |   }  t  j |  } |  j d } | j d } t  j |  | g  } t  j |  | d d | } t  j | | d d | } t  j t  j | |   } t  j | | | |  } y& t j	 j
 | d d | |  }	 Wn$ t k
 rt j d  d }	 n Xt | |	  S(   s2  
    Compute the Kolmogorov-Smirnov statistic on 2 samples.

    This is a two-sided test for the null hypothesis that 2 independent samples
    are drawn from the same continuous distribution.

    Parameters
    ----------
    data1, data2 : sequence of 1-D ndarrays
        two arrays of sample observations assumed to be drawn from a continuous
        distribution, sample sizes can be different

    Returns
    -------
    statistic : float
        KS statistic
    pvalue : float
        two-tailed p-value

    Notes
    -----
    This tests whether 2 samples are drawn from the same distribution. Note
    that, like in the case of the one-sample K-S test, the distribution is
    assumed to be continuous.

    This is the two-sided test, one-sided tests are not implemented.
    The test uses the two-sided asymptotic Kolmogorov-Smirnov distribution.

    If the K-S statistic is small or the p-value is high, then we cannot
    reject the hypothesis that the distributions of the two samples
    are the same.

    Examples
    --------
    >>> from scipy import stats
    >>> np.random.seed(12345678)  #fix random seed to get the same result
    >>> n1 = 200  # size of first sample
    >>> n2 = 300  # size of second sample

    For a different distribution, we can reject the null hypothesis since the
    pvalue is below 1%:

    >>> rvs1 = stats.norm.rvs(size=n1, loc=0., scale=1)
    >>> rvs2 = stats.norm.rvs(size=n2, loc=0.5, scale=1.5)
    >>> stats.ks_2samp(rvs1, rvs2)
    (0.20833333333333337, 4.6674975515806989e-005)

    For a slightly different distribution, we cannot reject the null hypothesis
    at a 10% or lower alpha since the p-value at 0.144 is higher than 10%

    >>> rvs3 = stats.norm.rvs(size=n2, loc=0.01, scale=1.0)
    >>> stats.ks_2samp(rvs1, rvs3)
    (0.10333333333333333, 0.14498781825751686)

    For an identical distribution, we cannot reject the null hypothesis since
    the p-value is high, 41%:

    >>> rvs4 = stats.norm.rvs(size=n2, loc=0.0, scale=1.0)
    >>> stats.ks_2samp(rvs1, rvs4)
    (0.07999999999999996, 0.41126949729859719)

    i    R  R)  gQ?g)\(?s   This should not happen! Please open an issue at https://github.com/scipy/scipy/issues and provide the code you used to trigger this warning.
g      ?(   RP   R  Ry   R{  t   searchsortedR   t   absoluteR   R   R  R   t	   ExceptionRh   Ri   R.  (
   t   data1t   data2R  R  t   data_allt   cdf1t   cdf2R  t   enR  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRD     s    ?&
c         C` s   t  j |   } t  j t  j t | d | d  k t f  d } t  j |  j t  j  } t  j | j  } | d k  r} d Sd | d | j	   | d | S(   s  
    Tie correction factor for ties in the Mann-Whitney U and
    Kruskal-Wallis H tests.

    Parameters
    ----------
    rankvals : array_like
        A 1-D sequence of ranks.  Typically this will be the array
        returned by `stats.rankdata`.

    Returns
    -------
    factor : float
        Correction factor for U or H.

    See Also
    --------
    rankdata : Assign ranks to the data
    mannwhitneyu : Mann-Whitney rank test
    kruskal : Kruskal-Wallis H test

    References
    ----------
    .. [1] Siegel, S. (1956) Nonparametric Statistics for the Behavioral
           Sciences.  New York: McGraw-Hill.

    Examples
    --------
    >>> from scipy.stats import tiecorrect, rankdata
    >>> tiecorrect([1, 2.5, 2.5, 4])
    0.9
    >>> ranks = rankdata([1, 3, 2, 4, 5, 7, 2, 8, 4])
    >>> ranks
    array([ 1. ,  4. ,  2.5,  5.5,  7. ,  8. ,  2.5,  9. ,  5.5])
    >>> tiecorrect(ranks)
    0.9833333333333333

    i   ii    i   g      ?i   (
   RP   R  R  R  R~   R  R   R   Rz   Re   (   t   rankvalst   arrR  R  Rz   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRF     s
    '1t   MannwhitneyuResultc         C` s  | d k r t j d t  n  t j |   }  t j |  } t |   } t |  } t t j |  | f   } | d | !} | | | | d d t j	 | d d } | | | }	 t
 |  }
 |
 d k r t d   n  t j |
 | | | | d d  } | | d d | } | d k s4| d	 k rFt | |	  } n6 | d
 k r[| } n! | d k rp|	 } n t d   | | | } | d k rt j j t |   } n= | d	 k rd t j j t |   } n t j j |  } |	 } | d k rt | |	  } n  t | |  S(   sB  
    Compute the Mann-Whitney rank test on samples x and y.

    Parameters
    ----------
    x, y : array_like
        Array of samples, should be one-dimensional.
    use_continuity : bool, optional
            Whether a continuity correction (1/2.) should be taken into
            account. Default is True.
    alternative : None (deprecated), 'less', 'two-sided', or 'greater'
            Whether to get the p-value for the one-sided hypothesis ('less'
            or 'greater') or for the two-sided hypothesis ('two-sided').
            Defaults to None, which results in a p-value half the size of
            the 'two-sided' p-value and a different U statistic. The
            default behavior is not the same as using 'less' or 'greater':
            it only exists for backward compatibility and is deprecated.

    Returns
    -------
    statistic : float
        The Mann-Whitney U statistic, equal to min(U for x, U for y) if
        `alternative` is equal to None (deprecated; exists for backward
        compatibility), and U for y otherwise.
    pvalue : float
        p-value assuming an asymptotic normal distribution. One-sided or
        two-sided, depending on the choice of `alternative`.

    Notes
    -----
    Use only when the number of observation in each sample is > 20 and
    you have 2 independent samples of ranks. Mann-Whitney U is
    significant if the u-obtained is LESS THAN or equal to the critical
    value of U.

    This test corrects for ties and by default uses a continuity correction.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Mann-Whitney_U_test

    .. [2] H.B. Mann and D.R. Whitney, "On a Test of Whether one of Two Random
           Variables is Stochastically Larger than the Other," The Annals of
           Mathematical Statistics, vol. 18, no. 1, pp. 50-60, 1947.

    sF   Calling `mannwhitneyu` without specifying `alternative` is deprecated.i    i   g       @RU   s)   All numbers are identical in mannwhitneyug      (@g      ?s	   two-sidedR  R  s<   alternative should be None, 'less', 'greater' or 'two-sided'i   N(   RO   Rh   Ri   t   DeprecationWarningRP   R   R   RJ   R{  Re   RF   Ra   R   R   R   R   R   R   R   R:  (   R   R   t   use_continuityR  R  R  t   rankedt   rankxt   u1t   u2R  R   t   meanrankt   bigut   zR  t   u(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRE   >  sB    /	
-'		t   RanksumsResultc   
      C` s   t  t j |  | f  \ }  } t |   } t |  } t j |  | f  } t |  } | |  }  t j |  d d } | | | d d } | | t j | | | | d d  } d t j	 j
 t |   }	 t | |	  S(   s  
    Compute the Wilcoxon rank-sum statistic for two samples.

    The Wilcoxon rank-sum test tests the null hypothesis that two sets
    of measurements are drawn from the same distribution.  The alternative
    hypothesis is that values in one sample are more likely to be
    larger than the values in the other sample.

    This test should be used to compare two samples from continuous
    distributions.  It does not handle ties between measurements
    in x and y.  For tie-handling and an optional continuity correction
    see `scipy.stats.mannwhitneyu`.

    Parameters
    ----------
    x,y : array_like
        The data from the two samples

    Returns
    -------
    statistic : float
        The test statistic under the large-sample approximation that the
        rank sum statistic is normally distributed
    pvalue : float
        The two-sided p-value of the test

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Wilcoxon_rank-sum_test

    RU   i    i   g       @g      (@i   (   RN  RP   R   R   R{  RJ   Re   R   R   R   R   R   RE  (
   R   R   R  R  R  R=  R^   t   expectedRC  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRG     s     
+t   KruskalResultc          O` s{  t  t t j |    }  t |   } | d k  r? t d   n  x0 |  D]( } | j d k rF t t j t j  SqF Wt j t  t t |     } d | j	   k r | d d k r t d   q | d } n d } t
 } x1 |  D]) } t | |  } | d r t } Pq q W| rM| d k rMx |  D] } t j |  } q'Wt j |    S| rr| d k rrt t j t j  St j |   }	 t |	  }
 t |
  } | d k rt d	   n  t j t j |  d d  } d } x? t |  D]1 } | t |
 | | | | d
 ! | | 7} qWt j |  } d | | d
 | d | d
 } | d
 } | | } t | t j j | |   S(   s  
    Compute the Kruskal-Wallis H-test for independent samples

    The Kruskal-Wallis H-test tests the null hypothesis that the population
    median of all of the groups are equal.  It is a non-parametric version of
    ANOVA.  The test works on 2 or more independent samples, which may have
    different sizes.  Note that rejecting the null hypothesis does not
    indicate which of the groups differs.  Post-hoc comparisons between
    groups are required to determine which groups are different.

    Parameters
    ----------
    sample1, sample2, ... : array_like
       Two or more arrays with the sample measurements can be given as
       arguments.
    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'.

    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

    See Also
    --------
    f_oneway : 1-way ANOVA
    mannwhitneyu : Mann-Whitney rank test on two samples.
    friedmanchisquare : Friedman test for repeated measurements

    Notes
    -----
    Due to the assumption that H has a chi square distribution, the number
    of samples in each group must not be too small.  A typical rule is
    that each sample must have at least 5 measurements.

    References
    ----------
    .. [1] W. H. Kruskal & W. W. Wallis, "Use of Ranks in
       One-Criterion Variance Analysis", Journal of the American Statistical
       Association, Vol. 47, Issue 260, pp. 583-621, 1952.
    .. [2] https://en.wikipedia.org/wiki/Kruskal-Wallis_one-way_analysis_of_variance

    Examples
    --------
    >>> from scipy import stats
    >>> x = [1, 3, 5, 7, 9]
    >>> y = [2, 4, 6, 8, 10]
    >>> stats.kruskal(x, y)
    KruskalResult(statistic=0.2727272727272734, pvalue=0.6015081344405895)

    >>> x = [1, 1, 1]
    >>> y = [2, 2, 2]
    >>> z = [2, 2]
    >>> stats.kruskal(x, y, z)
    KruskalResult(statistic=7.0, pvalue=0.0301973834223185)

    i   s+   Need at least two groups in stats.kruskal()i    Rk   RZ   R[   R\   s0   nan_policy must be 'propagate', 'raise' or'omit's$   All numbers are identical in kruskali   g      (@i   (   RZ   R[   R\   (   R   RN  RP   R   R   Ra   Rz   RG  R   R$  Rg   Rn   R~   R   R   R   RH   R{  RJ   RF   t   insertR:  R   R}  Re   R   R   R   (   RE  t   kwargsR  RH  R   Rk   Rm   t   cnRT   R  R=  t   tiesR!  R  R   t   totalnR<  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRH     sN    ?
/"

t   FriedmanchisquareResultc          G` s  t  |   } | d k  r' t d   n  t  |  d  } x< t d |  D]+ } t  |  |  | k rG t d   qG qG Wt j |   j } | j t  } x. t t  |   D] } t | |  | | <q Wd } x] t t  |   D]I } t	 t
 | |   \ } } x$ | D] } | | | | d 7} q
Wq Wd | | | | d | }	 t j | j d d  d  }
 d | | | d |
 d | | d |	 } t | t j j | | d   S(	   s  
    Compute the Friedman test for repeated measurements

    The Friedman test tests the null hypothesis that repeated measurements of
    the same individuals have the same distribution.  It is often used
    to test for consistency among measurements obtained in different ways.
    For example, if two measurement techniques are used on the same set of
    individuals, the Friedman test can be used to determine if the two
    measurement techniques are consistent.

    Parameters
    ----------
    measurements1, measurements2, measurements3... : array_like
        Arrays of measurements.  All of the arrays must have the same number
        of elements.  At least 3 sets of measurements must be given.

    Returns
    -------
    statistic : float
        the test statistic, correcting for ties
    pvalue : float
        the associated p-value assuming that the test statistic has a chi
        squared distribution

    Notes
    -----
    Due to the assumption that the test statistic has a chi squared
    distribution, the p-value is only reliable for n > 10 and more than
    6 repeated measurements.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Friedman_test

    i   s3   Less than 3 levels.  Friedman test not appropriate.i    i   s*   Unequal N in friedmanchisquare.  Aborting.RU   i   g      (@(   R   Ra   R   RP   t   vstackR  R   R   RJ   R   R   Re   RM  R   R   R   (   RE  R  R   R   R   RK  t   replistt   repnumRK  Rn  R  t   chisq(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRI   G  s(    $.t   BrunnerMunzelResultRK  c         C` s  t  j |   }  t  j |  } t |  |  \ } } t | |  \ } } | pQ | }	 | d k sl | d k ru d } n  |	 r | d k r t t  j t  j  S|	 r | d k r t j |   }  t j |  } t j |  | | |  St	 |   }
 t	 |  } |
 d k s| d k r#t t  j t  j  St
 t  j |  | f   } | d |
 !} | |
 |
 | !} t  j |  } t  j |  } t
 |   } t
 |  } t  j |  } t  j |  } t  j t  j | | | | d   } | |
 d } t  j t  j | | | | d   } | | d } |
 | | | } | |
 | t  j |
 | | |  } | d k rt  j |
 | | | d  } t  j |
 | d  |
 d } | t  j | | d  | d 7} | | } t j j | |  } n- | d k r t j j |  } n t d   | d	 k r!| } nQ | d
 k r:d | } n8 | d k rfd t  j | d | g  } n t d   t | |  S(   s
  
    Computes the Brunner-Munzel test on samples x and y

    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' .
    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'.

    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
    -------
    Brunner and Munzel recommended to estimate the p-value by t-distribution
    when the size of data is 50 or less. If the size is lower than 10, it would
    be better to use permuted Brunner Munzel test (see [2]_).

    References
    ----------
    .. [1] Brunner, E. and Munzel, U. "The nonparametric Benhrens-Fisher
           problem: Asymptotic theory and a small-sample approximation".
           Biometrical Journal. Vol. 42(2000): 17-25.
    .. [2] Neubert, K. and Brunner, E. "A studentized permutation test for the
           non-parametric Behrens-Fisher problem". Computational Statistics and
           Data Analysis. Vol. 51(2007): 5192-5204.

    Examples
    --------
    >>> from scipy import stats
    >>> x1 = [1,2,1,1,1,1,1,1,1,1,2,4,1,1]
    >>> x2 = [3,3,4,3,1,2,3,1,1,5,4]
    >>> w, p_value = stats.brunnermunzel(x1, x2)
    >>> w
    3.1374674823029505
    >>> p_value
    0.0057862086661515377

    R\   RZ   i    g       @i   RK  RQ  s&   distribution should be 't' or 'normal'R  R  s	   two-sidedi   s6   alternative should be 'less', 'greater' or 'two-sided'(   RP   R   Rn   RR  R   R   R   R   RN   R   RJ   R{  Ru   Re   R   R   R   RK  R  R   Ra   R   (   R   R   R  t   distributionRk   R  R  R  R  Rm   t   nxt   nyt   rankct   rankcxt   rankcyt   rankcx_meant   rankcy_meanR>  t   rankyt
   rankx_meant
   ranky_meant   Sxt   Syt   wbfnt   df_numert   df_denomR  R  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRN     sf    E	'''"
		 	R   c         C` s_  t  j |   }  |  j d k r- t d   n  | d k r~ d t  j t  j |    } t j j | d t	 |    } | | f S| d k rL| d
 k r t  j |   } n' t	 |  t	 |   k r t d   n  t  j |  } | j d k r t d   n  t j j |   } t  j | |  t  j j |  } t j j |  } | | f St d	 |   d
 S(   s  
    Methods for combining the p-values of independent tests bearing upon the
    same hypothesis.

    Parameters
    ----------
    pvalues : array_like, 1-D
        Array of p-values assumed to come from independent tests.
    method : {'fisher', 'stouffer'}, optional
        Name of method to use to combine p-values. The following methods are
        available:

        - "fisher": Fisher's method (Fisher's combined probability test),
          the default.
        - "stouffer": Stouffer's Z-score method.
    weights : array_like, 1-D, optional
        Optional array of weights used only for Stouffer's Z-score method.

    Returns
    -------
    statistic: float
        The statistic calculated by the specified method:
        - "fisher": The chi-squared statistic
        - "stouffer": The Z-score
    pval: float
        The combined p-value.

    Notes
    -----
    Fisher's method (also known as Fisher's combined probability test) [1]_ uses
    a chi-squared statistic to compute a combined p-value. The closely related
    Stouffer's Z-score method [2]_ uses Z-scores rather than p-values. The
    advantage of Stouffer's method is that it is straightforward to introduce
    weights, which can make Stouffer's method more powerful than Fisher's
    method when the p-values are from studies of different size [3]_ [4]_.

    Fisher's method may be extended to combine p-values from dependent tests
    [5]_. Extensions such as Brown's method and Kost's method are not currently
    implemented.

    .. versionadded:: 0.15.0

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Fisher%27s_method
    .. [2] https://en.wikipedia.org/wiki/Fisher%27s_method#Relation_to_Stouffer.27s_Z-score_method
    .. [3] Whitlock, M. C. "Combining probability from independent tests: the
           weighted Z-method is superior to Fisher's approach." Journal of
           Evolutionary Biology 18, no. 5 (2005): 1368-1373.
    .. [4] Zaykin, Dmitri V. "Optimally weighted Z-test is a powerful method
           for combining probabilities in meta-analysis." Journal of
           Evolutionary Biology 24, no. 8 (2011): 1836-1841.
    .. [5] https://en.wikipedia.org/wiki/Extensions_of_Fisher%27s_method

    i   s   pvalues is not 1-DR   ii   t   stouffers-   pvalues and weights must be of the same size.s   weights is not 1-Ds7   Invalid method '%s'. Options are 'fisher' or 'stouffer'N(   RP   R   RR   Ra   Re   Rr   R   R   R   R   RO   t	   ones_likeR   t   isft   dott   linalg(   t   pvaluesR  R  t   Xsqt   pvalt   ZiR   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRK     s*    8
"
c         C` s   t  d |  | | |  S(   s]
  
    Compute the first Wasserstein distance between two 1D distributions.

    This distance is also known as the earth mover's distance, since it can be
    seen as the minimum amount of "work" required to transform :math:`u` into
    :math:`v`, where "work" is measured as the amount of distribution weight
    that must be moved, multiplied by the distance it has to be moved.

    .. versionadded:: 1.0.0

    Parameters
    ----------
    u_values, v_values : array_like
        Values observed in the (empirical) distribution.
    u_weights, v_weights : array_like, optional
        Weight for each value. If unspecified, each value is assigned the same
        weight.
        `u_weights` (resp. `v_weights`) must have the same length as
        `u_values` (resp. `v_values`). If the weight sum differs from 1, it
        must still be positive and finite so that the weights can be normalized
        to sum to 1.

    Returns
    -------
    distance : float
        The computed distance between the distributions.

    Notes
    -----
    The first Wasserstein distance between the distributions :math:`u` and
    :math:`v` is:

    .. math::

        l_1 (u, v) = \inf_{\pi \in \Gamma (u, v)} \int_{\mathbb{R} \times
        \mathbb{R}} |x-y| \mathrm{d} \pi (x, y)

    where :math:`\Gamma (u, v)` is the set of (probability) distributions on
    :math:`\mathbb{R} \times \mathbb{R}` whose marginals are :math:`u` and
    :math:`v` on the first and second factors respectively.

    If :math:`U` and :math:`V` are the respective CDFs of :math:`u` and
    :math:`v`, this distance also equals to:

    .. math::

        l_1(u, v) = \int_{-\infty}^{+\infty} |U-V|

    See [2]_ for a proof of the equivalence of both definitions.

    The input distributions can be empirical, therefore coming from samples
    whose values are effectively inputs of the function, or they can be seen as
    generalized functions, in which case they are weighted sums of Dirac delta
    functions located at the specified values.

    References
    ----------
    .. [1] "Wasserstein metric", https://en.wikipedia.org/wiki/Wasserstein_metric
    .. [2] Ramdas, Garcia, Cuturi "On Wasserstein Two Sample Testing and Related
           Families of Nonparametric Tests" (2015). :arXiv:`1509.02237`.

    Examples
    --------
    >>> from scipy.stats import wasserstein_distance
    >>> wasserstein_distance([0, 1, 3], [5, 6, 8])
    5.0
    >>> wasserstein_distance([0, 1], [0, 1], [3, 1], [2, 2])
    0.25
    >>> wasserstein_distance([3.4, 3.9, 7.5, 7.8], [4.5, 1.4],
    ...                      [1.4, 0.9, 3.1, 7.2], [3.2, 3.5])
    4.0781331438047861
    i   (   t   _cdf_distance(   t   u_valuest   v_valuest	   u_weightst	   v_weights(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRL   i  s    Ic         C` s#   t  j d  t d |  | | |  S(   sk  
    Compute the energy distance between two 1D distributions.

    .. versionadded:: 1.0.0

    Parameters
    ----------
    u_values, v_values : array_like
        Values observed in the (empirical) distribution.
    u_weights, v_weights : array_like, optional
        Weight for each value. If unspecified, each value is assigned the same
        weight.
        `u_weights` (resp. `v_weights`) must have the same length as
        `u_values` (resp. `v_values`). If the weight sum differs from 1, it
        must still be positive and finite so that the weights can be normalized
        to sum to 1.

    Returns
    -------
    distance : float
        The computed distance between the distributions.

    Notes
    -----
    The energy distance between two distributions :math:`u` and :math:`v`, whose
    respective CDFs are :math:`U` and :math:`V`, equals to:

    .. math::

        D(u, v) = \left( 2\mathbb E|X - Y| - \mathbb E|X - X'| -
        \mathbb E|Y - Y'| \right)^{1/2}

    where :math:`X` and :math:`X'` (resp. :math:`Y` and :math:`Y'`) are
    independent random variables whose probability distribution is :math:`u`
    (resp. :math:`v`).

    As shown in [2]_, for one-dimensional real-valued variables, the energy
    distance is linked to the non-distribution-free version of the Cramer-von
    Mises distance:

    .. math::

        D(u, v) = \sqrt{2} l_2(u, v) = \left( 2 \int_{-\infty}^{+\infty} (U-V)^2
        \right)^{1/2}

    Note that the common Cramer-von Mises criterion uses the distribution-free
    version of the distance. See [2]_ (section 2), for more details about both
    versions of the distance.

    The input distributions can be empirical, therefore coming from samples
    whose values are effectively inputs of the function, or they can be seen as
    generalized functions, in which case they are weighted sums of Dirac delta
    functions located at the specified values.

    References
    ----------
    .. [1] "Energy distance", https://en.wikipedia.org/wiki/Energy_distance
    .. [2] Szekely "E-statistics: The energy of statistical samples." Bowling
           Green State University, Department of Mathematics and Statistics,
           Technical Report 02-16 (2002).
    .. [3] Rizzo, Szekely "Energy distance." Wiley Interdisciplinary Reviews:
           Computational Statistics, 8(1):27-38 (2015).
    .. [4] Bellemare, Danihelka, Dabney, Mohamed, Lakshminarayanan, Hoyer,
           Munos "The Cramer Distance as a Solution to Biased Wasserstein
           Gradients" (2017). :arXiv:`1705.10743`.

    Examples
    --------
    >>> from scipy.stats import energy_distance
    >>> energy_distance([0], [2])
    2.0000000000000004
    >>> energy_distance([0, 8], [0, 8], [3, 1], [2, 2])
    1.0000000000000002
    >>> energy_distance([0.7, 7.4, 2.4, 6.8], [1.4, 8. ],
    ...                 [2.1, 4.2, 7.4, 8. ], [7.6, 8.8])
    0.88003340976158217
    i   (   RP   R   Rl  (   Rm  Rn  Ro  Rp  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRM     s    Nc         C` s  t  | |  \ } } t  | |  \ } } t j |  } t j |  } t j | | f  } | j d d  t j |  } | | j | d  d  }	 | | j | d  d  }
 | d k r |	 | j } n7 t j d g t j	 | |  f  } | |	 | d } | d k r|
 | j } n7 t j d g t j	 | |  f  } | |
 | d } |  d k rt j
 t j t j | |  |   S|  d k rt j t j
 t j t j | |  |    St j t j
 t j t j t j | |  |   |   d |   S(	   s   
    Compute, between two one-dimensional distributions :math:`u` and
    :math:`v`, whose respective CDFs are :math:`U` and :math:`V`, the
    statistical distance that is defined as:

    .. math::

        l_p(u, v) = \left( \int_{-\infty}^{+\infty} |U-V|^p \right)^{1/p}

    p is a positive parameter; p = 1 gives the Wasserstein distance, p = 2
    gives the energy distance.

    Parameters
    ----------
    u_values, v_values : array_like
        Values observed in the (empirical) distribution.
    u_weights, v_weights : array_like, optional
        Weight for each value. If unspecified, each value is assigned the same
        weight.
        `u_weights` (resp. `v_weights`) must have the same length as
        `u_values` (resp. `v_values`). If the weight sum differs from 1, it
        must still be positive and finite so that the weights can be normalized
        to sum to 1.

    Returns
    -------
    distance : float
        The computed distance between the distributions.

    Notes
    -----
    The input distributions can be empirical, therefore coming from samples
    whose values are effectively inputs of the function, or they can be seen as
    generalized functions, in which case they are weighted sums of Dirac delta
    functions located at the specified values.

    References
    ----------
    .. [1] Bellemare, Danihelka, Dabney, Mohamed, Lakshminarayanan, Hoyer,
           Munos "The Cramer Distance as a Solution to Biased Wasserstein
           Gradients" (2017). :arXiv:`1705.10743`.
    R'  R  iR)  i    i   i   N(   t   _validate_distributionRP   R  R{  R  R  R/  RO   Rz   R:  Re   t   multiplyR   R   t   squareR   (   R  Rm  Rn  Ro  Rp  t   u_sortert   v_sortert
   all_valuest   deltast   u_cdf_indicest   v_cdf_indicest   u_cdft   u_sorted_cumweightst   v_cdft   v_sorted_cumweights(    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRl    s2    +&/.c         C` s   t  j |  d t }  t |   d k r6 t d   n  | d k	 r t  j | d t } t |  t |   k r~ t d   n  t  j | d k   r t d   n  d t  j |  k  o t  j k  n s t d   n  |  | f S|  d f S(   s  
    Validate the values and weights from a distribution input of `cdf_distance`
    and return them as ndarray objects.

    Parameters
    ----------
    values : array_like
        Values observed in the (empirical) distribution.
    weights : array_like
        Weight for each value.

    Returns
    -------
    values : ndarray
        Values as ndarray.
    weights : ndarray
        Weights as ndarray.
    Ro   i    s   Distribution can't be empty.sZ   Value and weight array-likes for the same empirical distribution must be of the same size.s!   All weights must be non-negative.sc   Weight array-like sum must be positive and finite. Set as None for an equal distribution of weight.N(	   RP   R   R   R   Ra   RO   R   Re   R  (   t   valuesR  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRq  ]  s    (
t   RepeatedResultsR~  R   c         C` s"   t  t t j |  d t j    S(   s#  
    Find repeats and repeat counts.

    Parameters
    ----------
    arr : array_like
        Input array. This is cast to float64.

    Returns
    -------
    values : ndarray
        The unique values from the (flattened) input that are repeated.

    counts : ndarray
        Number of times the corresponding 'value' is repeated.

    Notes
    -----
    In numpy >= 1.9 `numpy.unique` provides similar functionality. The main
    difference is that `find_repeats` only returns repeated values.

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

    >>> stats.find_repeats([[10, 20, 1, 2], [5, 5, 4, 4]])
    RepeatedResults(values=array([4.,  5.]), counts=array([2, 2]))

    Ro   (   R  R   RP   R   R   (   R9  (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR     s    !c         C` s)   t  |  |  \ }  } t j |  |  |  S(   s  
    Square each element of the input array, and return the sum(s) of that.

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

    Returns
    -------
    sum_of_squares : ndarray
        The sum along the given axis for (a**2).

    See also
    --------
    _square_of_sums : The square(s) of the sum(s) (the opposite of
    `_sum_of_squares`).
    (   RW   RP   Re   (   RT   RU   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR|    s    c         C` sY   t  |  |  \ }  } t j |  |  } t j |  sG | j t  | St |  | Sd S(   s  
    Sum elements of the input array, and return the square(s) of that sum.

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

    Returns
    -------
    square_of_sums : float or ndarray
        The square of the sum over `axis`.

    See also
    --------
    _sum_of_squares : The sum of squares (the opposite of `square_of_sums`).
    N(   RW   RP   Re   R   R   R   (   RT   RU   R^   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyR}    s
    t   averagec   	      C` st  | d k r$ t  d j |    n  t j t j |    } | d k rN d n d } t j | d	 | } t j | j d
 t j } t j	 | j d
 t j | | <| d k r | d S| | } t j
 t | d | d  k f } | j   | } | d k r| St j
 t j |  d t |  f } | d k r<| | S| d k rX| | d d Sd | | | | d d S(   s  
    Assign ranks to data, dealing with ties appropriately.

    Ranks begin at 1.  The `method` argument controls how ranks are assigned
    to equal values.  See [1]_ for further discussion of ranking methods.

    Parameters
    ----------
    a : array_like
        The array of values to be ranked.  The array is first flattened.
    method : str, optional
        The method used to assign ranks to tied elements.
        The options are 'average', 'min', 'max', 'dense' and 'ordinal'.

        'average':
            The average of the ranks that would have been assigned to
            all the tied values is assigned to each value.
        'min':
            The minimum of the ranks that would have been assigned to all
            the tied values is assigned to each value.  (This is also
            referred to as "competition" ranking.)
        'max':
            The maximum of the ranks that would have been assigned to all
            the tied values is assigned to each value.
        'dense':
            Like 'min', but the rank of the next highest element is assigned
            the rank immediately after those assigned to the tied elements.
        'ordinal':
            All values are given a distinct rank, corresponding to the order
            that the values occur in `a`.

        The default is 'average'.

    Returns
    -------
    ranks : ndarray
         An array of length equal to the size of `a`, containing rank
         scores.

    References
    ----------
    .. [1] "Ranking", https://en.wikipedia.org/wiki/Ranking

    Examples
    --------
    >>> from scipy.stats import rankdata
    >>> rankdata([0, 2, 3, 2])
    array([ 1. ,  2.5,  4. ,  2.5])
    >>> rankdata([0, 2, 3, 2], method='min')
    array([ 1,  2,  4,  2])
    >>> rankdata([0, 2, 3, 2], method='max')
    array([ 1,  3,  4,  3])
    >>> rankdata([0, 2, 3, 2], method='dense')
    array([ 1,  2,  3,  2])
    >>> rankdata([0, 2, 3, 2], method='ordinal')
    array([ 1,  2,  4,  3])
    R  R   R   t   denset   ordinals   unknown method "{0}"R  t	   quicksortR'  Ro   i   ii    g      ?(   R  R   R   R  R  (   Ra   RV  RP   RQ   R   R  R   Rz   R  R  R  R~   R:  R  R   (	   RT   R  R9  t   algot   sorterR  R  R  Rx   (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyRJ     s(    :
!&(   R   Rx   (   R   R   Ru   R   R   R"   (   R   R   (   R   R   (   R   R   (    (   Rx   R   R,  R-  (   R9  R   R,  R-  (   RA  R   R,  R-  (   i   iK   (   Rj  R  Rk  (   R   R   (   R  R   (   R  R   (   R  R   (   R  R   (   R   R   (   R   R   (   R   R   (   R   R   (    gUUUUUU?(   R   R   (   R   R   (   R   R   (   R   R   (   R   R   (   R   R   (   R   R   (   R~  R   (   t   __doc__t
   __future__R    R   R   Rh   R   t   collectionsR   t   numpyRP   R   R   R   t   scipy._lib.sixR   R   t   scipy._lib._versionR	   t   scipy._lib._utilR
   t   scipy.specialR~  t    R   R   t   _stats_mstats_commonR   R   R   R   t   _statsR   R   R   t   _rvs_samplingR   t   __all__RW   RY   Rn   RO   R   R   R{   R   R   R~   R   R   R   R   R   R   R   R   R    R!   R"   R   R#   R   R$   R   R%   R   R&   R'   t	   deprecateR(   R)   R  R*   R+  Rg   R7  R8  R+   R@  R,   R-   R.   R0   R/   t   erfinvR   RU  R1   RX  RW  Ri  R2   R3   R4   R5   Rz  R6   R7   R8   R  R9   R  R:   R  R;   R  R<   R  R=   R  R  R  R  R  R?   R>   R  R@   R  RA   R"  R   R!  RC   RB   R.  RD   RF   R:  RE   RE  RG   RG  RH   RM  RI   RR  RN   RK   RL   RM   Rl  Rq  R  R   R|  R}  RJ   (    (    (    s0   lib/python2.7/site-packages/scipy/stats/stats.pyt   <module>   s<  "						@B[	-17;:0:P	3-KP 	RNZG	<+O	+^	L 	M 	P	M<>6
$<	/E>5F	g	W		WP			
		W}_
	t	T	/\	.	u		A	XLRV	.	$