help for trimplot

Plots of trimmed means

trimplot
varname
[if exp]
[in range]
[,
{
over(overvar)
|
by(byvar [, by_subopts])
}
percent
metric
mad
scatter_options]

trimplot
varlist
[if exp]
[in range]
[,
percent
metric
mad
scatter_options]

Description

trimplot produces plots of trimmed means versus depth or percent
trimmed or deviation for one or more numeric variables. Such plots may
help specifically in choosing or assessing measures of level and
generally in assessing the symmetry or skewness of distributions. They
can be used to compare distributions or to assess whether
transformations are necessary or effective.

trimplot may be used to show trimmed means for one variable, in
which case different groups may be distinguished by the over() or
the by() option; or for several variables.

Remarks

Order n data values for a variable y and label them such that
y(1) <= ... <= y(n). Following Tukey (1977), depth is defined as 1 for
y(1) and y(n), 2 for y(2) and y(n-1), and so forth: it is the smaller
number reached by counting inwards from either extreme y(1) or y(n)
toward any specified value. So the depth of y(i) is the smaller of i and
n - i + 1.

Trimmed means as plotted by trimplot by default may be
related to depth as follows. A trimmed mean may be defined for any
particular depth as the mean of all values with that depth or greater.
Thus the trimmed mean for depth 1 is the mean of all values. The trimmed
mean for depth 2 is the mean of all values except those of depth 1, i.e.
all values except for the extremes. The trimmed mean for depth 3 is the
mean of all values except those of depth 1 and 2; and so forth.

The highest depth observed for a distribution occurs once if n
is odd and twice if n is even; either way it labels values whose mean is
the median. Thus trimmed means range from the mean to the median.

The idea of plotting trimmed mean as a family or function
is simple. Examples can be found in Rosenberger and Gasko (1983,
p.315) and Davison and Hinkley (1997, p.122). Users knowing good and/or
early references are welcome to email me with details.

Alternatively, values can be ordered in terms of their absolute
deviation from the median. The option metric is required for this.
In this case trimmed means are defined as
the means of values whose absolute deviation from the median is no greater
than some specified amount. More formally, let med() indicate taking the
median and ave() taking the average. Trimmed means for a variable y are then a
family ave(y : |y - med(y)| <= d). As d becomes small, the trimmed mean
tends to the median; as d becomes arbitrarily large, it becomes the
unconditional mean. This sequence of trimmed means has the same endpoints
(the mean and median) as trimmed means defined using depth, but need
not coincide with the latter otherwise.

For more on trimmed means, see the help for trimmean
(which must be installed first).

Options

over(overvar) specifies that calculations are
to be carried out separately for each group defined by overvar but
plotted in the same panel. over() is allowed only with a single
variable to be plotted.

by(byvar [, by_subopts] )
specifies that calculations are to be carried out separately for each
group defined by byvar and plotted in separate panels. Suboptions
may be specified to tune the graphical display: see help on the
by option. by() is allowed only with a single
variable to be plotted.

over() and by() may not be combined.

percent specifies that depth is to be scaled and plotted
as percent trimmed, which will range from 0 to nearly 50 (a median cannot
be based on no observed values, so 50 cannot be attained).

metric specifies that trimmed means be defined and plotted
in terms of allowed absolute deviation from the median.

mad specific metric trimming as above, but values will be
plotted versus absolute deviation from the median / median absolute deviation
from the median. The median (absolute) deviation (from the median) can be traced to Gauss (1816).

scatter_options are options of twoway scatter.

Examples

. webuse citytemp

. describe

. trimplot *dd

. trimplot temp*

. trimplot tempjan, over(region) percent

. gen code = word("E C S W", region)

. trimplot tempjan, over(region) metric mad legend(off) mla(code code code code) mlabpos(0 ..) ms(none ..)

Author

Nicholas J. Cox, Durham University

n.j.cox@durham.ac.uk

Acknowledgments

Ariel Linden found a typo in the help.

References

Davison, A.C. and Hinkley, D.V. 1997.
Bootstrap methods and their application.
Cambridge: Cambridge University Press.

Gauss, C.F. 1816.
Bestimmung der Genauigkeit der Beobachtungen.
Zeitschrift für Astronomie und verwandte Wissenschaften
1: 187-197.

Rosenberger, J.L. and Gasko, M. 1983.
Comparing location estimators: trimmed means, medians, and trimean.
In Hoaglin, D.C., Mosteller, F. and Tukey, J.W. (Eds)
Understanding robust and exploratory data analysis.
New York: John Wiley, 297-338.

Tukey, J.W. 1977.
Exploratory data analysis.
Reading, MA: Addison-Wesley.

Also see

summarize,
means,
trimmean (if installed),
hsmode (if installed),
shorth (if installed)