Module Expr Str ImportFrom alias Import alias identifier ImportFrom alias FunctionDef arguments args NameParam NameParam NameParam NameParam defaults BinOpDiv Num Num Num body Expr Str Assign NameStore 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 Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad BinOpMult NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index NameLoad Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad For NameStore Call NameLoad NameLoad body Expr Call NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad Assign NameStore AttributeLoad Call AttributeLoad NameLoad attr ListLoad NameLoad NameLoad attr Assign AttributeStore NameLoad attr TupleLoad NameLoad Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad keyword AttributeLoad NameLoad attr Assign NameStore ListLoad Num NameLoad Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad For NameStore Call NameLoad NameLoad body Assign NameStore BinOpSub SubscriptLoad NameLoad Index NameLoad SubscriptLoad NameLoad Index SubscriptLoad NameLoad Index Num Assign NameStore BinOpSub SubscriptLoad NameLoad Index BinOpSub SubscriptLoad NameLoad Index Num Num SubscriptLoad NameLoad Index NameLoad Assign NameStore Call NameLoad NameLoad NameLoad Expr Call NameLoad SubscriptLoad NameLoad ExtSlice Index NameLoad Slice SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index NameLoad NameLoad Expr Call NameLoad SubscriptLoad NameLoad ExtSlice Index NameLoad Slice Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Index NameLoad Slice Assign SubscriptStore NameLoad ExtSlice Slice Index Num SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign NameStore BinOpMult SubscriptLoad NameLoad ExtSlice Index NameLoad Slice SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad Call NameLoad BinOpMult Call AttributeLoad SubscriptLoad NameLoad ExtSlice Index NameLoad Slice attr NameLoad Num NameLoad NameLoad Index Num Assign SubscriptStore NameLoad Index NameLoad BinOpAdd SubscriptLoad NameLoad Index Num BinOpMult SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index NameLoad Expr Call NameLoad NameLoad NameLoad BinOpAdd NameLoad Num Return TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign SubscriptStore NameLoad Slice NameLoad AugAssignSub NameStore NameLoad AugAssignDiv NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore ListLoad Num NameLoad Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign AttributeStore NameLoad attr TupleLoad NameLoad AugAssignSub NameStore NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad AugAssignDiv NameStore BinOpMult Num NameLoad Assign NameStore CompareGtE NameLoad Num Expr Call NameLoad NameLoad Assign SubscriptStore NameLoad Index NameLoad Num For NameStore Call NameLoad NameLoad body Assign NameStore BinOpMult SubscriptLoad NameLoad ExtSlice Index NameLoad Slice Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign SubscriptStore NameLoad ExtSlice Slice Index Num SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign NameStore BinOpMult NameLoad SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign AttributeStore NameLoad attr TupleLoad NameLoad Num Assign NameStore SubscriptLoad Call NameLoad BinOpMult NameLoad NameLoad NameLoad Index Num Assign SubscriptStore NameLoad Index NameLoad BinOpAdd SubscriptLoad NameLoad Index Num BinOpMult SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index NameLoad Expr Call NameLoad NameLoad NameLoad BinOpAdd NameLoad Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str While NameLoad body If CompareLt SubscriptLoad NameLoad Index Num AttributeLoad NameLoad attr body Assign NameStore BinOpSub SubscriptLoad NameLoad Index NameLoad SubscriptLoad NameLoad Index SubscriptLoad NameLoad Index Num Assign NameStore BinOpSub SubscriptLoad NameLoad Index SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index NameLoad If CompareLt NameLoad NameLoad body Assign SubscriptStore NameLoad Index Num BinOpAdd SubscriptLoad NameLoad Index Num Num Assign SubscriptStore NameLoad Index Num BinOpAdd SubscriptLoad NameLoad Index Num Num orelse Break orelse Break decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign SubscriptStore NameLoad Slice Call AttributeLoad NameLoad attr NameLoad Expr Call NameLoad NameLoad Assign SubscriptStore NameLoad Slice Call AttributeLoad NameLoad attr NameLoad AugAssignAdd NameStore Num Expr Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore BinOpMult NameLoad NameLoad AugAssignMult NameStore NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str AugAssignMult NameStore NameLoad Assign SubscriptStore NameLoad Slice Call AttributeLoad NameLoad attr NameLoad AugAssignAdd NameStore Num AugAssignMult NameStore NameLoad decorator_list
N/A N/A 
Univariate lowess function, like in R.

References
----------
Hastie, Tibshirani, Friedman. (2009) The Elements of Statistical Learning: Data Mining, Inference, and Prediction, Second Edition: Chapter 6.

Cleveland, W.S. (1979) "Robust Locally Weighted Regression and Smoothing Scatterplots". Journal of the American Statistical Association 74 (368): 829-836.
 statsmodels.compat.python range N/A numpy np scipy.linalg lstsq lowess N/A N/A endog exog frac it N/A N/A 2.0 3 3 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.

    Returns
    -------
    out: numpy array
        A numpy array with two columns. The first column
        is the sorted x values and the second column the
        associated estimated y-values.

    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 true ``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 `_lowess_tricube` function applied to ``|x_i-x_j|``.

    If ``iter > 0``, 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.

    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 scipy.stats as stats
    >>> 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 x exog 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 x shape N/A 0 N/A N/A N/A ValueError exog and endog must have same length N/A n N/A N/A exog shape N/A 0 N/A fitted N/A N/A np zeros n N/A k N/A int N/A frac n N/A index_array N/A N/A np argsort exog N/A x_copy N/A N/A np array N/A exog N/A index_array N/A y_copy N/A endog N/A index_array N/A N/A fitted weights N/A _lowess_initial_fit x_copy y_copy k n N/A i N/A range it N/A N/A N/A _lowess_robustify_fit x_copy y_copy fitted weights k n N/A out N/A N/A N/A np array N/A x_copy fitted T N/A N/A out shape N/A n 2 N/A out N/A _lowess_initial_fit N/A N/A x_copy y_copy k n N/A N/A N/A 
    The initial weighted local linear regression for lowess.

    Parameters
    ----------
    x_copy : 1-d ndarray
        The x-values/exogenous part of the data being smoothed
    y_copy : 1-d ndarray
        The y-values/ endogenous part of the data being smoothed
   k : int
        The number of data points which affect the linear fit for
        each estimated point
    n : int
        The total number of points

    Returns
    -------
    fitted : 1-d ndarray
        The fitted y-values
    weights : 2-d ndarray
        An n by k array. The contribution to the weights in the
        local linear fit coming from the distances between the
        x-values

    N/A weights N/A N/A np zeros N/A n k dtype N/A x_copy dtype N/A nn_indices N/A 0 k N/A X N/A N/A np ones N/A k 2 N/A fitted N/A N/A np zeros n N/A i N/A range n N/A N/A left_width N/A N/A x_copy N/A i N/A x_copy N/A N/A nn_indices N/A 0 N/A right_width N/A N/A x_copy N/A N/A N/A nn_indices N/A 1 1 N/A x_copy N/A i N/A width N/A max left_width right_width N/A N/A _lowess_wt_standardize N/A weights N/A N/A i N/A N/A x_copy N/A N/A nn_indices N/A 0 N/A nn_indices N/A 1 N/A x_copy N/A i width N/A N/A _lowess_tricube N/A weights N/A N/A i N/A N/A N/A weights N/A N/A i N/A N/A N/A np sqrt N/A weights N/A N/A i N/A N/A N/A X N/A N/A N/A 1 N/A x_copy N/A N/A nn_indices N/A 0 N/A nn_indices N/A 1 N/A y_i N/A N/A weights N/A N/A i N/A N/A y_copy N/A N/A nn_indices N/A 0 N/A nn_indices N/A 1 N/A beta N/A N/A lstsq N/A N/A N/A N/A weights N/A N/A i N/A reshape k 1 X y_i N/A 0 N/A N/A fitted N/A i N/A N/A beta N/A 0 N/A N/A beta N/A 1 N/A x_copy N/A i N/A N/A _lowess_update_nn x_copy nn_indices N/A i 1 N/A N/A fitted weights N/A _lowess_wt_standardize N/A N/A weights new_entries x_copy_i width N/A N/A N/A 
    The initial phase of creating the weights.
    Subtract the current x_i and divide by the width.

    Parameters
    ----------
    weights : ndarray
        The memory where (new_entries - x_copy_i)/width will be placed
    new_entries : ndarray
        The x-values of the k closest points to x[i]
    x_copy_i : float
        x[i], the i'th point in the (sorted) x values
    width : float
        The maximum distance between x[i] and any point in new_entries

    Returns
    -------
    Nothing. The modifications are made to weight in place.

     N/A N/A weights N/A new_entries N/A weights x_copy_i N/A weights width N/A _lowess_robustify_fit N/A N/A x_copy y_copy fitted weights k n N/A N/A N/A 
    Additional weighted local linear regressions, performed if
    iter>0. They take into account the sizes of the residuals,
    to eliminate the effect of extreme outliers.

    Parameters
    ----------
    x_copy : 1-d ndarray
        The x-values/exogenous part of the data being smoothed
    y_copy : 1-d ndarray
        The y-values/ endogenous part of the data being smoothed
    fitted : 1-d ndarray
        The fitted y-values from the previous iteration
    weights : 2-d ndarray
        An n by k array. The contribution to the weights in the
        local linear fit coming from the distances between the
        x-values
    k : int
        The number of data points which affect the linear fit for
        each estimated point
    n : int
        The total number of points

   Returns
    -------
    Nothing. The fitted values are modified in place.

     N/A nn_indices N/A 0 k N/A X N/A N/A np ones N/A k 2 N/A residual_weights N/A N/A np copy y_copy N/A N/A residual_weights shape N/A n N/A residual_weights fitted N/A residual_weights N/A N/A np absolute residual_weights N/A s N/A N/A np median residual_weights N/A residual_weights N/A 6 s N/A too_big N/A residual_weights 1 N/A N/A _lowess_bisquare residual_weights N/A N/A residual_weights N/A too_big 0 N/A i N/A range n N/A N/A total_weights N/A N/A weights N/A N/A i N/A N/A N/A np sqrt N/A residual_weights N/A N/A nn_indices N/A 0 N/A nn_indices N/A 1 N/A N/A X N/A N/A N/A 1 N/A x_copy N/A N/A nn_indices N/A 0 N/A nn_indices N/A 1 N/A y_i N/A total_weights N/A y_copy N/A N/A nn_indices N/A 0 N/A nn_indices N/A 1 N/A N/A total_weights shape N/A k 1 N/A beta N/A N/A lstsq N/A total_weights X y_i N/A 0 N/A N/A fitted N/A i N/A N/A beta N/A 0 N/A N/A beta N/A 1 N/A x_copy N/A i N/A N/A _lowess_update_nn x_copy nn_indices N/A i 1 N/A _lowess_update_nn N/A N/A x cur_nn i N/A N/A N/A 
    Update the endpoints of the nearest neighbors to
    the ith point.

    Parameters
    ----------
    x : iterable
        The sorted points of x-values
    cur_nn : list of length 2
        The two current indices between which are the
        k closest points to x[i]. (The actual value of
        k is irrelevant for the algorithm.
    i : int
        The index of the current value in x for which
        the k closest points are desired.

    Returns
    -------
    Nothing. It modifies cur_nn in place.

     N/A True N/A N/A N/A N/A cur_nn N/A 1 N/A x size N/A N/A left_dist N/A N/A x N/A i N/A x N/A N/A cur_nn N/A 0 N/A new_right_dist N/A N/A x N/A N/A cur_nn N/A 1 N/A x N/A i N/A N/A new_right_dist left_dist N/A N/A N/A cur_nn N/A 0 N/A N/A cur_nn N/A 0 1 N/A N/A cur_nn N/A 1 N/A N/A cur_nn N/A 1 1 N/A N/A N/A N/A N/A _lowess_tricube N/A N/A t N/A N/A N/A 
    The _tricube function applied to a numpy array.
    The tricube function is (1-abs(t)**3)**3.

    Parameters
    ----------
    t : ndarray
        Array the tricube function is applied to elementwise and
        in-place.

    Returns
    -------
    Nothing
     N/A N/A t N/A N/A N/A np absolute t N/A N/A _lowess_mycube t N/A N/A t N/A N/A N/A np negative t N/A t 1 N/A N/A _lowess_mycube t N/A _lowess_mycube N/A N/A t N/A N/A N/A 
    Fast matrix cube

    Parameters
    ----------
    t : ndarray
        Array that is cubed, elementwise and in-place

    Returns
    -------
    Nothing

     N/A t2 N/A t t N/A t t2 N/A _lowess_bisquare N/A N/A t N/A N/A N/A 
    The bisquare function applied to a numpy array.
    The bisquare function is (1-t**2)**2.

    Parameters
    ----------
    t : ndarray
        array bisquare function is applied to, element-wise and in-place.

    Returns
    -------
    Nothing

     N/A t t N/A N/A t N/A N/A N/A np negative t N/A t 1 N/A t t N/A