guox at ucalgary.ca
2009-Mar-12 21:28 UTC
[R] How to find maximum values on the density function of a random variable
I would like to find the maximum values on the density function of a random variable. For example, I have a random variable rv <- rbinom(10000,1,0.1) + rnorm(10000) Its density function is given by density(rv) and can be displayed by plot(density(rv)). How to calculate its maximum values? A density function may have a few (global and local) maximum values. Please help. Thanks, -james
Mike Lawrence
2009-Mar-13 00:40 UTC
[R] 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:> I would like to find the maximum values on the density function of a > random variable. For example, I have a random variable > > rv <- rbinom(10000,1,0.1) + rnorm(10000) > > Its density function is given by density(rv) and can be displayed by > plot(density(rv)). How to calculate its maximum values? > A density function may have a few (global and local) maximum values. > Please help. Thanks, > -james > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tinyurl.com/mikes-public-calendar ~ Certainty is folly... I think. ~