Learn R Programming

modeest (version 1.06)

mlv: Estimation of the Mode

Description

mlv is a generic function which enables to compute an estimate of the mode of a univariate distribution. Many different estimates (or methods) are provided:
  • mfv, which returns the most frequent value(s) in a given numerical vector;
  • theLientzmode estimator, which is the value minimizing the Lientz function estimate;
  • the Chernoff mode estimator, also callednaivemode estimator, which is defined as the center of the interval of given length containing the most observations;
  • theVentermode estimator, including theshorth, i.e. the midpoint of the modal interval;
  • theGrenandermode estimator;
  • the half sample mode (HSM) and the half range mode (HRM), which are iterative versions of Venter mode estimator;
  • Parzen's kernel mode estimator, which is the value maximizing the kernel density estimate;
  • theTsybakovmode estimator, based on a gradient-like recursive algorithm.
mlv can also be used to compute the mode of a given distribution, with mlv.character. A 'plot' and a 'print' methods are provided.

Usage

mlv(x, ...)

## S3 method for class 'default':
mlv(x, bw = NULL, method, na.rm = FALSE, dip.test = FALSE, 
   boot = FALSE, R = 100, B = length(x), ...)
## S3 method for class 'factor':
mlv(x, ...)
## S3 method for class 'integer':
mlv(x, na.rm = FALSE, ...)
## S3 method for class 'character':
mlv(x, ...)
## S3 method for class 'density':
mlv(x, all = TRUE, dip.test = FALSE, biau = FALSE, ...)
## S3 method for class 'mlv':
plot(x, ...)
## S3 method for class 'mlv':
print(x, digits = NULL, ...)

Arguments

x
numeric (vector of observations), or an object of class "factor", "integer", etc.
bw
numeric. The bandwidth to be used. This may have different meanings regarding the method used.
method
character. One of the methods available for computing the mode estimate. See 'Details'.
na.rm
logical. Should missing values be removed?
dip.test
logical. Should Hartigan's DIP statistic for unimodality be computed?
boot
logical. Should bootstrap resampling be done?
R
numeric. If boot = TRUE, the number of bootstrap resampling rounds to use.
B
numeric. If boot = TRUE, the size of the bootstrap samples drawn from x. Default is to use a sample which is the same size as data. For large data sets, this may be slow and unnecessary.
all
logical.
biau
logical. If FALSE (the default), the estimate of the density function is maximised using optim.
digits
numeric. Number of digits to be printed.
...
Further arguments to be passed to the function called for computation. This function is related to the method argument.

Value

  • mlv returns an object of class "mlv". An object of class "mlv" is a list containing at least the following components:
  • Mthe value of the mode
  • skewnessBickel's measure of skewness
  • xthe argument x
  • methodthe argument method
  • dip.statHartigan's DIP statistic
  • bootthe argument boot
  • boot.Mif boot = TRUE, the resampled values of the mode
  • callthe call which produced the result

Details

For the function mlv.default, available methods are "discrete", "lientz", "naive", "venter", "grenander", "hsm", "hrm", "parzen", and "tsybakov". See the description above and the associated links. If x is of class "factor" or "integer", the most frequent value found in x is returned. If x is of class "character", x should be one of "beta", "cauchy", "gev", etc. i.e. a character for which a function 'x'Mode exists (for instance betaMode, cauchyMode, etc.). See distribMode for the available functions. The mode of the corresponding distribution is returned. If x is of class "density", the value where the density is maximised is returned. For the S3 function mlv.lientz, see Lientz for more details.

References

See the references on mode estimation on the modeest-package's page. For the DIP test, see:
  • Hartigan J.A. and Hartigan P.M. (1985). The Dip Test of Unimodality.Ann. Statist.,13:70-84.
  • Hartigan P.M. (1985). Computation of the Dip Statistic to Test for Unimodality.Appl. Statist. (JRSS C),34:320-325.

See Also

mfv, Lientz, naive, venter, grenander, hrm, hsm, parzen, tsybakov, skewness

Examples

Run this code
# Unimodal distribution
x <- rbeta(1000,23,4)

## True mode
betaMode(23, 4)
# or
mlv("beta", 23, 4)

## Estimate of the mode
mlv(x, method = "lientz", bw = 0.2)
mlv(x, method = "naive", bw = 1/3)
mlv(x, method = "venter", type = "shorth")
mlv(x, method = "grenander", p = 4)
mlv(x, method = "hrm", bw = 0.3)
mlv(x, method = "hsm")
mlv(x, method = "parzen", kernel = "gaussian")
mlv(x, method = "tsybakov", kernel = "gaussian")

## Bootstrap
M <- mlv(x, method = "kernel", boot = TRUE, R = 150)
print(M)
plot(M)
print(mean(M[["boot.M"]]))

Run the code above in your browser using DataLab