I need to find as precisely as possible the peak of the kernel density estimation (modal value of the continuous random variable). I can find the approximate value:
I think you need two steps to archive what you need:
1) Find the x-Axis value of the KDE peak
2) Get the desnity value of the peak
So (if you dont mind using a package) a solution using the hdrcde
package would look like this:
require(hdrcde)
x<-rlnorm(100)
d<-density(x)
# calcualte KDE with help of the hdrcde package
hdrResult<-hdr(den=d,prob=0)
# define the linear interpolation function for the density estimation
dd<-approxfun(d$x,d$y)
# get the density value of the KDE peak
vDens<-dd(hdrResult[['mode']])
Edit: You could also use the
hdrResult[['falpha']]
if it is precise enough for you!