# What does the y axis in a kernel density plot mean? [duplicate]

Possible Duplicate:
Probability distribution value exceeding 1 is OK?

I thought the area under the curve of a density function represents the probability of getting an x value between a range of x values, but then how can the y-axis be greater than 1 when I make the bandwidth small? See this R plot:

range <- seq(2,6,.01)
n <- 1000
d <- sample(range,n, replace=TRUE)
d <- c(d,rep(0,100))
d <- c(d,rep(1,50))
df <- data.frame(counts=d)
plot(dens)


Also, the probability of getting $P(x<2)=\frac{150}{1000}=.15$, how can I see this in the plot?

• Consider a uniform density on $(0,0.1)$. What's the height of the density in that range? Density is not probability. Jan 20, 2013 at 6:17
• Density is "unit probability". Jun 11, 2014 at 11:10

You are correct that

the area under the curve of a density function represents the probability of getting an x value between a range of x values

But remember area is not just height: width is also important. So if you have a spike at 0, if the width is very small (say 0.1) then the height can be quite a bit higher than 1 (up to 10, if the spike is perfectly rectangular, since $0.1\times10 = 1$) without violating any rules of probability. The height of the spike is large, but the area under the spike is still quite small.

For the same reason, density functions of continuous random variables can have values greater than one. If you plot a Normal(0,0.0001) pdf, for example, you will find that the peak is quite high.

I missed your second question initially, but $P(x<2)=\frac{150}{1000}=.15$ means that the area under the curve to the left of 2 (i.e., the area of the two spikes at 0 and 1, more or less) is .15.

• Thanks, that makes sense. In R I can do library(pracma);trapz(dens$x[dens$x < 2], dens$y[dens$x < 2]) and I get .139. Close enough Jan 20, 2013 at 2:23