Peak of the kernel density estimation

前端 未结 3 1655
孤街浪徒
孤街浪徒 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:57

    If I understand your question, I think you are just wanting a finer discretisation of x and y. To do this, you can change the value of n in the density function (default is n=512).

    For example, compare

    set.seed(1)
    x = rlnorm(100)
    d = density(x)
    i = which.max(d$y)
    d$y[i]; d$x[i]
    0.4526; 0.722
    

    with:

    d = density(x, n=1e6)
    i = which.max(d$y)
    d$y[i]; d$x[i]
    0.4525; 0.7228
    

提交回复
热议问题