help for transplot

Plots for trying out transformations

One-way mode:

transplot
cmd
varlist
[if exp]
[in range]
,
transform(trans_spec)
[
cmd_options
combineopts(combine_opts)
]

Two-way mode:

transplot
cmd
( yvarlist )
( xvarlist )
[if exp]
[in range]
,
ytransform(trans_spec)
xtransform(trans_spec)
[
cmd_options
combineopts(combine_opts)
]

Description

transplot draws plots using one or more transformed versions of
supplied numeric variables. One-way and two-way modes are supported.

For the one-way mode, the syntax starts transplot cmd
varlist, where

cmd is any graph command for one variable

varlist specifies one or more numeric variables

and transform() is a required option.

With one-way mode a separate plot appears for each variable and
each transformation specified.

For the two-way mode, the declared syntax starts
transplot cmd
( yvarlist )
( xvarlist ) where

cmd is any graph command for two variables, noting that
commands such as twoway connected are included

( yvarlist ) specifies one or more numeric variables
to be plotted on the vertical axis (in practice, parentheses ()
may be omitted for a single y variable)

( xvarlist ) specifies one or more numeric variables
to be plotted on the horizontal axis (in practice, parentheses ()
may be omitted; all variables named after the first token are treated as
x variables)

and at least one of ytransform() and xtransform()
is a required option.

With two-way mode a plot is drawn for each combination of
y variable, x variable and transformation.

Some broad advice: transplot allows you to draw many
graphs, but comparison may be difficult with more than a chosen few.
transplot does not try to be smart about axis labels for
transformed scales.
transplot is for exploratory analysis, not modelling.

Options

transform() is a required option for one-way mode. The
rules are (1) @ means the variable itself; (2) a bare Stata
function name such as log10 is applied to the variable; (3) an
expression such as sqrt(@) - sqrt(1 - @) is evaluated substituting
the variable name for @.

ytransform() is a required option for two-way mode if the
y axis variable is to be transformed. If omitted, the variable is
plotted as it arrives. Otherwise the rules are (1) (2) (3) as above.

xtransform() is a required option for two-way mode if the
x axis variable is to be transformed. If omitted, the variable is
plotted as it arrives. Otherwise the rules are (1) (2) (3) as above.

Transformation expressions containing spaces should be protected by
double quotation marks "".

cmd_options are options of cmd.

combineopts() are options of graph combine. Note
that this includes name() or saving() should you wish to
name or save the resulting graph.

Examples

For most of the graphs here see Cox (2019a).

Spiegelhalter (2019) includes an example with guesses on how
many jelly beans are in a jar. The data tell you more about guessing
than about jelly beans, but that is fine.

. use beans, clear

. transplot qnorm beans, trans(@ log10) ms(Oh)

. transplot kdensity beans, trans(@ log10) combine(col(1))

. webuse grunfeld, clear

. transplot qnorm invest mvalue kstock, trans(@ log10) ms(Oh)

. transplot qnorm invest mvalue kstock, trans(@ log10) ms(Oh) combine(colfirst)

. transplot qnorm invest mvalue kstock, trans(@ log10) combine(colfirst) recast(line) lw(medthick)

Note: Although qnorm works fine here, the
community-contributed qplot (Cox 1999, 2005, 2019b) is more
flexible.

. sysuse auto, clear

. transplot scatter mpg weight, ytrans(@ log10 100/@) ms(Oh)

. transplot scatter mpg weight, ytrans(@ log10 100/@) xtrans(@ log10) ms(Oh) combine(colfirst)

. sysuse census, clear

. transplot scatter (marriage divorce) (pop) , ytr(log10) xtr(log10)

Remarks

Transformations in general

Transformation can mean (for example) using a
transformed scale on a graph axis; transforming variables for later
analysis; using a particular link function in a model.

Researchers and students alike often have problems deciding
whether and how to choose transformed scales. Teachers often have
problems trying to teach that topic. Whatever makes thinking about
transformations easier is welcome. The best arguments are often graphical,
whenever you can see that a transformation works - or is useless.

What makes use of a transformed scale - or choice of a
transformed scale - easier to think about?

Without attempting here even a brief history, I note that
Galileo Galilei in 1627 recommended using the geometric mean of bids to
decide on a fair price, in effect recommending thinking on a logarithmic
scale.

In 1627 Galileo "was presented with an amiable dispute between a
Florentine gentleman and a parish priest over the proper method to price
a horse .... one bidder-undoubtedly the priest-had offered ten crowns
and the other one thousand. In arriving at the proper value, the
equestrians asked Galileo to be their arbiter. Was it better to employ
an arithmetic or a geometric proportion in arriving at a fair price
between divergent estimates? A geometric proportion was Galileo's
answer. The real value of the horse was one hundred."

Reston, James. 1994. Galileo: A Life. New York: HarperCollins, p.218

The toolkit includes (Tukey 1957, 1977; Box and Cox 1964;
Mosteller and Tukey 1977; Atkinson 1985; Keene 1995)

for variables y

logarithms and powers
neglog: sign(y) log(1 +|y|) and its siblings
inverse hyperbolic sine asinh()

for proportions p

logit: log [p / (1 - p)] = log p - log (1 - p)
folded roots: sqrt(p) - sqrt(1 - p) and its siblings
loglog(), cloglog()

for correlations and similar measures r

Fisher's z: atanh(r) = (1/2) logit((1 + r)/2)

Some goals (or Grails) of transformations are

linear relationships
additive effects
equal variability
symmetric distribution (even normal distribution)

The last goal is not the most important, as many researchers
seem to think....

Objections - not always from those new to or naive about
statistics - include

Transformation is troubling. Using an unfamiliar function
just makes the analysis harder to think about.

Transformation is tricky. How do we choose a
transformation without seeming arbitrary or ad hoc?

Transformation is treasonous. You are proposing changing
the data. How is that allowed or even honest?

Transformed scales in graphics

As people are always coming new to Stata, so a brisk survey of
using transformed scales in graphics comes first. Graph commands in
most cases allow yscale(log) and xscale(log) as option
choices.

Limitation: This does not always give what you really want. For
example, with histograms and box plots, working on logarithmic scale
requires a fresh calculation.

Limitation: graph does not typically make good default
choices of axis labels with a logarithmic scale. Doing better was
discussed in Cox (2018). The niceloglabels command discussed there
depends on the user specifying a style. style(1) means labels
like 1 10 100. style(13) means labels like 1 3 10 30 100.
style(125) means labels like 1 2 5 10 20 50 100.

Using other transformed scales (e.g. root, logit) divides into
(1) which numbers to use on the transformed scale? (2) which axis labels to
show values on the original scale? For more technique, see Cox (2008) and
mylabels (SSC).

The ladder commands in official Stata

ladder, gladder and qladder are official
commands of some vintage. ladder and gladder were added to
Stata in 1992. qladder was added to Stata in 2000. A sample
script follows.

. sysuse citytemp, clear

. set scheme s1color

. ladder tempjuly

. gladder tempjuly, l1title("") ylabel(none) xlabel(none) name(gladder)

. qladder tempjuly, ylabel(none) xlabel(none) name(qladder)

ladder bins transformed data and does a chi-square test
for normality. If you want such a test, other tests are surely better,
say Shapiro-Wilk or Doornik-Hansen. Such a test often answers the wrong
question. For moderate or large sample sizes, it may merely detect
trivial departures from normality. For small sample sizes, it may
indicate that you do not have enough data.

gladder transforms data and shows histograms with
comparable normal distributions superimposed.

qladder transforms data and shows normal quantile plots
with comparable normal distributions as reference lines. Such plots are
also known as normal probability plots, normal scores plots, or probit
plots.

What is wrong with these commands?

These commands offer too many transformations. It should
never be true that all the transformations from cube to reciprocal cube
are serious candidates.

These commands offer too few transformations. No support
is offered for cube root, neglog, asinh, logit, folded roots or anything
not on the menu.

Histograms are poor for choosing a transformation.
Histograms depend too much on arbitrary choices of bin width and origin.
Important details are often difficult to spot.

The official examples are poor. Fahrenheit temperatures are
interval scale variables.

One variable at a time. Often you want to compare two or
more variables.

No support for group comparisons. Often you want to
compare two or more groups.

To be fair: The ladder idea is powerful (power full!) and
persuasive. Many transformations lie on a ladder (as emphasised by
J.W. Tukey and others): hence
choose that best suited to the data (possibly the identity
transformation?).

What is right: These commands are based on the idea of looping
over candidate transformations, generating temporary variables with
transforms and then drawing a graph for each candidate. Finally, combine
graphs and so show a portfolio.

Rumination

Command design means thinking through the design carefully
before you write any code. That can be hard.... Commands can suffer
from option creep and other conditions of complexity. The syntax becomes
Baroque if not rococo, and at most only the programmer understands the
command. What the programmer thinks of as a handy Swiss army knife might
be just a Heath Robinson machine (William Heath Robinson, 1872-1944)
or a Rube Goldberg machine (Reuben Garrett Lucius Goldberg,
1883-1970).

References

Atkinson, A.C. 1985.
Plots, Transformations, and Regression: An Introduction to Graphical Methods of Diagnostic Regression Analysis.
Oxford: Oxford University Press.

Box, G.E.P. and D.R. Cox. 1964.
An analysis of transformations.
Journal of the Royal Statistical Society, Series B 26: 211-252.
https://www.jstor.org/stable/2984418

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

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

Cox, N.J. 2008.
Plotting on any transformed scale.
Stata Journal 8: 142-145.

Cox, N.J. 2018. Logarithmic binning and labelling.
Stata Journal 18: 262-286.

Cox, N.J. 2019a. Needing a different space?
Transformed scales in Stata.
Presentation at London Stata Conference, 5-6 September 2019, Cass Business School.
https://www.stata.com/meeting/uk19/slides/uk19_cox.pptx

Cox, N.J. 2019b. Software Update: Quantile plots, generalized.
Stata Journal 19: 748.

Keene, O.N. 1995. The log transformation is special.
Statistics in Medicine 14: 811-819.

Mosteller, F. and J.W. Tukey. 1977.
Data Analysis and Regression: A Second Course in Statistics.
Reading, MA: Addison-Wesley.

Spiegelhalter, D. 2019.
The Art of Statistics: Learning from Data.
London: Penguin.

Tukey, J.W. 1957.
On the comparative anatomy of transformations.
Annals of Mathematical Statistics 28: 602-632.
https://www.jstor.org/stable/2237224

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

Author

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

n.j.cox@durham.ac.uk

Also see

On-line: help for ladder, gladder,
qladder, qplot (if installed), niceloglabels (if
installed), mylabels (if installed), crossplot (if
installed)