Module Expr Str Import alias identifier ImportFrom alias identifier FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults BinOpDiv Num Num Num Num NameLoad Str NameLoad body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad If CompareNotEq AttributeLoad NameLoad attr Num body Raise Call NameLoad Str If CompareNotEq AttributeLoad NameLoad attr Num body Raise Call NameLoad Str If CompareNotEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num body Raise Call NameLoad Str If CompareIn NameLoad ListLoad Str Str body Assign NameStore BinOpBitAnd Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If NameLoad body Assign NameStore NameLoad Assign NameStore NameLoad orelse If CompareEq NameLoad Str body Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore SubscriptLoad NameLoad Index NameLoad orelse Raise Call NameLoad Str orelse If CompareEq NameLoad Str body Assign NameStore NameLoad Assign NameStore NameLoad Assign NameStore NameLoad orelse Raise Call NameLoad Str If UnaryOpNot NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index NameLoad Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index NameLoad Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Assign TupleStore NameStore NameStore AttributeLoad NameLoad attr If NameLoad body Return NameLoad orelse If UnaryOpNot NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign SubscriptStore NameLoad Index NameLoad NameLoad Assign NameStore NameLoad orelse Assign NameStore NameLoad If UnaryOpNot NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign SubscriptStore NameLoad Index NameLoad NameLoad Assign NameStore NameLoad Return NameLoad decorator_list
N/A N/A Lowess - wrapper for cythonized extension

Author : Chris Jordan-Squire
Author : Carl Vogel
Author : Josef Perktold

 N/A numpy np _smoothers_lowess lowess _lowess lowess N/A N/A endog exog frac it delta is_sorted missing return_sorted N/A N/A 2.0 3.0 3 0.0 False drop True N/A N/A LOWESS (Locally Weighted Scatterplot Smoothing)

    A lowess function that outs smoothed estimates of endog
    at the given exog values from points (exog, endog)

    Parameters
    ----------
    endog: 1-D numpy array
        The y-values of the observed points
    exog: 1-D numpy array
        The x-values of the observed points
    frac: float
        Between 0 and 1. The fraction of the data used
        when estimating each y-value.
    it: int
        The number of residual-based reweightings
        to perform.
    delta: float
        Distance within which to use linear-interpolation
        instead of weighted regression.
    is_sorted : bool
        If False (default), then the data will be sorted by exog before
        calculating lowess. If True, then it is assumed that the data is
        already sorted by exog.
    missing : str
        Available options are 'none', 'drop', and 'raise'. If 'none', no nan
        checking is done. If 'drop', any observations with nans are dropped.
        If 'raise', an error is raised. Default is 'drop'.
    return_sorted : bool
        If True (default), then the returned array is sorted by exog and has
        missing (nan or infinite) observations removed.
        If False, then the returned array is in the same length and the same
        sequence of observations as the input array.

    Returns
    -------
    out: ndarray, float
        The returned array is two-dimensional if return_sorted is True, and
        one dimensional if return_sorted is False.
        If return_sorted is True, then a numpy array with two columns. The
        first column contains the sorted x (exog) values and the second column
        the associated estimated y (endog) values.
        If return_sorted is False, then only the fitted values are returned,
        and the observations will be in the same order as the input arrays.

    Notes
    -----
    This lowess function implements the algorithm given in the
    reference below using local linear estimates.

    Suppose the input data has N points. The algorithm works by
    estimating the `smooth` y_i by taking the frac*N closest points
    to (x_i,y_i) based on their x values and estimating y_i
    using a weighted linear regression. The weight for (x_j,y_j)
    is tricube function applied to abs(x_i-x_j).

    If it > 1, then further weighted local linear regressions
    are performed, where the weights are the same as above
    times the _lowess_bisquare function of the residuals. Each iteration
    takes approximately the same amount of time as the original fit,
    so these iterations are expensive. They are most useful when
    the noise has extremely heavy tails, such as Cauchy noise.
    Noise with less heavy-tails, such as t-distributions with df>2,
    are less problematic. The weights downgrade the influence of
    points with large residuals. In the extreme case, points whose
    residuals are larger than 6 times the median absolute residual
    are given weight 0.

    `delta` can be used to save computations. For each `x_i`, regressions
    are skipped for points closer than `delta`. The next regression is
    fit for the farthest point within delta of `x_i` and all points in
    between are estimated by linearly interpolating between the two
    regression fits.

    Judicious choice of delta can cut computation time considerably
    for large data (N > 5000). A good choice is ``delta = 0.01 * range(exog)``.

    Some experimentation is likely required to find a good
    choice of `frac` and `iter` for a particular dataset.

    References
    ----------
    Cleveland, W.S. (1979) "Robust Locally Weighted Regression
    and Smoothing Scatterplots". Journal of the American Statistical
    Association 74 (368): 829-836.

    Examples
    --------
    The below allows a comparison between how different the fits from
    lowess for different values of frac can be.

    >>> import numpy as np
    >>> import statsmodels.api as sm
    >>> lowess = sm.nonparametric.lowess
    >>> x = np.random.uniform(low = -2*np.pi, high = 2*np.pi, size=500)
    >>> y = np.sin(x) + np.random.normal(size=len(x))
    >>> z = lowess(y, x)
    >>> w = lowess(y, x, frac=1./3)

    This gives a similar comparison for when it is 0 vs not.

    >>> import numpy as np
    >>> import scipy.stats as stats
    >>> import statsmodels.api as sm
    >>> lowess = sm.nonparametric.lowess
    >>> x = np.random.uniform(low = -2*np.pi, high = 2*np.pi, size=500)
    >>> y = np.sin(x) + stats.cauchy.rvs(size=len(x))
    >>> z = lowess(y, x, frac= 1./3, it=0)
    >>> w = lowess(y, x, frac=1./3)

     N/A endog N/A N/A np asarray endog float N/A exog N/A N/A np asarray exog float N/A N/A N/A exog ndim 1 N/A N/A N/A ValueError exog must be a vector N/A N/A N/A endog ndim 1 N/A N/A N/A ValueError endog must be a vector N/A N/A N/A N/A endog shape N/A 0 N/A N/A exog shape N/A 0 N/A N/A N/A ValueError exog and endog must have same length N/A N/A missing N/A drop raise N/A N/A mask_valid N/A N/A N/A np isfinite exog N/A N/A np isfinite endog N/A all_valid N/A N/A np all mask_valid N/A all_valid N/A N/A y endog N/A x exog N/A N/A N/A missing drop N/A N/A x N/A exog N/A mask_valid N/A y N/A endog N/A mask_valid N/A N/A N/A ValueError nan or inf found in data N/A N/A N/A missing none N/A N/A y endog N/A x exog N/A all_valid True N/A N/A N/A ValueError missing can only be 'none', 'drop' or 'raise' N/A N/A is_sorted N/A N/A sort_index N/A N/A np argsort x N/A x N/A N/A np array N/A x N/A sort_index N/A y N/A N/A np array N/A y N/A sort_index N/A res N/A _lowess y x frac frac it it delta delta N/A N/A _ yfitted N/A res T N/A return_sorted N/A N/A res N/A N/A N/A is_sorted N/A N/A yfitted_ N/A N/A np empty_like y N/A N/A N/A yfitted_ fill N/A np nan N/A N/A yfitted_ N/A sort_index yfitted N/A yfitted yfitted_ N/A N/A yfitted yfitted N/A N/A all_valid N/A N/A yfitted_ N/A N/A np empty_like endog N/A N/A N/A yfitted_ fill N/A np nan N/A N/A yfitted_ N/A mask_valid yfitted N/A yfitted yfitted_ N/A yfitted N/A