help aaplot

Scatter plot with linear and/or quadratic fit, automatically annotated

Syntax

aaplot yvar xvar
[if] [in]
[,
quadratic
both
lopts(lfitoptions)
qopts(qfitoptions)
aformat(format)
bformat(format)
cformat(format)
rsqformat(format)
rmseformat(format)
abbrev(#)
backdrop(addplot_option)
addplot(addplot_option)
scatter_options
]

Description

aaplot graphs a scatter plot for yvar versus xvar with
linear and/or quadratic fit superimposed. The equation(s) and R-square
statistics of the fits shown are also shown at the top of the graph. If
just one fit is shown, the subtitle is used. The sample size and RMSE(s)
are shown in a note.

Remarks

aaplot is indicative, not definitive. Some tastes might run to
showing (for example) standard errors, t statistics and P-values instead
of, or in addition to, the results shown. Users so inclined should feel
free to clone aaplot and should feel compelled to use their own
different program name.

Options

quadratic specifies plotting of quadratic fit only.

both specifies plotting of linear and quadratic fit. The equation
and R-square for the quadratic fit are displayed in the subtitle and
those for the linear fit in the t1title.

lopts() are options of twoway lfit to tune the rendering of
the linear fit.

qopts() are options of twoway qfit to tune the rendering of
the quadratic fit.

aformat(), bformat(), cformat(), rsqformat() and
rmseformat() tune the display format of the constant, the
coefficient of the linear term, the coefficient of the quadratic term
(if any), the R-square statistic (given as a percent) and the RMSE. The
defaults are, respectively, %7.0g,
%7.0g, %7.0g, %3.1f and the display format of yvar.
See help on format for guidance.

abbrev() tunes the abbreviation of longer variable names. By
default such names are abbreviated in the subtitle using
abbrev(, 10). Users may change the length shown from 10.

backdrop(addplot_option) provides a way to add other
plots to the generated graph, but as backdrop plotted before and below
all other plots. For example, many users
like to draw shaded areas showing confidence intervals, but showing all
data points too.
See addplot_option.

addplot(addplot_option) provides a way to add other
plots to the generated graph. See addplot_option.

scatter_options are any options allowed for scatter
excluding by(). These include the options for titling the graph
(see title_options), for tuning the display of data points
and for saving the graph to disk (see saving_option).

Examples

. sysuse auto, clear

. gen gpm = 1000 / mpg

. label var gpm "Gallons per thousand miles"

. aaplot gpm weight, name(g1)

. aaplot gpm weight, lopts(lc(blue)) aformat(%04.3f) bformat(%06.5f) rmseformat(%4.3f) name(g2)

. aaplot gpm weight, quadratic qopts(lc(pink)) name(g3)

. aaplot gpm weight, both name(g4)

. aaplot gpm weight, both backdrop(lfitci gpm weight, color(gs12)) name(g5)

Author

Nicholas J. Cox, Durham University

n.j.cox@durham.ac.uk

Acknowledgments

This problem was suggested by Alona Armstrong.
Kit Baum, Eric Booth and Ariel Linden made helpful suggestions.

Also see

Manual: [R] regress postestimation, [G] graph twoway