[R] Histogram questions
Thomas Lumley
tlumley at u.washington.edu
Mon Feb 5 23:10:00 CET 2001
On Mon, 5 Feb 2001, M. Edward (Ed) Borasky wrote:
> Questions on histograms:
>
> 1. When I run "hist" on a data set, the histogram object produced has two
> variables, "$density" and "$intensities". These appear to be the same:
>
> $intensities
> [1] 1.7619226436 0.0360495682 0.1967705595 0.0000000000 0.0037551633
> [6] 0.0000000000 0.0007510327 0.0007510327
>
> $density
> [1] 1.7619226436 0.0360495682 0.1967705595 0.0000000000 0.0037551633
> [6] 0.0000000000 0.0007510327 0.0007510327
>
> Why are they the same? Are both necessary?
It says in help(hist)
intensities: same as `density'. Deprecated, but retained for
compatibility.
> 2. I want to plot histograms that are normalized -- that is, the sum of the
> intensities or density is 1.0, so the bars represent probabilities. As it's set
> up now, I have to do this calculation manually. Why can't R do this when it
> calculates the values? If I specify "probability=TRUE", I expect probabilities,
> not some arbitrarily scaled value.
A histogram, like a kernel density, estimates the density, not the
probability. The bar heights would only add to 1 if the bars all had
width 1. If you want a barplot, use barplot().
> 3. What would be even nicer is to have "hist" and "density" *both* scale their
> outputs as probabilities, so they could be overlaid on a plot together. How
> difficult is this to do?
They both *do* scale their outputs as probability densities so they *can*
be overlaid. They couldn't be overlaid if the bar heights added up to 1,
since then the histogram wouldn't be a density estimate.
Eg
data(faithful)
hist(faithful$eruptions,prob=TRUE)
lines(density(faithful$eruptions))
-thomas
Thomas Lumley Asst. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list