help for designplot

Design plot: graphical summary of response given one or more factors

designplot
yvar
xvarlist
[weight]
[if]
[in]
[
,
statistics(statistics)
prefix(prefix)
saveresults(filename [, save_options)
maxway(#)
minway(#)
recast({bar|hbar})
{
variablelabels
|
variablenames
}
alllabel(text)
entryopts(over_subopts)
groupopts(over_subopts)
graph_options
]

aweights and fweights are supported.

Description

designplot produces a graphical summary of a numeric response
variable yvar given one or more "factors" xvarlist. The term
"factor" in this context means that any (numeric or string) variable
concerned will be treated in terms of its distinct values or levels as
they occur in the data. Use of Stata's factor variable syntax is neither
explicit nor implicit.

For concreteness, consider the example

. sysuse auto, clear

. designplot mpg foreign rep78

This produces a plot showing the mean of mpg for all observations;
for all the classes defined by the values of foreign and also
those of rep78; and for all the classes defined by the
cross-combinations of values of foreign and rep78 occurring
in the data.

Options give scope for showing other summary statistics as calculated by
summarize and for restricting the results shown in the plot.

By default the graph is produced by graph dot. Optionally
graph hbar or graph bar may be used instead.

Design plots offer a diversity of uses, ranging from simple exploratory
overviews to multiscale breakdowns deserving and demanding detailed
scrutiny.

Remarks

designplot is an eclectic combination of ideas. Readers are warmly
invited to inform the author of other similar or related work.

1. The existing Stata command grmeanby shows means (or optionally
medians) of a response variable given one or more other variables. The
scope of grmeanby is identical to that of designplot insofar
as the other variables could be string variables as well as numeric
variables. As recorded by Gould (1993) and in the manual entry,
grmeanby was inspired by examples in Chambers and Hastie (1992).
grmeanby is based on direct use of summarize.

2. Freeny and Landwehr (1992) gave the name "design plot" to plots
similar to those in Chambers and Hastie (1992) and that name is
associated with software implementations outside Stata, notably in S,
S-Plus and R. The name is also consistent with S syntax detailed at
Chambers and Hastie (1992, pp.546-547). In these implementations
plots show results from fitting linear models, specifically analyses of
variance. The name evokes the idea of an underlying experimental
design, but the command here clearly may be applied to any data,
including observational data in any sense of that term. The graph shown
by Zuur et al. (2007, p.37) is an example from the applied literature.

3. Various plots given in Hoaglin, Mosteller, and Tukey (1991) show
displays "side-by-side" of main effects, interactions and residuals as
fitted in analysis of variance. Roberts (1993, p.310) cites an earlier
instance of the same idea in Tukey (1977, p.451). Yandell (1997) calls
these "effect plots" or "effects plots".

4. Broadly similar plots for "graphical ANOVA" appear in Box, Hunter and
Hunter (2005). See also the earlier work in Box (1993). van Belle
(2008, p.201) called them "BHH plots".

Graphs of types 3 and 4 commonly show effects and residuals scaled to be
comparable in terms of variability.

5. Graphically, these displays share a possible problem: points may need
to be plotted close to each other, creating difficulties especially if
any text labels occlude each other or need to be abbreviated. 3 out of 4
examples in Chambers and Hastie (1992) show this, as does the example in
[R] grmeanby. Several examples in Hoaglin et al. (1991) avoid the
problem only by jittering points apart. Harrell (2001) used a different
display based on dot charts or dot plots (in the sense of Cleveland
1984, 1985, 1994) that avoids this problem. Conversely, a dot chart
representation will work well with say 10 entries, but not with 100 or
more.

6. On a simpler level, tables or graphs reporting survey results often
show two or more separate breakdowns of some sample. Examples are
shown by Tufte (1983/2001, p.179) and (more trivially) Cox (2008), among
many others.

7. The statsby command with its subsets option provides an
easy framework for calculation and assembly of summary statistics for
zero-, one-, two-way and higher breakdowns of a dataset. Cox (2010)
provided an illustration of its exploitation for graphics.

The name "design plot" is adopted here as a simple, memorable name and
given its earlier and widespread use to show similar information. These
are positive features. On the other hand, the connotation of experimental
design will often be inappropriate. The use of dot chart (or optionally
bar chart) form also distinguishes the results of this command from
others published as design plots. People who like the plots and dislike
the name are naturally free to use other terminology, or none at all.
Not every kind of graph needs a distinct name, but every graph program
does.

Naturally, this lack of standardization is not new. "Most or all
features of statistical computation-computer hardware, software
systems, coding, languages, symbols, terminology, procedures-have
much to gain from elimination of pointless variations, redundancies and
confusion. Yet pointlessness is not always easy to judge. The only quite
satisfying rule of standardization is that you adopt my standards."
(Anscombe 1981, p.3)

designplot creates a new dataset of summarize results with
default variable names _stat1 and so forth for each statistic and
_way, _group and _entry describing the results. If the
number of observations is not one of the statistics requested, a
variable with default name _nobs is added any way, on the grounds
that it will often be interesting or useful. The original dataset will
be restored after the graph is drawn, but the results set may be
saved for other use with the saveresults() option.

How therefore does designplot differ from what is readily
available through (e.g.) graph dot? There are two main
differences. First, graph dot and its siblings are more restricted
in offering only one-way or two-way or three-way breakdowns given,
respectively, one or two or three "factors" as arguments to over()
or by() options. Second, they do not give scope for saving results
for separate graphing or tabulation.

For concreteness, consider again the example

. sysuse auto, clear

. designplot mpg foreign rep78

This produces a plot showing

the mean of mpg for all observations, which may be called a
"zero-way" breakdown

the means for all the classes defined by the values of foreign and
also of rep78, which may be called "one-way" breakdowns, as often
done in statistical literature

and the means for all the classes defined by the cross-combinations of
values of foreign and rep78 occurring in the data, which
similarly may be called a "two-way" breakdown, again as often done.

In general, specifying one or more factors gives scope for various
breakdowns, but the number of (cross-)combinations may grow rapidly, so
that the resulting graph might be too complicated to be readable or
useful. Thus designplot offers options to restrict the scope of
what is plotted.

Options

statistics() specifies statistics calculated by
summarize to be calculated. The default is the mean (only). One
or more statistics may be specified. Note that no allowance is made in
graphics for different statistics being on quite different scales, so
that the user may need to exercise discretion over what is specified.
The names allowed include the names of the r-class results as visible
after summarize, detail or as documented in [R] summarize. Thus
p50 specifies the median available as r(p50).

Allowed synonyms also include the following. Any synonym specified will
be echoed literally to the ytitle().

n or count or any abbreviation of frequency for
N.

minimum for min and maximum for max.

total for sum.

median for p50.

SD for sd.

any abbreviation of variance or Variance for Var.

skew for skewness and kurt for kurtosis.

Note that if just statistics(N) is specified, which yvar is
specified is immaterial so long as it is non-missing
whenever xvarlist are non-missing.

prefix() is an occasionally used option. designplot creates
a dataset of results with variable names such as _stat1 and so
forth. If these names clash with existing variable names, this option
may be used to add a prefix to all such names to remove the clash.

saveresults() saves the results as a Stata dataset. Options of
save may be specified, most usefully replace. The dataset
will include notes on the designplot command issued and
(if defined) the filename and its date for the (saved) dataset.

maxway() specifies the maximum "way" to be plotted. See
explanation in Remarks on breakdowns that are called zero-way, one-way,
two-way and so forth. Thus maxway(1) by itself specifies that
zero-way and one-way breakdowns only are to be shown.

minway() specifies the minimum "way" to be plotted. See
explanation in Remarks on breakdowns that are called zero-way, one-way,
two-way and so forth. Thus minway(1) by itself specifies that the
zero-way breakdown should not be shown.

recast({hbar|bar}) specifies that
the graph should be drawn using graph hbar or graph bar.
The default is graph dot. People fond of bar charts are advised
to try graph hbar for greater readability of axis information.
Note for experienced users: although the option name is suggested by another
recast() option, this is not a back door to
recasting to a twoway plot.

variablelabels specifies that one-way breakdowns should be
labelled by the corresponding variable labels, or the corresponding
variable names if no variable label is defined. The default is, or
should be, an invisible label (precisely, an instance of
char(160)).

variablenames specifies that one-way breakdowns should be labelled
by the corresponding variable names. The default is, or should be, an
invisible label (precisely, an instance of char(160)). The reason
for using this option rather than variablelabels is likely to be
that variable labels would take up too much space.

Only one of variablelabels and variablenames may be
specified.

alllabel(text) specifies text to label results for all
observations used. The default is (all).

entryopts(over_subopts) specifies over_subopts of
graph dot, graph hbar or graph bar, used to tune the
corresponding call to an over() option that affects the display of
individual entries in the graph. Users unsure of what this means may
find inspection of the source code helpful or alternatively just modify
a graph by use of the Graph Editor.

groupopts(over_subopts) specifies over_subopts of
graph dot, graph hbar or graph bar, used to tune the
corresponding call to an over() option that affects the display of
groups of entries in the graph. Users unsure of what this means may
find inspection of the source code helpful or alternatively just modify
a graph by use of the Graph Editor.

graph_options are other options allowed with
graph dot,
graph hbar or
graph bar (whichever command is being used).
Note that among other defaults t1title() is used to display
information on yvar.

Examples

. set scheme s1color

. sysuse auto, clear

. designplot mpg foreign rep78

. designplot mpg foreign rep78 if !missing(foreign,rep78), stat(count) recast(hbar) blabel(total) yla(none) t1title("frequencies") variablelabels ytitle("") ysc(r(0 72))

. designplot mpg foreign rep78, stat(min p25 median mean p75 max) maxway(1) legend(row(1))

. infix class 1-9 adult 10-18 male 19-27 survived 28-36 using http://www.amstat.org/publications/jse/datasets/titanic.dat.txt, clear

. label def class 0 crew 1 first 2 second 3 third

. label def adult 1 adult 0 child

. label def male 1 male 0 female

. label def survived 1 yes 2 no

. foreach v in class adult male survived {

. label val `v' `v'

. }

. designplot survived class adult male, max(2) ysize(7)

Author

Nicholas J. Cox, Durham University, U.K.

n.j.cox@durham.ac.uk

References

Anscombe, F.J. 1981.
Computing in Statistical Science through APL.
New York: Springer.

Box, G.E.P. 1993.
How to get lucky.
Quality Engineering 5: 517-524.

Box, G.E.P., Hunter, J.S. and Hunter, W.G. 2005.
Statistics for Experimenters: Design, Innovation, and Discovery.
Hoboken, NJ: John Wiley.

Chambers, J.M. and Hastie, T.J. (Eds.) 1992.
Statistical Models in S.
Pacific Grove, CA: Wadsworth and Brooks/Cole.
See pp.3, 9, 148, 164.

Cleveland, W.S. 1984. Graphical methods for data presentation: full
scale breaks, dot charts, and multibased logging.
American Statistician 38: 270-80.

Cleveland, W.S. 1985. Elements of graphing data.
Monterey, CA: Wadsworth.

Cleveland, W.S. 1994. Elements of graphing data.
Summit, NJ: Hobart Press.

Cox, N.J. 2008.
Between tables and graphs.
Stata Journal 8: 269-289.

Cox, N.J. 2010.
The statsby strategy.
Stata Journal 10: 143-151.

Dawson, R.J.M. 1995.
The "unusual episode" data revisited.
Journal of Statistics Education 3(3).
http://www.amstat.org/publications/jse/v3n3/datasets.dawson.html

Freeny, A.E. and Landwehr, J.M. 1992.
Displays for data from large designed experiments.
In Page, C. and LePage, R. (Eds)
Computer Science and Statistics: Proceedings of the 22nd Symposium on the Interface. Statistics of Many Parameters: Curves, Images, Spatial Models.
New York: Springer, 117-126.

Gould, W.W. 1993.
gr12: Graphs of means and medians by categorical variables.
Stata Technical Bulletin 12: 13.

Harrell, F.E. 2001.
Regression Modeling Strategies: With Applications to Linear Models, Logistic Regression, and Survival Analysis.
New York: Springer. See pp.126, 303, 304, 314, 315, 336.

Hoaglin, D.C., Mosteller, F. and Tukey, J.W. (Eds) 1991.
Fundamentals of Exploratory Analysis of Variance.
New York: John Wiley. See pp.84, 97, 103, 120, 125, 133, 140, 174, 181,
182, 382, 385.

Roberts, S. 1993.
Fundamentals of Exploratory Analysis of Variance.
Edited by David C. Hoaglin, Frederick Mosteller, and John W. Tukey.
American Journal of Psychology
106: 308-320.

Tufte, E.R. 1983/2001.
The Visual Display of Quantitative Information.
Cheshire, CT: Graphics Press.

Tukey, J.W. 1977.
Exploratory Data Analysis.
Reading, MA: Addison-Wesley.

van Belle, G. 2008.
Statistical Rules of Thumb.
Hoboken, NJ: John Wiley.

Yandell, B.S. 1997.
Practical Data Analysis for Designed Experiments.
London: Chapman & Hall.
See pp.138, 173, 174, etc. for examples of effects plots.

Zuur, A.F., Ieno, E.N. and Smith, G.M. 2007.
Analysing ecological data.
New York: Springer.

Also see

On-line: help for graph dot, help for graph hbar,
help for graph bar; help for statsby