help qbplot

Title

qbplot -- Quantile plot with box flavour

Syntax

qbplot
varname
[if] [in]
[,
spike(spike_options)
a(#)
addplot(twoway_command(s))
graph_options
]

Description

qbplot is a dedicated pedagogic or propaganda command with the
aim of showing that a quantile plot can convey all the key information
given by a box plot showing median and quartiles. Indeed, it can convey
much more.

The main part of the display is a quantile plot, a scatter plot showing
ordered values against the so-called plotting positions, labelled
"Fraction of the data". Compare official command quantile;
community-contributed command qplot (Cox 1999, 2005, 2019, 2024);
community-contributed command multqplot (Cox 2012, 2019);
community-contributed command stripplot.

On the vertical axis, the values of the minimum, maximum, median and
quartiles are shown as axis labels. The median and quartiles are
connected using horizontal and vertical line segments to plotting
positions 0.25, 0.5, 0.75 on the horizontal axis. These segments may be
extended mentally to imagine a conventional box showing median and
quartiles, as in most variations of box plots.

Variations from the basic design may be obtained by particular option
choices.

Remarks

The stance here is that this design can work well for samples of small,
moderate or large size. If a sample is small, there is enough space to
show all the detail in the data; the art is doing so while allowing
broad features to be grasped easily. If a sample is very large, many
data points often blur into each other, but that doesn't make such plots
useless. Marked outliers, gaps, spikes and so forth are likely to be
evident when they are present. Either way, quantile plots also convey
information on skewness and tail weight.

The precise definition of plotting position is (unique rank - a) /
(#values - 2 * a + 1), where a defaults to 1/2 = 0.5, yielding
(unique rank - 0.5) / #values. To specify another definition, see the
a() option. See also Cox (2014).

Occasionally, ties in the data may lead to one or more of median,
quartiles, minimum and maximum coinciding. Such ties do not necessarily
render the plot useless. Indeed, the plot may help to clarify the fine
structure of the data, even if it also implies that some quite different
display may be more helpful.

Whenever data are strongly skewed, between two and four axis labels may
be uncomfortably close to each other. This is often a sign that you
might be better off using a transformed scale. Note that ysc(log)
is available for on-the-fly logarithmic transformation of entirely
positive data, Here we rely on median and quartiles of logarithms of
data being usually close enough to logarithms of median and quartiles of
data, at least for exploratory purposes. Otherwise you may need to apply
a transformation separately.

Much of the point of this display is that we no longer need to worry
about precisely what is shown outside the box of a box plot. We just
show all the data points. So, we do not need to implement any particular
rule or convention, such as displaying data points individually if and
only if they are more than 1.5 IQR from the nearer quartile. Nor do we
need to interpret the results of any such rule or convention.

Literature on so-called quantile-box plots is pertinent here. Parzen
(1979a, 1979b, 1982, 1997) hybridised box and quantile plots as
quantile-box plots. See also (e.g.) Shera (1991), Militký and
Meloun (1993), Meloun and Militký (1994), Nair et al. (2013),
Evans and Cox (2017) and Cox (2020). Shelly (1996), Guevara and
Avilés (2007), Feigelson and Babu (2012, p.208) and Holmes and Huber (2019,
p.129) plotted quantile plots and box plots side by side. Note,
however, that the quantile box plot of Keen (2010, 2018) is just a box
plot with whiskers extending to the extremes. In contrast, the quantile
box plots of JMP are evidently box plots with marks at 0.5%, 2.5%, 10%,
90%, 97.5%, 99.5%: see Sall et al. (2014, pp.143-4).

For further references in this territory, see the help for stripplot.

Options

a() specifies an alternative rule for plotting position, as
discussed above. Possibilities are a(0) or a(1/3). Note from
the last example that expressions yielding numeric results may be
specified.

spike() indicates options of twoway spike to tune the
display of line segments indicating median and quartiles.

addplot() adds other twoway commands. See help on
addplot_option.

graph_options are other options of graph, including any used
to tune the scatter. Good examples would be name() or
saving(). aspect(1) can work well for single plots.

Examples

. sysuse auto, clear

. qbplot mpg, aspect(1) name(qb1, replace)

. qbplot mpg, ysc(log) subtitle(logarithmic scale, place(w)) aspect(1) name(qb2, replace)

. means mpg

. local gmean = r(mean_g)

. qbplot mpg, ysc(log) subtitle(logarithmic scale, place(w)) note(dashed line shows geometric mean) addplot(function `gmean', lp(dash) lc(magenta)) aspect(1) name(qb3, replace)

. levelsof foreign

. foreach g in `r(levels)' {

. local this : label (foreign) `g'

. qbplot mpg if foreign == `g', ytitle("`this'", size(large)) name(G`g', replace)

. local G `G' G`g'

. }

. graph combine `G', ycommon subtitle("`: var label mpg'") name(qb4, replace)

. label var price "Price (USD)"

. foreach v in price weight length mpg {

. qbplot `v', ytitle(, size(large)) name(`v', replace)

. local V `V' `v'

. }

. graph combine `V', imargin(small) name(qb5, replace)

. sysuse nlsw88, clear

. qbplot wage, name(qb6, replace)

. qbplot wage, ysc(log) name(qb7, replace)

. qbplot wage, ysc(log) yla(, format(%3.2f)) name(qb8, replace)

Author

Nicholas J. Cox, Durham University

n.j.cox@durham.ac.uk

References

Cox, N.J. 1999.
gr42: Quantile plots, generalized.
Stata Technical Bulletin 51: 16-18.

Cox, N.J. 2005.
Speaking Stata: The protean quantile plot.
Stata Journal 5: 442-460.

Cox, N.J. 2012.
Speaking Stata: Axis practice, or what goes where on a graph.
Stata Journal 12: 549-561.

Cox, N.J. 2014.
How can I calculate percentile ranks?
How can I calculate plotting positions?
http://www.stata.com/support/faqs/statistics/percentile-ranks-and-plotting-positions/

Cox, N.J. 2019.
Software updates for qplot and multqplot.
Stata Journal 19: 748-751.

Cox, N.J. 2020.
Speaking Stata: More ways for rowwise.
Stata Journal 20: 481-488.

Cox, N.J. 2024.
Software update for qplot.
Stata Journal 24: in press.

Evans, I.S. and N.J. Cox. 2017. Comparability of cirque size and
shape measures between regions and between researchers.
Zeitschrift für Geomorphologie 61 SupplementBand 2: 81-103.

Feigelson, E. D. and G. J. Babu. 2012.
Modern Statistical Methods for Astronomy with R Applications.
Cambridge: Cambridge University Press.

Guevara, J. and L. Avilés. 2007.
Multiple techniques confirm elevational differences in insect size that may influence spider sociality.
Ecology 88: 2015-2023.

Holmes, S. and W. Huber. 2019.
Modern Statistics for Modern Biology.
Cambridge: Cambridge University Press.

Keen, K.J. 2010.
Graphics for Statistics and Data Analysis with R.
Boca Raton, FL: CRC Press. (second edition 2018)

Meloun, M. and J. Militký. 1994.
Computer-assisted data treatment in analytical chemometrics.
I. Exploratory analysis of univariate data.
Chemical Papers 48: 151-157.

Militký, J. and M. Meloun. 1993.
Some graphical aids for univariate exploratory data analysis.
Analytica Chimica Acta 277: 215-221.

Nair, N.U., Sankaran, P.G. and Balakrishnan, N. 2013.
Quantile-based Reliability Analysis.
New York: Springer.

Parzen, E. 1979a.
Nonparametric statistical data modeling.
Journal, American Statistical Association
74: 105-121.

Parzen, E. 1979b.
A density-quantile function perspective on robust estimation.
In Launer, R.L. and G.N. Wilkinson (eds) Robustness in Statistics.
New York: Academic Press, 237-258.

Parzen, E. 1982.
Data modeling using quantile and density-quantile functions.
In Tiago de Oliveira, J. and B. Epstein (eds)
Some Recent Advances in Statistics. London: Academic Press,
23-52.

Parzen, E. 1997.
Concrete statistics. In
Ghosh, S., W.R. Schucany, and W.B. Smith (eds)
Statistics of Quality. New York: Marcel Dekker, 309-332.

Sall, J., A. Lehman, M. Stephens and L. Creighton. 2014.
JMP Start Statistics: A Guide to Statistics and Data Analysis Using JMP.
Cary, NC: SAS Institute.

Shelly, M. 1996.
Exploratory data analysis: data visualization or torture?
Infection Control and Hospital Epidemiology 17: 605-612.

Shera, D.M. 1991.
Some uses of quantile plots to enhance data presentation.
Computing Science and Statistics 23: 50-53.
http://www.dtic.mil/dtic/tr/fulltext/u2/a252938.pdf

Also see

Online: help for quantile,

qplot (if installed),

multqplot (if installed),

stripplot (if installed)