ó
áp7]c        	   @   s,  d  d l  m Z m Z d  d l Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d d	 l m Z d
 d d d g Z d e f d „  ƒ  YZ e j f  d d d e e e d „ Z e e e e d „ Z e e e d d „ Z d „  Z d „  Z e e e d d „ Z d „  Z d S(   iÿÿÿÿ(   t   lzipt   string_typesN(   t   stats(   t   OLS(   t   add_constant(   t   cache_readonly(   t   ECDFi   (   t   utilst   qqplott   qqplot_2samplest   qqlinet   ProbPlotc           B   s¿   e  Z d  Z e j e d d d d d „ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d „  ƒ Z d d d d d d	 „ Z d d d d d d
 „ Z d d d e d d „ Z RS(   sA  
    Class for convenient construction of Q-Q, P-P, and probability plots.

    Can take arguments specifying the parameters for dist or fit them
    automatically. (See fit under kwargs.)

    Parameters
    ----------
    data : array-like
        1d data array
    dist : A scipy.stats or statsmodels distribution
        Compare x against dist. The default is
        scipy.stats.distributions.norm (a standard normal).
    distargs : tuple
        A tuple of arguments passed to dist to specify it fully
        so dist.ppf may be called. distargs must not contain loc
        or scale. These values must be passed using the loc or
        scale inputs.
    a : float
        Offset for the plotting position of an expected order
        statistic, for example. The plotting positions are given
        by (i - a)/(nobs - 2*a + 1) for i in range(0,nobs+1)
    loc : float
        Location parameter for dist
    scale : float
        Scale parameter for dist
    fit : boolean
        If fit is false, loc, scale, and distargs are passed to the
        distribution. If fit is True then the parameters for dist
        are fit automatically using dist.fit. The quantiles are formed
        from the standardized data, after subtracting the fitted loc
        and dividing by the fitted scale.

    See Also
    --------
    scipy.stats.probplot

    Notes
    -----
    1) Depends on matplotlib.
    2) If `fit` is True then the parameters are fit using the
        distribution's `fit()` method.
    3) The call signatures for the `qqplot`, `ppplot`, and `probplot`
        methods are similar, so examples 1 through 4 apply to all
        three methods.
    4) The three plotting methods are summarized below:
        ppplot : Probability-Probability plot
            Compares the sample and theoretical probabilities (percentiles).
        qqplot : Quantile-Quantile plot
            Compares the sample and theoretical quantiles
        probplot : Probability plot
            Same as a Q-Q plot, however probabilities are shown in the scale of
            the theoretical distribution (x-axis) and the y-axis contains
            unscaled quantiles of the sample data.

    Examples
    --------
    The first example shows a Q-Q plot for regression residuals

    >>> # example 1
    >>> import statsmodels.api as sm
    >>> from matplotlib import pyplot as plt
    >>> data = sm.datasets.longley.load(as_pandas=False)
    >>> data.exog = sm.add_constant(data.exog)
    >>> model = sm.OLS(data.endog, data.exog)
    >>> mod_fit = model.fit()
    >>> res = mod_fit.resid # residuals
    >>> probplot = sm.ProbPlot(res)
    >>> fig = probplot.qqplot()
    >>> h = plt.title('Ex. 1 - qqplot - residuals of OLS fit')
    >>> plt.show()

    qqplot of the residuals against quantiles of t-distribution with 4
    degrees of freedom:

    >>> # example 2
    >>> import scipy.stats as stats
    >>> probplot = sm.ProbPlot(res, stats.t, distargs=(4,))
    >>> fig = probplot.qqplot()
    >>> h = plt.title('Ex. 2 - qqplot - residuals against quantiles of t-dist')
    >>> plt.show()

    qqplot against same as above, but with mean 3 and std 10:

    >>> # example 3
    >>> probplot = sm.ProbPlot(res, stats.t, distargs=(4,), loc=3, scale=10)
    >>> fig = probplot.qqplot()
    >>> h = plt.title('Ex. 3 - qqplot - resids vs quantiles of t-dist')
    >>> plt.show()

    Automatically determine parameters for t distribution including the
    loc and scale:

    >>> # example 4
    >>> probplot = sm.ProbPlot(res, stats.t, fit=True)
    >>> fig = probplot.qqplot(line='45')
    >>> h = plt.title('Ex. 4 - qqplot - resids vs. quantiles of fitted t-dist')
    >>> plt.show()

    A second `ProbPlot` object can be used to compare two separate sample
    sets by using the `other` kwarg in the `qqplot` and `ppplot` methods.

    >>> # example 5
    >>> import numpy as np
    >>> x = np.random.normal(loc=8.25, scale=2.75, size=37)
    >>> y = np.random.normal(loc=8.75, scale=3.25, size=37)
    >>> pp_x = sm.ProbPlot(x, fit=True)
    >>> pp_y = sm.ProbPlot(y, fit=True)
    >>> fig = pp_x.qqplot(line='45', other=pp_y)
    >>> h = plt.title('Ex. 5 - qqplot - compare two sample sets')
    >>> plt.show()

    In qqplot, sample size of `other` can be equal or larger than the first.
    In case of larger, size of `other` samples will be reduced to match the
    size of the first by interpolation

    >>> # example 6
    >>> x = np.random.normal(loc=8.25, scale=2.75, size=37)
    >>> y = np.random.normal(loc=8.75, scale=3.25, size=57)
    >>> pp_x = sm.ProbPlot(x, fit=True)
    >>> pp_y = sm.ProbPlot(y, fit=True)
    >>> fig = pp_x.qqplot(line='45', other=pp_y)
    >>> title = 'Ex. 6 - qqplot - compare different sample sizes'
    >>> h = plt.title(title)
    >>> plt.show()

    In ppplot, sample size of `other` and the first can be different. `other`
    will be used to estimate an empirical cumulative distribution function
    (ECDF). ECDF(x) will be plotted against p(x)=0.5/n, 1.5/n, ..., (n-0.5)/n
    where x are sorted samples from the first.

    >>> # example 7
    >>> x = np.random.normal(loc=8.25, scale=2.75, size=37)
    >>> y = np.random.normal(loc=8.75, scale=3.25, size=57)
    >>> pp_x = sm.ProbPlot(x, fit=True)
    >>> pp_y = sm.ProbPlot(y, fit=True)
    >>> fig = pp_y.ppplot(line='45', other=pp_x)
    >>> h = plt.title('Ex. 7A- ppplot - compare two sample sets, other=pp_x')
    >>> fig = pp_x.ppplot(line='45', other=pp_y)
    >>> h = plt.title('Ex. 7B- ppplot - compare two sample sets, other=pp_y')
    >>> plt.show()

    The following plot displays some options, follow the link to see the
    code.

    .. plot:: plots/graphics_gofplots_qqplot.py
    i    i   c   
      C   sà  | |  _  | |  _ | j d |  _ | |  _ | |  _ t | t ƒ rU t t	 | ƒ } n  | j | ƒ |  _
 | rè |  j
 d |  _ |  j
 d |  _ t |  j
 ƒ d k rÍ | |  j
 d  t d d d d ƒ Ž  |  _ qÓ| d d d d ƒ |  _ në | s| d k s| d k r¸y% | | t d | d | ƒ Ž  |  _ Wnu t k
 r¢d j g  | D] } t | ƒ ^ qHƒ } d	 }	 |	 j d
 | d | d | ƒ }	 t d j d |	 ƒ ƒ ‚ n X| |  _ | |  _ n | |  _ | |  _ | |  _ i  |  _ d  S(   Ni    iþÿÿÿiÿÿÿÿi   t   loct   scalei   s   , s*   dist({distargs}, loc={loc}, scale={scale})t   distargssŠ   Initializing the distribution failed.  This can occur if distargs contains loc or scale. The distribution initialization command is:
{cmd}t   cmd(   t   datat   at   shapet   nobsR   t   fitt
   isinstanceR   t   getattrR   t
   fit_paramsR   R   t   lent   dictt   distt	   Exceptiont   joint   strt   formatt	   TypeErrort   _cache(
   t   selfR   R   R   R   R   R   R   t   daR   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   __init__¤   s<    				%(				c         C   s   t  |  j |  j ƒ S(   s   Theoretical percentiles(   t   plotting_posR   R   (   R!   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   theoretical_percentilesÎ   s    c         C   sn   y |  j  j |  j ƒ SWnP t k
 rK d j |  j  j ƒ } t | ƒ ‚ n d j |  j  j ƒ } ‚  n Xd S(   s   Theoretical quantiless*   %s requires more parameters to compute ppfs    failed to compute the ppf of {0}N(   R   t   ppfR%   R   R   t   name(   R!   t   msg(    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   theoretical_quantilesÓ   s    c         C   s&   t  j |  j d t ƒ} | j ƒ  | S(   s   sorted datat   copy(   t   npt   arrayR   t   Truet   sort(   R!   t   sorted_data(    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR/   à   s    
c         C   sG   |  j  r< |  j d k r< |  j d k r< |  j |  j |  j S|  j Sd S(   s   sample quantilesi    i   N(   R   R   R   R/   (   R!   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   sample_quantilesç   s    'c         C   s/   |  j  |  j d |  j d } |  j j | ƒ S(   s   Sample percentilesiþÿÿÿiÿÿÿÿ(   R/   R   R   t   cdf(   R!   t	   quantiles(    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   sample_percentilesï   s    c      	   K   sF  | d	 k	 r¨ t | t ƒ } | s0 t | ƒ } n  |  j } t | j ƒ |  j ƒ }	 t | |	 |  j d | d | | \ }
 } | d	 k r d } n  | d	 k rd } qnZ t |  j |  j |  j d | d | | \ }
 } | d	 k rí d } n  | d	 k rd } n  | j	 | ƒ | j
 | ƒ | j d d g ƒ | j d d g ƒ |
 S(
   s8  
        P-P plot of the percentiles (probabilities) of x versus the
        probabilities (percetiles) of a distribution.

        Parameters
        ----------
        xlabel : str or None, optional
            User-provided lables for the x-axis. If None (default),
            other values are used depending on the status of the kwarg `other`.
        ylabel : str or None, optional
            User-provided lables for the y-axis. If None (default),
            other values are used depending on the status of the kwarg `other`.
        line : str {'45', 's', 'r', q'} or None, optional
            Options for the reference line to which the data is compared:

                - '45': 45-degree line
                - 's': standardized line, the expected order statistics are
                  scaled by the standard deviation of the given sample and have
                  the mean added to them
                - 'r': A regression line is fit
                - 'q': A line is fit through the quartiles.
                - None: by default no reference line is added to the plot.

        other : ProbPlot, array-like, or None, optional
            If provided, ECDF(x) will be plotted against p(x) where x are
            sorted samples from `self`. ECDF is an empirical cumulative
            distribution function estimated from `other` and
            p(x) = 0.5/n, 1.5/n, ..., (n-0.5)/n where n is the number of
            samples in `self`. If an array-object is provided, it will be
            turned into a `ProbPlot` instance default parameters. If not
            provided (default), `self.dist(x)` is be plotted against p(x).

        ax : Matplotlib AxesSubplot instance, optional
            If given, this subplot is used to plot in instead of a new figure
            being created.
        **plotkwargs : additional matplotlib arguments to be passed to the
            `plot` command.

        Returns
        -------
        fig : Matplotlib figure instance
            If `ax` is None, the created figure.  Otherwise the figure to which
            `ax` is connected.
        t   axt   lines   Probabilities of 2nd Samples   Probabilities of 1st Samples   Theoretical Probabilitiess   Sample Probabilitiesg        g      ð?N(   t   NoneR   R   R%   R   R0   t   _do_plotR   R3   t
   set_xlabelt
   set_ylabelt   set_xlimt   set_ylim(   R!   t   xlabelt   ylabelR5   t   otherR4   t
   plotkwargst   check_othert   p_xt   ecdf_xt   fig(    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   ppplotö   s2    .					c      	   K   s  | d	 k	 r	t | t ƒ } | s0 t | ƒ } n  |  j } | j }	 t | ƒ t |	 ƒ k rm t d d ƒ ‚ nE t | ƒ t |	 ƒ k  r² t |  j |  j ƒ }
 t	 j
 j |	 |
 ƒ }	 n  t |	 | |  j d | d | | \ } } | d	 k rñ d } n  | d	 k rcd } qcnZ t |  j |  j |  j d | d | | \ } } | d	 k rNd } n  | d	 k rcd } n  | j | ƒ | j | ƒ | S(
   s  
        Q-Q plot of the quantiles of x versus the quantiles/ppf of a
        distribution or the quantiles of another `ProbPlot` instance.

        Parameters
        ----------
        xlabel, ylabel : str or None, optional
            User-provided lables for the x-axis and y-axis. If None (default),
            other values are used depending on the status of the kwarg `other`.
        line : str {'45', 's', 'r', q'} or None, optional
            Options for the reference line to which the data is compared:

            - '45' - 45-degree line
            - 's' - standardized line, the expected order statistics are scaled
              by the standard deviation of the given sample and have the mean
              added to them
            - 'r' - A regression line is fit
            - 'q' - A line is fit through the quartiles.
            - None - by default no reference line is added to the plot.

        other : `ProbPlot` instance, array-like, or None, optional
            If provided, the sample quantiles of this `ProbPlot` instance are
            plotted against the sample quantiles of the `other` `ProbPlot`
            instance. Sample size of `other` must be equal or larger than
            this `ProbPlot` instance. If the sample size is larger, sample
            quantiles of `other` will be interpolated to match the sample size
            of this `ProbPlot` instance. If an array-like object is provided,
            it will be turned into a `ProbPlot` instance using default
            parameters. If not provided (default), the theoretical quantiles
            are used.
        ax : Matplotlib AxesSubplot instance, optional
            If given, this subplot is used to plot in instead of a new figure
            being created.
        **plotkwargs : additional matplotlib arguments to be passed to the
            `plot` command.

        Returns
        -------
        fig : Matplotlib figure instance
            If `ax` is None, the created figure.  Otherwise the figure to which
            `ax` is connected.
        s(   Sample size of `other` must be equal or s$   larger than this `ProbPlot` instanceR4   R5   s   Quantiles of 2nd Samples   Quantiles of 1st Samples   Theoretical Quantiless   Sample QuantilesN(   R6   R   R   R0   R   t
   ValueErrorR$   R   R   R   t   mstatst
   mquantilesR7   R   R)   R8   R9   (   R!   R<   R=   R5   R>   R4   R?   R@   t   s_selft   s_othert   pRC   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR   F  s:    ,						c      	   K   sé   | r[ t  |  j d d d … |  j |  j d | d | | \ } } | d k r  d } q  nE t  |  j |  j |  j d | d | | \ } } | d k r  d } n  | d k rµ d } n  | j | ƒ | j | ƒ t | |  j |  j ƒ | S(   su  
        Probability plot of the unscaled quantiles of x versus the
        probabilities of a distibution (not to be confused with a P-P plot).

        The x-axis is scaled linearly with the quantiles, but the probabilities
        are used to label the axis.

        Parameters
        ----------
        xlabel, ylabel : str or None, optional
            User-provided lables for the x-axis and y-axis. If None (default),
            other values are used depending on the status of the kwarg `other`.
        line : str {'45', 's', 'r', q'} or None, optional
            Options for the reference line to which the data is compared:

            - '45' - 45-degree line
            - 's' - standardized line, the expected order statistics are scaled
              by the standard deviation of the given sample and have the mean
              added to them
            - 'r' - A regression line is fit
            - 'q' - A line is fit through the quartiles.
            - None - by default no reference line is added to the plot.

        exceed : boolean, optional

             - If False (default) the raw sample quantiles are plotted against
               the theoretical quantiles, show the probability that a sample
               will not exceed a given value
             - If True, the theoretical quantiles are flipped such that the
               figure displays the probability that a sample will exceed a
               given value.
        ax : Matplotlib AxesSubplot instance, optional
            If given, this subplot is used to plot in instead of a new figure
            being created.
        **plotkwargs : additional matplotlib arguments to be passed to the
            `plot` command.

        Returns
        -------
        fig : Matplotlib figure instance
            If `ax` is None, the created figure.  Otherwise the figure to which
            `ax` is connected.
        NiÿÿÿÿR4   R5   s   Probability of Exceedance (%)s   Non-exceedance Probability (%)s   Sample Quantiles(	   R7   R)   R/   R   R6   R8   R9   t   _fmt_probplot_axisR   (   R!   R<   R=   R5   t   exceedR4   R?   RC   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   probplotš  s&    -			(    N(   t   __name__t
   __module__t   __doc__R   t   normt   FalseR#   R   R%   R)   R/   R0   R3   R6   RD   R   RM   (    (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR      s   “	)OS	i    c	         K   sO   t  |  d | d | d | d | d | d | ƒ}
 |
 j d | d | |	  } | S(	   sÞ  
    Q-Q plot of the quantiles of x versus the quantiles/ppf of a distribution.

    Can take arguments specifying the parameters for dist or fit them
    automatically. (See fit under Parameters.)

    Parameters
    ----------
    data : array-like
        1d data array
    dist : A scipy.stats or statsmodels distribution
        Compare x against dist. The default
        is scipy.stats.distributions.norm (a standard normal).
    distargs : tuple
        A tuple of arguments passed to dist to specify it fully
        so dist.ppf may be called.
    loc : float
        Location parameter for dist
    a : float
        Offset for the plotting position of an expected order statistic, for
        example. The plotting positions are given by (i - a)/(nobs - 2*a + 1)
        for i in range(0,nobs+1)
    scale : float
        Scale parameter for dist
    fit : boolean
        If fit is false, loc, scale, and distargs are passed to the
        distribution. If fit is True then the parameters for dist
        are fit automatically using dist.fit. The quantiles are formed
        from the standardized data, after subtracting the fitted loc
        and dividing by the fitted scale.
    line : str {'45', 's', 'r', q'} or None
        Options for the reference line to which the data is compared:

        - '45' - 45-degree line
        - 's' - standardized line, the expected order statistics are scaled
          by the standard deviation of the given sample and have the mean
          added to them
        - 'r' - A regression line is fit
        - 'q' - A line is fit through the quartiles.
        - None - by default no reference line is added to the plot.

    ax : Matplotlib AxesSubplot instance, optional
        If given, this subplot is used to plot in instead of a new figure being
        created.
    **plotkwargs : additional matplotlib arguments to be passed to the
            `plot` command.

    Returns
    -------
    fig : Matplotlib figure instance
        If `ax` is None, the created figure.  Otherwise the figure to which
        `ax` is connected.

    See Also
    --------
    scipy.stats.probplot

    Examples
    --------
    >>> import statsmodels.api as sm
    >>> from matplotlib import pyplot as plt
    >>> data = sm.datasets.longley.load(as_pandas=False)
    >>> data.exog = sm.add_constant(data.exog)
    >>> mod_fit = sm.OLS(data.endog, data.exog).fit()
    >>> res = mod_fit.resid # residuals
    >>> fig = sm.qqplot(res)
    >>> plt.show()

    qqplot of the residuals against quantiles of t-distribution with 4 degrees
    of freedom:

    >>> import scipy.stats as stats
    >>> fig = sm.qqplot(res, stats.t, distargs=(4,))
    >>> plt.show()

    qqplot against same as above, but with mean 3 and std 10:

    >>> fig = sm.qqplot(res, stats.t, distargs=(4,), loc=3, scale=10)
    >>> plt.show()

    Automatically determine parameters for t distribution including the
    loc and scale:

    >>> fig = sm.qqplot(res, stats.t, fit=True, line='45')
    >>> plt.show()

    The following plot displays some options, follow the link to see the code.

    .. plot:: plots/graphics_gofplots_qqplot.py

    Notes
    -----
    Depends on matplotlib. If `fit` is True then the parameters are fit using
    the distribution's fit() method.

    R   R   R   R   R   R   R4   R5   (   R   R   (   R   R   R   R   R   R   R   R5   R4   R?   RM   RC   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR   á  s    bc         C   sj   t  |  t ƒ s t |  ƒ }  n  t  | t ƒ s< t | ƒ } n  |  j d | d | d | d | d | ƒ } | S(   s!	  
    Q-Q Plot of two samples' quantiles.

    Can take either two `ProbPlot` instances or two array-like objects. In the
    case of the latter, both inputs will be converted to `ProbPlot` instances
    using only the default values - so use `ProbPlot` instances if
    finer-grained control of the quantile computations is required.

    Parameters
    ----------
    data1, data2 : array-like (1d) or `ProbPlot` instances
    xlabel, ylabel : str or None
        User-provided labels for the x-axis and y-axis. If None (default),
        other values are used.
    line : str {'45', 's', 'r', q'} or None
        Options for the reference line to which the data is compared:

        - '45' - 45-degree line
        - 's' - standardized line, the expected order statistics are scaled
          by the standard deviation of the given sample and have the mean
          added to them
        - 'r' - A regression line is fit
        - 'q' - A line is fit through the quartiles.
        - None - by default no reference line is added to the plot.

    ax : Matplotlib AxesSubplot instance, optional
        If given, this subplot is used to plot in instead of a new figure being
        created.

    Returns
    -------
    fig : Matplotlib figure instance
        If `ax` is None, the created figure.  Otherwise the figure to which
        `ax` is connected.

    See Also
    --------
    scipy.stats.probplot

    Examples
    --------
    >>> import statsmodels.api as sm
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from statsmodels.graphics.gofplots import qqplot_2samples
    >>> x = np.random.normal(loc=8.5, scale=2.5, size=37)
    >>> y = np.random.normal(loc=8.0, scale=3.0, size=37)
    >>> pp_x = sm.ProbPlot(x)
    >>> pp_y = sm.ProbPlot(y)
    >>> qqplot_2samples(pp_x, pp_y)
    >>> plt.show()

    .. plot:: plots/graphics_gofplots_qqplot_2samples.py

    >>> fig = qqplot_2samples(pp_x, pp_y, xlabel=None, ylabel=None,     ...                       line=None, ax=None)

    Notes
    -----
    1) Depends on matplotlib.
    2) If `data1` and `data2` are not `ProbPlot` instances, instances will be
       created using the default parameters. Therefore, it is recommended to use
       `ProbPlot` instance if fine-grained control is needed in the computation
       of the quantiles.

    R<   R=   R5   R>   R4   (   R   R   R   (   t   data1t   data2R<   R=   R5   R4   RC   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR	   I  s    Ds   r-c         C   sÊ  | d k r€ t  |  j ƒ  |  j ƒ  ƒ } t | d ƒ | d <t | d ƒ | d <|  j | | | ƒ |  j | ƒ |  j | ƒ d S| d k r§ | d k r§ t	 d ƒ ‚ n| d k rç t
 | t | ƒ ƒ j ƒ  j } |  j | | | ƒ nß | d k r0| j ƒ  | j ƒ  } } | | | }	 |  j | |	 | ƒ n– | d k rÆt | ƒ t j | d	 ƒ }
 t j | d
 ƒ } | j d d g ƒ } | |
 t j | ƒ } |
 | | d } |  j | | | | | ƒ n  d S(   s’  
    Plot a reference line for a qqplot.

    Parameters
    ----------
    ax : matplotlib axes instance
        The axes on which to plot the line
    line : str {'45','r','s','q'}
        Options for the reference line to which the data is compared.:

        - '45' - 45-degree line
        - 's'  - standardized line, the expected order statistics are scaled by
                 the standard deviation of the given sample and have the mean
                 added to them
        - 'r'  - A regression line is fit
        - 'q'  - A line is fit through the quartiles.
        - None - By default no reference line is added to the plot.

    x : array
        X data for plot. Not needed if line is '45'.
    y : array
        Y data for plot. Not needed if line is '45'.
    dist : scipy.stats.distribution
        A scipy.stats distribution, needed if line is 'q'.

    Notes
    -----
    There is no return value. The line is plotted on the given `ax`.

    Examples
    --------
    Import the food expenditure dataset.  Plot annual food expendeture on x-axis
    and household income on y-axis.  Use qqline to add regression line into the
    plot.

    >>> import statsmodels.api as sm
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from statsmodels.graphics.gofplots import qqline

    >>> foodexp = sm.datasets.engel.load(as_pandas=False)
    >>> x = foodexp.exog
    >>> y = foodexp.endog
    >>> ax = plt.subplot(111)
    >>> plt.scatter(x, y)
    >>> ax.set_xlabel(foodexp.exog_name[0])
    >>> ax.set_ylabel(foodexp.endog_name)
    >>> qqline(ax, 'r', x, y)
    >>> plt.show()

    .. plot:: plots/graphics_gofplots_qqplot_qqline.py

    t   45i    i   Ns*   If line is not 45, x and y cannot be None.t   rt   st   qi   iK   g      Ð?g      è?(   R    t   get_xlimt   get_ylimt   mint   maxt   plotR:   R;   R6   RE   R   R   R   t   fittedvaluest   stdt   meant   _check_for_ppfR   t   scoreatpercentileR&   R+   t   diff(   R4   R5   t   xt   yR   t   fmtt   end_ptst   mt   bt   ref_linet   q25t   q75t   theoretical_quartiles(    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR
   ™  s2    6
c         C   s(   t  j d |  d ƒ | |  d | d S(   s  
    Generates sequence of plotting positions

    Parameters
    ----------
    nobs : int
        Number of probability points to plot
    a : float
        Offset for the plotting position of an expected order statistic, for
        example.

    Returns
    -------
    plotting_positions : array
        The plotting positions

    Notes
    -----
    The plotting positions are given by (i - a)/(nobs - 2*a + 1) for i in
    range(0,nobs+1)

    See Also
    --------
    scipy.stats.mstats.plotting_positions
    g      ð?i   i   (   R+   t   arange(   R   R   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR$   í  s    c         C   s†  t  | ƒ | d k  rY t j d d d d d d d d d	 d
 d d d d d g ƒ d } nÅ | d k  rº t j d d d d d d d d d d d d	 d
 d d d d d d d d g ƒ d } nd t j 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 g ƒ d } | j | ƒ } |  j | ƒ |  j | d d d  d! d" d# d$ d% d& ƒ|  j | j ƒ  | j ƒ  g ƒ d' S((   s  
    Formats a theoretical quantile axis to display the corresponding
    probabilities on the quantiles' scale.

    Parameteters
    ------------
    ax : Matplotlib AxesSubplot instance, optional
        The axis to be formatted
    nobs : scalar
        Numbero of observations in the sample
    dist : scipy.stats.distribution
        A scipy.stats distribution sufficiently specified to impletment its
        ppf() method.

    Returns
    -------
    There is no return value. This operates on `ax` in place
    i2   i   i   i   i
   i   i   i(   i<   iF   iP   iZ   i_   ib   ic   g      Y@iô  gš™™™™™¹?gš™™™™™É?g      à?g     àX@g33333óX@gš™™™™ùX@g{®Gáz„?g{®Gáz”?gš™™™™™©?gÍÌÌÌÌüX@g…ëQ¸þX@gÂõ(\ÿX@id   t   rotationi-   t   rotation_modet   anchort   horizontalalignmentt   rightt   verticalalignmentt   centerN(	   Ra   R+   R,   R&   t
   set_xtickst   set_xticklabelsR:   R[   R\   (   R4   R   R   t
   axis_probst
   axis_qntls(    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyRK   
  s$    
!"*$!t   boc   	   	   K   s   t  j | ƒ \ } } | j d ƒ | j |  | | |  | r… | d
 k rc d | } t | ƒ ‚ n  t | | d |  d | d	 | ƒn  | | f S(   sJ  
    Boiler plate plotting function for the `ppplot`, `qqplot`, and
    `probplot` methods of the `ProbPlot` class

    Parameteters
    ------------
    x, y : array-like
        Data to be plotted
    dist : scipy.stats.distribution
        A scipy.stats distribution, needed if `line` is 'q'.
    line : str {'45', 's', 'r', q'} or None
        Options for the reference line to which the data is compared.
    ax : Matplotlib AxesSubplot instance, optional
        If given, this subplot is used to plot in instead of a new figure being
        created.
    fmt : str, optional
        matplotlib-compatible formatting string for the data markers
    kwargs : keywords
        These are passed to matplotlib.plot

    Returns
    -------
    fig : Matplotlib Figure instance
    ax : Matplotlib AxesSubplot instance (see Parameters)

    g{®Gáz”?RV   RX   RU   RW   s!   %s option for line not understoodRd   Re   R   (   RV   RX   RU   RW   (   R   t   create_mpl_axt   set_xmarginR]   RE   R
   (	   Rd   Re   R   R5   R4   Rf   t   kwargsRC   R(   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyR7   2  s    
"c         C   s"   t  |  d ƒ s t d ƒ ‚ n  d  S(   NR&   s#   distribution must have a ppf method(   t   hasattrRE   (   R   (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyRa   Z  s    (   t   statsmodels.compat.pythonR    R   t   numpyR+   t   scipyR   t#   statsmodels.regression.linear_modelR   t   statsmodels.tools.toolsR   t   statsmodels.tools.decoratorsR   t   statsmodels.distributionsR   t    R   t   __all__t   objectR   RQ   RR   R6   R   R	   R
   R$   RK   R7   Ra   (    (    (    s<   lib/python2.7/site-packages/statsmodels/graphics/gofplots.pyt   <module>   s&   ÿ Óg	OT		((