Peak of the kernel density estimation

前端 未结 3 1634
孤街浪徒
孤街浪徒 2020-12-29 12:26

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:

3条回答
  •  时光说笑
    2020-12-29 12:52

    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!

提交回复
热议问题