Results 1 to 3 of 3

Thread: R histogram weird behavior

  1. #1
    Join Date
    Sep 2007
    Location
    TX, USA
    Beans
    385
    Distro
    Ubuntu 16.04 Xenial Xerus

    R histogram weird behavior

    Hi everyone,
    I encountered some unexpected behavior from the hist() function while doing a curve-fitting assignment at work.

    First, upon typing this:
    Code:
    > hist(y,col="red")


    Then
    Code:
    > hist(y,prob=TRUE,col="red",ylim=c(0,1.5))
    gets me this


    Now, my question is: Why there are densities (probabilities) larger than 1 ??????

    the problem gets even worse if I try to increase the number of rectangles, using the 'breaks' option, like this:
    Code:
    > hist(y,breaks=50,prob=TRUE,col="red",ylim=c(0,2))


    Any idea what is going on here?
    This should be a sticky, or a bug 'cos it ain't a feature

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: R histogram weird behavior

    Probability density is not the same as probability - the area (not height) of each bar should correspond to the probability that the value falls with the range of that bar, and of course that should be < 1 (in fact the area of all the bars together should equal 1)

    So in your first 'Density' histogram, the height of the highest bar is maybe 1.1, but its width is only 0.2 i.e. probability that y lies in the range 0.8 to 1.0 is about 0.22

  3. #3
    Join Date
    Sep 2007
    Location
    TX, USA
    Beans
    385
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: R histogram weird behavior

    Thanks, that's what I figured.
    This should be a sticky, or a bug 'cos it ain't a feature

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •