[R] How to get mode (the most frequent value in distribution) ?

Liaw, Andy andy_liaw at merck.com
Fri Nov 12 14:10:53 CET 2004


A sample from a continuous distribution most likely has no meaningful sample
mode.  Shown below is a way to estimate the location of mode from a kernel
density estimate (using the locfit package):

> x <- rnorm(50)
> library(locfit)
Locfit for R.
August 3, 2000.  (Updated for R 1.7.0, March 21, 2003)

Attaching package 'locfit':


        The following object(s) are masked from package:stats :

         knots 

> x.den <- locfit(~x)
> x[which.max(predict(x.den, newdata=x))]
[1] -0.615337

HTH,
Andy

> From: Gregor GORJANC
> 
> Hello!
> 
> I have a continous distribution and would like to get mode  (the most 
> frequent value in distribution). I easily found mean, median 
> and other 
> basic thing but not mode function. Can anyone help?
> 
> I know there my might be problems with multiple modes, but 
> still I think 
> that there should be a mode function in R.
> 
> Please send mail to R-help list and me, so I can get response faster.
> 
> Thank you!
> 
> -- 
> Lep pozdrav / With regards,
>      Gregor GORJANC
> 
> ---------------------------------------------------------------
> University of Ljubljana
> Biotechnical Faculty       URI: http://www.bfro.uni-lj.si
> Zootechnical Department    mail: gregor.gorjanc <at> bfro.uni-lj.si
> Groblje 3                  tel: +386 (0)1 72 17 861
> SI-1230 Domzale            fax: +386 (0)1 72 41 005
> Slovenia
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list