
    >h֎                         S SK Jr  S SKrS SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  SS	KJr  / S
Qr " S S5      r\R$                  SS S SSSS4S jr SS jrSS jrSS jrS r SS jrSS jrg)    )lzipN)stats)ECDF)OLS)cache_readonly)add_constant   )utils)qqplotqqplot_2samplesqqlineProbPlotc                       \ rS rSrSr\R                  SSSSS4S jr\S 5       r	\S	 5       r
\S
 5       r\S 5       r\S 5       r     SS jr      SS\4S jjr     SS jrSrg)r      a  
Q-Q and P-P Probability Plots

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

Parameters
----------
data : array_like
    A 1d data array
dist : callable
    Compare x against dist. A scipy.stats or statsmodels distribution. The
    default is scipy.stats.distributions.norm (a standard normal). Can be
    a SciPy frozen distribution.
fit : bool
    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. fit cannot be used if dist is a SciPy frozen
    distribution.
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. distargs cannot be used
    if dist is a SciPy frozen distribution.
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. Cannot be used if dist is a SciPy frozen
    distribution.
scale : float
    Scale parameter for dist. Cannot be used if dist is a SciPy frozen
    distribution.

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()
>>> data.exog = sm.add_constant(data.exog)
>>> model = sm.OLS(data.endog, data.exog)
>>> mod_fit = model.fit()
>>> res = mod_fit.resid # residuals
>>> pplot = sm.ProbPlot(res)
>>> fig = pplot.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
>>> pplot = sm.ProbPlot(res, stats.t, distargs=(4,))
>>> fig = pplot.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
>>> pplot = sm.ProbPlot(res, stats.t, distargs=(4,), loc=3, scale=10)
>>> fig = pplot.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
>>> pplot = sm.ProbPlot(res, stats.t, fit=True)
>>> fig = pplot.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)
>>> pp_y.ppplot(line="45", other=pp_x)
>>> plt.title("Ex. 7A- ppplot - compare two sample sets, other=pp_x")
>>> pp_x.ppplot(line="45", other=pp_y)
>>> 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
F r   r	   c           	         Xl         XPl        UR                  S   U l        X@l        X0l        [        U[        R                  R                  5      U l
        U R                  (       a$  U(       d  US:w  d  US:w  d  US:w  a  [        S5      e0 U l        U R                  (       Gan  X l        UR                  nUR                  n	U	b3  [        [!        ["        R$                  U	R'                  S5      5      5      n
OSn
[)        U
5      nUR*                  n[)        U5      US-   :  a
  X   U l        O!UR.                  R1                  SU5      U l        [)        U5      US-   :  a  XS-      U l        O!UR.                  R1                  SU5      U l        / n[5        U
5       HD  u  pXR.                  ;   a  UR.                  U   nOUR*                  U   nUR7                  U5        MF     [8        R:                  XR,                  U R2                  4   U l        g U(       a  UR                  U5      U l        U R<                  S	   U l        U R<                  S
   U l        [)        U R<                  5      S:  a#  U" U R<                  S S	 0 [?        SSS9D6U l        g U" SSS9U l        g U(       d  US:w  d  US:w  a<   U" U0 [?        XgS9D6U l        X`l        Xpl        [8        R:                  XFU4   U l        g X l        X`l        Xpl        [8        R:                  Xg4   U l        g ! [@         a\    SRC                  U Vs/ s H  n[#        U5      PM     Os  snf sn5      nSnURE                  XFUS9n[G        SRE                  US95      ef = f)Nr   r	   r   zIFrozen distributions cannot be combined with fit, loc, scale or distargs.,loc   scale)r   r   z, z*dist({distargs}, loc={loc}, scale={scale}))distargsr   r   zInitializing the distribution failed.  This can occur if distargs contains loc or scale. The distribution initialization command is:
{cmd})cmd)$dataashapenobsr   fit
isinstancer   distributions	rv_frozen
_is_frozen
ValueError_cachedistshapestuplemapstrstripsplitlenargsr   kwdsgetr   	enumerateappendnpr_
fit_paramsdict	Exceptionjoinformat	TypeError)selfr   r&   r   r   r   r   r   dist_genr'   
shape_argsnumargsr.   r5   iargvaluedar   s                      pC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/graphics/gofplots.py__init__ProbPlot.__init__   s    	JJqM	 $T5+>+>+H+HI??3!8uzX^  
 ???IyyH__F!"3syy&,,s2C#DE

*oG99D4yGaK'=99==44yGaK'!A+.
!YY]]7E:
J#J/))# IIcNE IIaLE!!%( 0 !eeJ$**$DEDO"hhtnDOr*DH,DJ4??#a' $//#2"6O$1A:NO	 Qa0	UaZ (Ids.HI	 HJ eeH5$89DOIHJ eeCJ/DO#  	99%A"c"g%ABBjj(5jI! "(C	 		s   4L N4M

	8Nc                 B    [        U R                  U R                  5      $ )zTheoretical percentiles)plotting_posr   r   r;   s    rC   theoretical_percentiles ProbPlot.theoretical_percentiles   s     DIItvv..    c                      U R                   R                  U R                  5      $ ! [         a%    U R                   R                   S3n[        U5      e[
         a/  nSU R                   R                   3n[        U5      " U5      eSnAff = f)zTheoretical quantilesz( requires more parameters to compute ppfzfailed to compute the ppf of N)r&   ppfrI   r:   namer7   type)r;   msgexcs      rC   theoretical_quantilesProbPlot.theoretical_quantiles  s{    	!99==!=!=>> 	!YY^^$$LMCC.  	!1$))..1ABCs)C. 	!s   $' 7B*BBc                 j    [         R                  " [         R                  " U R                  5      5      $ )zsorted data)r3   sortarrayr   rH   s    rC   sorted_dataProbPlot.sorted_data  s      wwrxx		*++rK   c                     U R                   (       aF  U R                  S:w  a6  U R                  S:w  a&  U R                  U R                  -
  U R                  -  $ U R                  $ )zsample quantilesr   r	   )r   r   r   rW   rH   s    rC   sample_quantilesProbPlot.sample_quantiles  sI     88A$**/$$txx/4::==###rK   c                 (   [        U R                  S5        U R                  (       a%  U R                  R                  U R                  5      $ U R                  U R
                  S   -
  U R
                  S   -  nU R                  R                  U5      $ )zSample percentilescdfr   r   )
_check_forr&   r#   r]   rW   r5   )r;   	quantiless     rC   sample_percentilesProbPlot.sample_percentiles  st     	499e$??99==!1!122%%(;;t@
 
	 yy}}Y''rK   Nc                    Uby  [        U[        5      nU(       d  [        U5      nU R                  n[        UR                  5      " U R                  5      n	[        XU R                  4XSS.UD6u  pUc  SnUc  SnO;[        U R                  U R                  U R                  4UUS.UD6u  pUc  SnUc  SnUR                  U5        UR                  U5        UR                  SS/5        UR                  SS/5        U
$ )a  
Plot of the percentiles of x versus the percentiles of a distribution.

Parameters
----------
xlabel : str or None, optional
    User-provided labels 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 labels for the y-axis. If None (default),
    other values are used depending on the status of the kwarg `other`.
line : {None, "45", "s", "r", q"}, 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 : AxesSubplot, optional
    If given, this subplot is used to plot in instead of a new figure
    being created.
**plotkwargs
    Additional arguments to be passed to the `plot` command.

Returns
-------
Figure
    If `ax` is None, the created figure.  Otherwise the figure to which
    `ax` is connected.
axlinezProbabilities of 2nd SamplezProbabilities of 1st SamplezTheoretical ProbabilitieszSample Probabilities              ?)r    r   rI   r   rZ   _do_plotr&   r`   
set_xlabel
set_ylabelset_xlimset_ylim)r;   xlabelylabelre   otherrd   
plotkwargscheck_otherp_xecdf_xfigs              rC   ppplotProbPlot.ppplot%  s   h $UH5K ..C%001$2G2GHFTYY+-<FGC ~6~6 ,,''		  GC ~4~/
f
f
S#J
S#J
rK   swapc                    Ub  [        U[        5      nU(       d  [        U5      nU R                  n	UR                  n
[        U	5      [        U
5      :  a  [	        S5      e[        U	5      [        U
5      :  a?  [        U R                  U R                  5      n[        R                  R                  X5      n
[        XU R                  4XSS.UD6u  pUc  SnUc  SnU(       a  X!p!O;[        U R                  U R                  U R                  4UUS.UD6u  pUc  SnUc  SnUR                  U5        UR                  U5        U$ )a|  
Plot of the quantiles of x versus the quantiles/ppf of a distribution.

Can also be used to plot against the quantiles of another `ProbPlot`
instance.

Parameters
----------
xlabel : {None, str}
    User-provided labels for the x-axis. If None (default),
    other values are used depending on the status of the kwarg `other`.
ylabel : {None, str}
    User-provided labels for the y-axis. If None (default),
    other values are used depending on the status of the kwarg `other`.
line : {None, "45", "s", "r", q"}, 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, 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 : AxesSubplot, optional
    If given, this subplot is used to plot in instead of a new figure
    being created.
swap : bool, optional
    Flag indicating to swap the x and y labels.
**plotkwargs
    Additional arguments to be passed to the `plot` command.

Returns
-------
Figure
    If `ax` is None, the created figure.  Otherwise the figure to which
    `ax` is connected.
zLSample size of `other` must be equal or larger than this `ProbPlot` instancerc   zQuantiles of 2nd SamplezQuantiles of 1st SamplezTheoretical QuantilesSample Quantiles)r    r   rZ   r-   r$   rG   r   r   r   mstats
mquantilesrh   r&   rR   ri   rj   )r;   rm   rn   re   ro   rd   rw   rp   rq   s_selfs_otherprt   s                rC   r   ProbPlot.qqplot  sL   v $UH5K **F,,G6{S\) =  Vs7|+ !DFF3,,11'=/1@JGC ~2~2!' **%%		  GC ~0~+
f
f
rK   c                    U(       a=  [        U R                  SSS2   U R                  U R                  4UUS.UD6u  puUc  SnO6[        U R                  U R                  U R                  4UUS.UD6u  puUc  SnUc  SnUR	                  U5        UR                  U5        [        XPR                  U R                  5        U$ )aO  
Plot of unscaled quantiles of x against the prob of a distribution.

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

Parameters
----------
xlabel : {None, str}, optional
    User-provided labels for the x-axis. If None (default),
    other values are used depending on the status of the kwarg `other`.
ylabel : {None, str}, optional
    User-provided labels for the y-axis. If None (default),
    other values are used depending on the status of the kwarg `other`.
line : {None, "45", "s", "r", q"}, 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 : bool, 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 : AxesSubplot, optional
    If given, this subplot is used to plot in instead of a new figure
    being created.
**plotkwargs
    Additional arguments to be passed to the `plot` command.

Returns
-------
Figure
    If `ax` is None, the created figure.  Otherwise the figure to which
    `ax` is connected.
Nr   rc   zProbability of Exceedance (%)zNon-exceedance Probability (%)ry   )rh   rR   rW   r&   ri   rj   _fmt_probplot_axisr   )r;   rm   rn   re   exceedrd   rp   rt   s           rC   probplotProbPlot.probplot  s    h **4R40  		  GC ~8 **  		  GC ~9>'F
f
f2yy$))4
rK   )r%   r#   r   r   r&   r   r   r5   r   r   r   )NNNNN)NNNNNF)NNNFN)__name__
__module____qualname____firstlineno____doc__r   normrD   r   rI   rR   rW   rZ   r`   ru   boolr   r   __static_attributes__r   rK   rC   r   r      s    Vv ZZ
Q0f / / 	! 	! , , $ $ ( ( Yz i iZ SrK   r   r   Fc	           
      F    [        XX&X4US9n
U
R                  " SXS.U	D6nU$ )a3  
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
    A 1d data array.
dist : callable
    Comparison distribution. 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.
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 : bool
    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 : {None, "45", "s", "r", "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.

ax : AxesSubplot, 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
-------
Figure
    If `ax` is None, the created figure.  Otherwise the figure to which
    `ax` is connected.

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

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

Examples
--------
>>> import statsmodels.api as sm
>>> from matplotlib import pyplot as plt
>>> data = sm.datasets.longley.load()
>>> exog = sm.add_constant(data.exog)
>>> mod_fit = sm.OLS(data.endog, 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
)r&   r   r   r   r   r   rc   r   )r   r   )r   r&   r   r   r   r   r   re   rd   rp   r   rt   s               rC   r   r   A  s5    V (qH //
9R
9j
9CJrK   c           	      <   [        U [        5      (       d  [        U 5      n [        U[        5      (       d  [        U5      nUR                  R                  S   U R                  R                  S   :  a  U R	                  X2XAUS9nU$ UR	                  UUUU USS9nU$ )a	  
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 : {array_like, ProbPlot}
    Data to plot along x axis. If the sample sizes are unequal, the longer
    series is always plotted along the x-axis.
data2 : {array_like, ProbPlot}
    Data to plot along y axis. Does not need to have the same number of
    observations as data 1. If the sample sizes are unequal, the longer
    series is always plotted along the x-axis.
xlabel : {None, str}
    User-provided labels for the x-axis. If None (default),
    other values are used.
ylabel : {None, str}
    User-provided labels for the y-axis. If None (default),
    other values are used.
line : {None, "45", "s", "r", 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.

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

Returns
-------
Figure
    If `ax` is None, the created figure.  Otherwise the figure to which
    `ax` is connected.

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

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.

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)
r   )rm   rn   re   ro   rd   T)rm   rn   re   ro   rd   rw   )r    r   r   r   r   )data1data2rm   rn   re   rd   rt   s          rC   r   r     s    Z eX&&eX&&zzUZZ--a00lltR  
 J ll  
 JrK   c                    UR                  5       nS H.  nXu;   d  M
  UR                  SU5        UR                  US5      n  O   S H.  nX;   d  M
  UR                  SU5        UR                  US5      n  O   U(       a  UR                  SU5        US:X  a  [        U R	                  5       U R                  5       5      n	[        U	S   5      U	S'   [        U	S	   5      U	S	'   U R                  " X40 UD6  U R                  U	5        U R                  U	5        g
Ub  Uc  [        S5      e[        R                  " U5      n[        R                  " U5      nUS:X  aA  [        U[        U5      5      R!                  5       R"                  nU R                  " X#40 UD6  g
US:X  aF  [        R$                  " U5      [        R&                  " U5      pX*-  U-   nU R                  " X,40 UD6  g
US:X  a  [)        US5        [*        R,                  " US5      n[*        R,                  " US5      nUR/                  SS/5      nX-
  [        R0                  " U5      -  n
XUS   -  -
  nU R                  " X*U-  U-   40 UD6  g
g
)ab  
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 : ndarray
    X data for plot. Not needed if line is "45".
y : ndarray
    Y data for plot. Not needed if line is "45".
dist : scipy.stats.distribution
    A scipy.stats distribution, needed if line is "q".
fmt : str, optional
    Line format string passed to `plot`.
**lineoptions
    Additional arguments to be passed to the `plot` command.

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

Examples
--------
Import the food expenditure dataset.  Plot annual food expenditure 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()
>>> 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
)-z--z-.:	linestyle ).r   ov^<>12348sr~   P*hH+xXDd|_markercolor45r   r	   Nz*If line is not 45, x and y cannot be None.rr   qrM      K   g      ?g      ?)copy
setdefaultreplacer   get_xlimget_ylimminmaxplotrk   rl   r$   r3   rV   r   r   r   fittedvaluesstdmeanr^   r   scoreatpercentilerM   diff)rd   re   r   yr&   fmtlineoptionslsr   end_ptsmbref_lineq25q75theoretical_quartiless                   rC   r   r     s.   r ""$K$9"";3++b"%C	 %
6 =""8V4++fb)C=> w,t|r{{}bkkm4_
_

0K0
G
GyAIEFF
A
As{ <?#'')66
$$	vvay"''!*1519
+{+	4%%a,%%a, $$ 6Y"''"788+A...
q519,, 
rK   c                 b    Uc  UOUn[         R                  " SU S-   5      U-
  U S-   U-
  U-
  -  $ )ac  
Generates sequence of plotting positions

Parameters
----------
nobs : int
    Number of probability points to plot
a : float, default 0.0
    alpha parameter for the plotting position of an expected order
    statistic
b : float, default None
    beta parameter for the plotting position of an expected order
    statistic. If None, then b is set to a.

Returns
-------
ndarray
    The plotting positions

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

See Also
--------
scipy.stats.mstats.plotting_positions
    Additional information on alpha and beta
rg   r	   )r3   arange)r   r   r   s      rC   rG   rG     s;    < YAAIIc4!8$q(TAX\A-=>>rK   c                    [        US5        [        R                  " SSS[        S9n[        R                  " / SQ5      n[        R
                  XCSUSSS	2   -
  4   nUS
:  a%  [        R
                  US-  USUSSS	2   S-  -
  4   nUS:  a%  [        R
                  US-  USUSSS	2   S-  -
  4   nUS-  nUR                  U5      nU R                  U5        U R                  US-   Vs/ s H  n[        U5      PM     snSSSSS9  U R                  UR                  5       UR                  5       /5        gs  snf )a  
Formats a theoretical quantile axis to display the corresponding
probabilities on the quantiles' scale.

Parameters
----------
ax : AxesSubplot, optional
    The axis to be formatted
nobs : scalar
    Number of observations in the sample
dist : scipy.stats.distribution
    A scipy.stats distribution sufficiently specified to implement its
    ppf() method.

Returns
-------
There is no return value. This operates on `ax` in place
rM   
   Z   	   )dtype)rg   r      d   Nr   2   i  g      Y@-   anchorrightcenter)rotationrotation_modehorizontalalignmentverticalalignment)r^   r3   linspacefloatrV   r4   rM   
set_xticksset_xticklabelsr*   rk   r   r   )rd   r&   r   
axis_probssmall
axis_qntlslbls          rC   r   r     s:   & tURQe4JHH[!Eu#dd*;;<JrzUU52:z3ttr9I3IIJ
s{UU53;
C%"+:K4KKL
%J*%JMM*(3.0.cS.0#"   KK!:>>#345 	1s   -D;c                 d   SSSSS.nUR                   " S0 UD6  UR                  SS5      n	[        R                  " U5      u  pUR	                  S5        U(       a  UR
                  " XU4SU	0UD6  OUR                  " XU40 UD6  U(       a!  US;  a  S	U-  n[        U5      e[        XCXUS
9  X4$ )a8  
Boiler plate plotting function for the `ppplot`, `qqplot`, and
`probplot` methods of the `ProbPlot` class

Parameters
----------
x : array_like
    X-axis data to be plotted
y : array_like
    Y-axis data to be plotted
dist : scipy.stats.distribution
    A scipy.stats distribution, needed if `line` is "q".
line : {"45", "s", "r", "q", None}, default None
    Options for the reference line to which the data is compared.
ax : AxesSubplot, 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 : Figure
    The figure containing `ax`.
ax : AxesSubplot
    The original axes if provided.  Otherwise a new instance.
r   C0none)r   markerfacecolormarkeredgecolorr   wherepreg{Gz?)r   r   r   r   z!%s option for line not understood)r   r   r&   r   )	updatepopr
   create_mpl_axset_xmarginstepr   r$   r   )r   r   r&   re   rd   r   r   kwargs
plot_styler   rt   rP   s               rC   rh   rh     s    B 	J NN7E*E!!"%GCNN4
c55*5
c(Z(,,5<CS/!r1-7NrK   c                 B    [        X5      (       d  [        SU S35      eg )Nzdistribution must have a z method)hasattrAttributeError)r&   attrs     rC   r^   r^     s'    48gFGG rK   )NNNN)NNNzr-)rf   N)NNNr   F)rM   )statsmodels.compat.pythonr   numpyr3   scipyr   statsmodels.distributionsr   #statsmodels.regression.linear_modelr   statsmodels.tools.decoratorsr   statsmodels.tools.toolsr   r   r
   __all__r   r   r   r   r   rG   r   rh   r^   r   rK   rC   <module>r      s    *   * 3 7 0 
=n nf 
	
	of ;?`F}-B?D%6R 8=8vHrK   