How to find the statistical mode?

前端 未结 30 1642
时光取名叫无心
时光取名叫无心 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:01

    A quick and dirty way of estimating the mode of a vector of numbers you believe come from a continous univariate distribution (e.g. a normal distribution) is defining and using the following function:

    estimate_mode <- function(x) {
      d <- density(x)
      d$x[which.max(d$y)]
    }
    

    Then to get the mode estimate:

    x <- c(5.8, 5.6, 6.2, 4.1, 4.9, 2.4, 3.9, 1.8, 5.7, 3.2)
    estimate_mode(x)
    ## 5.439788
    

提交回复
热议问题