Skip to content
Prev 173558 / 398502 Next

How to find maximum values on the density function of a random variable

rv <- rbinom(10000,1,0.1) + rnorm(10000)

d.rv = density(rv)
d.x = d.rv$x
d.y = d.rv$y

d.rv.max = d.rv$x[which.max(d.rv$y)]

plot(d.rv)
abline(v=d.rv.max)

#that what you want?
On Thu, Mar 12, 2009 at 6:28 PM, <guox at ucalgary.ca> wrote: