help aaplot-------------------------------------------------------------------------------

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

Syntax

aaplotyvar xvar[if] [in] [,quadraticbothlopts(lfitoptions)qopts(qfitoptions)aformat(format)bformat(format)cformat(format)rsqformat(format)rmseformat(format)abbrev(#)backdrop(addplot_option)addplot(addplot_option)scatter_options]

Description

aaplotgraphs a scatter plot foryvarversusxvarwith 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

aaplotis 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 cloneaaplotand should feel compelled to use their own different program name.

Options

quadraticspecifies plotting of quadratic fit only.

bothspecifies 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()andrmseformat()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 ofyvar. See help on format for guidance.

abbrev()tunes the abbreviation of longer variable names. By default such names are abbreviated in the subtitle usingabbrev(, 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. Seeaddplot_option.

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

scatter_optionsare any options allowed for scatter excludingby(). These include the options for titling the graph (seetitle_options), for tuning the display of data points and for saving the graph to disk (seesaving_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)

AuthorNicholas J. Cox, Durham University n.j.cox@durham.ac.uk

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

Also seeManual:

[R] regress postestimation,[G] graph twoway