[R] How to identify the two largest peaks in a trimodal distribution

Paul Smith phhs80 at gmail.com
Sat Oct 13 10:49:25 CEST 2007

On 10/13/07, Rob Knell <R.Knell at qmul.ac.uk> wrote:
> I'm trying to do a simulation that involves identifying the minimum
> point between two peaks of a (usually) bimodal distribution. I can do
> this easily if there are only two peaks:
> CnBdens<-density(Ys/Xs) #probability density function for ratio of Ys
> to Xs
>         for(p in 1:512) ifelse(CnBdens$y[p]>CnBdens$y[p-1],peak1<-p,break)
> #identifies first peak in probability distribution
>         for(p in 1:512) ifelse(CnBdens$y[512-p]>CnBdens$y[512-p
> +1],peak2<-512-p,break) #identifies second peak in probability
> distribution
>   but the simulation sometimes produces a small third peak at one end
> of the distribution. Is there any simple way to identify the two
> highest maxima in a trimodal distribution?

Is your distribution discrete or continuous?


More information about the R-help mailing list