**[R] lowess** -- Lowess smoothing

__Syntax__

**lowess** *yvar* *xvar* [*if*] [*in*] [**,** *options*]

*options* Description
-------------------------------------------------------------------------
Main
__m__**ean** running-mean smooth; default is running-line
least squares
__now__**eight** suppress weighted regressions; default is
tricube weighting function
__bw__**idth(***#***)** use *#* for the bandwidth; default is
**bwidth(0.8)**
__lo__**git** transform dependent variable to logits
__a__**djust** adjust smoothed mean to equal mean of
dependent variable
__nog__**raph** suppress graph
__gen__**erate(***newvar***)** create *newvar* containing smoothed values of
*yvar*

Plot
*marker_options* change look of markers (color, size, etc.)
*marker_label_options* add marker labels; change look or position

Smoothed line
__lineop__**ts(***cline_options***)** affect rendition of the smoothed line

Add plots
**addplot(***plot***)** add other plots to generated graph

Y axis, X axis, Titles, Legend, Overall, By
*twoway_options* any of the options documented in **[G-3]**
*twoway_options*
-------------------------------------------------------------------------
*yvar* and *xvar* may contain time-series operators; see tsvarlist.

__Menu__

**Statistics > Nonparametric analysis > Lowess smoothing**

__Description__

**lowess** carries out a locally weighted regression of *yvar* on *xvar*,
displays the graph, and optionally saves the smoothed variable.

Warning: **lowess** is computationally intensive and may therefore take a
long time to run on a slow computer. Lowess calculations on 1,000
observations, for instance, require performing 1,000 regressions.

__Options__

+------+
----+ Main +-------------------------------------------------------------

**mean** specifies running-mean smoothing; the default is running-line
least-squares smoothing.

**noweight** prevents the use of Cleveland's (1979) tricube weighting
function; the default is to use the weighting function.

**bwidth(***#***)** specifies the bandwidth. Centered subsets of **bwidth()***N
observations are used for calculating smoothed values for each point
in the data except for end points, where smaller, uncentered subsets
are used. The greater the **bwidth()**, the greater the smoothing. The
default is 0.8.

**logit** transforms the smoothed *yvar* into logits. Predicted values less
than 0.0001 or greater than 0.9999 are set to 1/N and 1-1/N,
respectively, before taking logits.

**adjust** adjusts the mean of the smoothed *yvar* to equal the mean of *yvar* by
multiplying by an appropriate factor. This option is useful when
smoothing binary (0/1) data.

**nograph** suppresses displaying the graph.

**generate(***newvar***)** creates *newvar* containing the smoothed values of *yvar*.

+------+
----+ Plot +-------------------------------------------------------------

*marker_options* affect the rendition of markers drawn at the plotted
points, including their shape, size, color, and outline; see **[G-3]**
*marker_options*.

*marker_label_options* specify if and how the markers are to be labeled;
see **[G-3]** *marker_label_options*.

+---------------+
----+ Smoothed line +----------------------------------------------------

**lineopts(***cline_options***)** affects the rendition of the lowess-smoothed
line; see **[G-3]** *cline_options*.

+-----------+
----+ Add plots +--------------------------------------------------------

**addplot(***plot***)** provides a way to add other plots to the generated graph;
see **[G-3]** *addplot_option*.

+---------------------------------------------+
----+ Y axis, X axis, Titles, Legend, Overall, By +----------------------

*twoway_options* are any of the options documented in **[G-3]** *twoway_options*.
These include options for titling the graph (see **[G-3]**
*title_options*), options for saving the graph to disk (see **[G-3]**
*saving_option*), and the **by()** option (see **[G-3]** *by_option*).

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse lowess1**

Perform locally weighted regression of **h1** on **depth** and display graph
**. lowess h1 depth**

Same as above, but use 0.4 as the bandwidth rather than the default of
0.8
**. lowess h1 depth, bwidth(.4)**

Same as above, but save smoothed values of **h1** in **x1** and suppress the
graph
**. lowess h1 depth, bwidth(.4) gen(x1) nograph**

---------------------------------------------------------------------------
Setup
**. sysuse auto, clear**

Perform locally weighted regression of **foreign** on **mpg**, labeling y axis
with Domestic for 0 and Foreign for 1
**. lowess foreign mpg, ylabel(0 "Domestic" 1 "Foreign")**

Same as above, but adjust mean of smoothed **foreign** to equal mean of
**foreign**
**. lowess foreign mpg, ylabel(0 "Domestic" 1 "Foreign")** **adjust**

Perform locally weighted regression of **foreign** on **mpg**, transforming the
smoothed **foreign** into logits and drawing a horizontal line at 0
**. lowess foreign mpg, logit yline(0)**
---------------------------------------------------------------------------

__Reference__

Cleveland, W. S. 1979. Robust locally weighted regression and smoothing
scatterplots. *Journal of the American Statistical Association* 74:
829-836.