10 1. Summarizing Data Box 1.2. R packages used in this text From now on we will assume that the lattice, Hmisc, and fastR packages have been loaded and will not show the loading of these packages in our examples. If you try an example in this book and R reports that it cannot find a function or data set, it is likely that you have failed to load one of these packages. You can set up R to automatically load these packages every time you launch R if you like. (See Appendix A for details.) Other packages will be used from time to time as well. In this case, we will show the require() statement explicitly. The documentation for the fastR package includes a list of required and recommended packages. +-------+----------+---+------------+ | | |N |Sepal.Length| +-------+----------+---+------------+ |Species|setosa | 50|5.0060 | | |versicolor| 50|5.9360 | | |virginica | 50|6.5880 | +-------+----------+---+------------+ |Overall| |150|5.8433 | +-------+----------+---+------------+ summary(Sepal.Length~Species,iris,fun=median) # median instead Sepal.Length N=150 +-------+----------+---+------------+ | | |N |Sepal.Length| +-------+----------+---+------------+ |Species|setosa | 50|5.0 | | |versicolor| 50|5.9 | | |virginica | 50|6.5 | +-------+----------+---+------------+ |Overall| |150|5.8 | +-------+----------+---+------------+ Comparing with the histograms in Figure 1.2, we see that these numbers are indeed good descriptions of the center of the distribution for each species. We can also compute the mean and median of the Old Faithful eruption times. faithful-mean-median mean(faithful$eruptions) [1] 3.4878 median(faithful$eruptions) [1] 4 Notice, however, that in the Old Faithful eruption times histogram (Figure 1.5) there are very few eruptions that last between 3.5 and 4 minutes. So although these numbers are the mean and median, neither is a very good description of the typical eruption time(s) of Old Faithful. It will often be the case that the mean and median are not very good descriptions of a data set that is not unimodal.
Previous Page Next Page