How to find the statistical mode?

前端 未结 30 1674
时光取名叫无心
时光取名叫无心 2020-11-21 07:00

In R, mean() and median() are standard functions which do what you\'d expect. mode() tells you the internal storage mode of the objec

30条回答
  •  忘了有多久
    2020-11-21 08:03

    I can't vote yet but Rasmus Bååth's answer is what I was looking for. However, I would modify it a bit allowing to contrain the distribution for example fro values only between 0 and 1.

    estimate_mode <- function(x,from=min(x), to=max(x)) {
      d <- density(x, from=from, to=to)
      d$x[which.max(d$y)]
    }
    

    We aware that you may not want to constrain at all your distribution, then set from=-"BIG NUMBER", to="BIG NUMBER"

提交回复
热议问题