help lpoly dialog: lpoly
-------------------------------------------------------------------------------
Title
[R] lpoly -- Kernel-weighted local polynomial smoothing
Syntax
lpoly yvar xvar [if] [in] [weight] [, options]
options description
-------------------------------------------------------------------------
Main
kernel(kernel) specify kernel function; default is
kernel(epanechnikov)
bwidth(#|varname) specify kernel bandwidth
degree(#) specify degree of the polynomial smooth;
default is degree(0)
generate([newvar_x] newvar_s) store smoothing grid in newvar_x and
smoothed points in newvar_s
n(#) obtain the smooth at # points; default
is min(N,50)
at(varname) obtain the smooth at the values
specified by varname
nograph suppress graph
noscatter suppress scatterplot only
SE/CI
ci plot confidence bands
level(#) set confidence level; default is
level(95)
se(newvar) store standard errors in newvar
pwidth(#) specify pilot bandwidth for standard
error calculation
var(#|varname) specify estimates of residual variance
Scatterplot
marker_options change look of markers (color, size,
etc.)
marker_label_options add marker labels; change look or
position
Smoothed line
lineopts(cline_options) affect rendition of the smoothed line
CI plot
ciopts(cline_options) affect rendition of the confidence bands
Add plots
addplot(plot) add other plots to the generated graph
Y axis, X axis, Titles, Legend, Overall
twoway_options any options other than by() documented
in [G] twoway_options
-------------------------------------------------------------------------
kernel description
-------------------------------------------------------------------------
epanechnikov Epanechnikov kernel function; the default
epan2 alternative Epanechnikov kernel function
biweight biweight kernel function
cosine cosine trace kernel function
gaussian Gaussian kernel function
parzen Parzen kernel function
rectangle rectangle kernel function
triangle triangle kernel function
-------------------------------------------------------------------------
fweights and aweights are allowed; see weight.
Menu
Statistics > Nonparametric analysis > Local polynomial smoothing
Description
lpoly performs a kernel-weighted local polynomial regression of yvar on
xvar and displays a graph of the smoothed values with (optional)
confidence bands.
Options
+------+
----+ Main +-------------------------------------------------------------
kernel(kernel) specifies the kernel function for use in calculating the
weighted local polynomial estimate. The default is
kernel(epanechnikov).
bwidth(#|varname) specifies the half-width of the kernel, the width of
the smoothing window around each point. If bwidth() is not
specified, a rule-of-thumb (ROT) bandwidth estimator is calculated
and used. A local variable bandwidth may be specified in varname, in
conjunction with an explicit smoothing grid using the at() option.
degree(#) specifies the degree of the polynomial to be used in the
smoothing. The default is degree(0), meaning local-mean smoothing.
generate([newvar_x] newvar_s) stores the smoothing grid in newvar_x and
the smoothed values in newvar_s. If at() is not specified, then both
newvar_x and newvar_s must be specified. Otherwise, only newvar_s is
to be specified.
n(#) specifies the number of points at which the smooth is to be
evaluated. The default is min(N,50), where N is the number of
observations.
at(varname) specifies a variable that contains the values at which the
smooth should be calculated. By default, the smoothing is done on an
equally spaced grid, but you can use at() to instead perform the
smoothing at the observed x's, for example. This option also allows
you to more easily obtain smooths for different variables or
different subsamples of a variable and then overlay the estimates for
comparison.
nograph suppresses drawing the graph of the estimated smooth. This
option is often used with the generate() option.
noscatter suppresses superimposing a scatterplot of the observed data
over the smooth. This option is useful when the number of resulting
points would be so large as to clutter the graph.
+-------+
----+ SE/CI +------------------------------------------------------------
ci plots confidence bands, using the confidence level specified in
level().
level(#) specifies the confidence level, as a percentage, for confidence
intervals. The default is level(95) or as set by set level.
se(newvar) stores the estimates of the standard errors in newvar. This
option requires specifying generate() or at().
pwidth(#) specifies the pilot bandwidth to be used for standard-error
computations. The default is chosen to be 1.5 times the value of the
ROT bandwidth selector. If you specify pwidth() without specifying
se() or ci, then the ci option is assumed.
var(#|varname) specifies an estimate of a constant residual variance or a
variable containing estimates of the residual variances at each grid
point required for standard-error computation. By default, the
residual variance at each smoothing point is estimated by the
normalized weighted residual sum of squares obtained from locally
fitting a polynomial of order p+2, where p is the degree specified in
degree(). var(varname) is allowed only if at() is specified. If you
specify var() without specifying se() or ci, then the ci option is
assumed.
+-------------+
----+ Scatterplot +------------------------------------------------------
marker_options affect the rendition of markers drawn at the plotted
points, including their shape, size, color, and outline; see [G]
marker_options.
marker_label_options specify if and how the markers are to be labeled;
see [G] marker_label_options.
+---------------+
----+ Smoothed line +----------------------------------------------------
lineopts(cline_options) affects the rendition of the smoothed line; see
[G] cline_options.
+---------+
----+ CI plot +----------------------------------------------------------
ciopts(cline_options) affects the rendition of the confidence bands; see
[G] cline_options.
+-----------+
----+ Add plots +--------------------------------------------------------
addplot(plot) provides a way to add other plots to the generated graph;
see [G] addplot_option.
+-----------------------------------------+
----+ Y axis, X axis, Titles, Legend, Overall +--------------------------
twoway_options are any of the options documented in [G] twoway_options,
excluding by(). These include options for titling the graph (see [G]
title_options) and for saving the graph to disk (see [G]
saving_option).
Examples
Setup
. webuse motorcycle
Local mean smoothing
. lpoly accel time
Local cubic polynomial smoothing
. lpoly accel time, degree(3) kernel(epan2)
Same as above, but save smoothed values and standard errors as variables
instead of graphing
. lpoly accel time, degree(3) kernel(epan2) generate(x s) se(se)
nograph
Saved results
lpoly saves the following in r():
Scalars
r(degree) smoothing polynomial degree
r(ngrid) number of successful regressions
r(N) sample size
r(bwidth) bandwidth of the smooth
r(pwidth) pilot bandwidth
Macros
r(kernel) name of kernel
Also see
Manual: [R] lpoly
Help: [G] graph, [R] kdensity, [R] lowess, [R] smooth