Statistics 3011 (Geyer and Jones, Spring 2006) Examples: Histograms, Stemplots, and Smooths

Contents

Histograms

For our example we will use the data from Exercise 1.17 in the Textbook (Moore) which is in the URL

http://www.stat.umn.edu/geyer/3011/mdata/chap01/ex01-17.dat

so we can use the URL external data entry method.

External Data Entry

Enter a dataset URL :

Or

Select a local file to submit:

Comments

The R function hist (on-line help) draws histograms.

The first argument is a vector of numbers that are the data (observations of a continuous variable).

Looking in the data URL linked above we see the numbers are in the variable named Return That is where we got those variable names.

The histogram produced by the first try doesn't look much like the one in the textbook (on p. 24). Either we don't have enough bins or the book has too many (not clear which).

The breaks argument allows us to suggest a number of bins (R may choose more or fewer to get round numbers for bin divisions). That plot looks just like the book except for labels. The next try adds labels like the book.

The last try changes the vertical axis from counts to probability density. (The areas of the boxes sum to 1.00.) You may use either frequency (counts, the default) or density. The picture is the same either way. Only the vertical axis changes.

Stem and Leaf Plots

For our example we will use the data from Example 1.8 in the Textbook (Moore) which is in the URL

http://www.stat.umn.edu/geyer/3011/mdata/chap01/eg01-08.dat

so we can use the URL external data entry method.

External Data Entry

Enter a dataset URL :

Or

Select a local file to submit:

Comments

The R function stem (on-line help) does stem and leaf plots.

The stem gives only one very simple control over how the stems and leaves are chosen. The optional argument scale, used in the second and third try in the example, give stem a hint (which it may not get). Values larger than one tell stem to spread it out. Values smaller than one tell stem to compress it.

You just have to fiddle with the scale argument until you get what you want (if any setting gives you what you want). On the third try we get what Figure 1.7 in the book has.

Smooths

For our example we will use the same data as we used for histograms above.

External Data Entry

Enter a dataset URL :

Or

Select a local file to submit:

Comments

The R function density (on-line help) draws smooth density curves. Or, to be more precise, it calculates but does not draw it, which is why the result must be passed to the plot function.