[R] mode
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Sat Dec 13 14:19:43 CET 2003
Sorry, typo:
On 13-Dec-03 Ted Harding wrote:
> Example of kernel density estimation:
>
> X<-c(rnorm(200),2+0.5*rnorm(300))
> hist(X,freq=FALSE,breaks=(-4)+0.2*(0:50))
> S<-density(X,from=(-4),to=5,bw=0.2)
> N<-length(S$y)
> V1<-S$y[1:(N-2)];V2<-S$y[2:(N-1)];V3<-S$y[3:N]
> ix<-1+which((V1<V2)&(V2>V3))
> lines(S$x,S$y,col="red")
> points(S$x[ix],S$y[ix],col="blue")
>
> where the index ix identifies all the local modes of the fitted
> spline density estimate S. These include the global mode[s]
>
> S$x[which(S$y==maxS$y)]
S$x[which(S$y==max(S$y))]
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 13-Dec-03 Time: 13:19:43
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list