[R] stem() bug?

Jack Tanner ihok at hotmail.com
Wed Aug 25 01:11:50 CEST 2004


<insert obligatory bemoan>

First, I'm curious. Is there any reason why the leaves are squished together 
with no delimeters?

Second, the crucial point that seems to be missing from the stem help page 
(and one I can't glean without going through the code) is how bins are 
determined. If that can be explained to the reader, the explanation of scale 
follows naturally.

Third, feel free to incorporate the following text into the help page as 
necessary; I've tried to make it helpful (but clarity is obviously in the 
eye of the beholder).

stem produces a stem-and-leaf plot of the elements in x. Each element is 
placed in a bin ranging [low, high); that is, if y is an element, it is 
placed in the bin iff low <= element < high. The size of the bin is 
determined by... .

The stem that is listed for the bin is not necessarily the stem of all (or 
any) of the leaves in the bin; the true stems must be equal to or higher 
than the listed stems, but they will all be smaller than the  lowerst stem 
of the next highest bin. (Observe how the bin for the stem 4 changes with 
the two examples below.)

Leaves are ordered within a bin. If leaves seem unordered (e.g., 4 | 0306), 
then the scale of the plot may be too compressed: that bin contains leaves 
from multiple different stems. The parameter scale can be used to expand the 
scale of the plot.

Arguments
x 	a numeric vector.
scale 	This controls the number of bins. A value of scale=2 will cause the 
plot to be twice as long as the default by using roughly twice as many bins.
width 	The desired width of the plot, in characters.
atom 	a tolerance [This needs better text.]

Examples
stem(c(30, 32, 50, 52, 60, 62, 70, 72, 80, 82))
stem(c(30, 32, 50, 52, 60, 62, 70, 72, 80, 82), scale=2)

----Original Message Follows----
From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
To: Ramzi Nahhas <Ramzi_Nahhas at sil.org>
CC: ihok at hotmail.com, <jc at or.psychology.dal.ca>, <r-help at stat.math.ethz.ch>
Subject: Re: [R] stem() bug?
Date: Tue, 24 Aug 2004 09:17:08 +0100 (BST)

It is as intended.  The answer is correct but your interpretation of it is
not, and the help page is woefully lacking.

Note that the bins in your problem are [20, 40), [40, 60), [60, 80) and
[80, 100) and they are correctly labelled.  In such bins e.g. 20 and 30
are both represented in the same way.

Does stem(seq(30, 92, 5)) help you see the pattern?

Please would one of those bemoaning R's documentation recently submit to
R-bugs an enhanced help page for stem?

On Tue, 24 Aug 2004, Ramzi Nahhas wrote:

 >
 > Is the following a bug with stem() or is there something else that I am
 > missing? I ran stem() on the vector x below and got stem(x-10) instead of
 > stem(x). If I subtract 1 from x, I get a correct answer. If I add 1 to x, 
I
 > still get a wrong answer. If I add 10 to x, I get a correct answer. I'm 
not
 > sure what to make of this, other than to think it is a bug.
 >
 > Can anyone tell me if this is a bug?
 >
 > I am running R 1.9.1 on Windows XP (SP2).
 >
 > Sincerely,
 > 	Ramzi Nahhas
 >
 > PS In your reply, please copy me at Ramzi_Nahhas at sil.org as I am not
 > subscribed to this list. Thank you.
 >
 > > x
 >  [1] 30 70 90 75 70 95 75 70 60 55
 > > stem(x)
 >
 >   The decimal point is 1 digit(s) to the right of the |
 >
 >   2 | 0
 >   4 | 5
 >   6 | 000055
 >   8 | 05
 >
 > > stem(x-1)
 >
 >   The decimal point is 1 digit(s) to the right of the |
 >
 >   2 | 9
 >   4 | 49
 >   6 | 99944
 >   8 | 94
 >
 > > stem(x+1)
 >
 >   The decimal point is 1 digit(s) to the right of the |
 >
 >   2 | 1
 >   4 | 6
 >   6 | 111166
 >   8 | 16
 >
 > > stem(x+10)
 >
 >   The decimal point is 1 digit(s) to the right of the |
 >
 >    4 | 0
 >    6 | 50
 >    8 | 00055
 >   10 | 05
 >
 > ---
 >
 >
 >
 >
 >
 > 	[[alternative HTML version deleted]]
 >
 > ______________________________________________
 > R-help at stat.math.ethz.ch mailing list
 > https://stat.ethz.ch/mailman/listinfo/r-help
 > PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html
 >
 >

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list