Hartigans' Dip Test for Unimodality
Compute Hartigans' dip statistic Dn, and its p-value for the test for unimodality, by interpolating tabulated quantiles of sqrt(n) * Dn.
For X_i ~ F, i.i.d, the null hypothesis is that F is a unimodal distribution. Consequently, the test alternative is non-unimodal, i.e., at least bimodal. Using the language of medical testing, you would call the test “Test for Multimodality”.
dip.test(x, simulate.p.value = FALSE, B = 2000)
x |
numeric vector; sample to be tested for unimodality. |
simulate.p.value |
a logical indicating whether to compute p-values by Monte Carlo simulation. |
B |
an integer specifying the number of replicates used in the Monte Carlo test. |
A list with class "htest"
containing the following
components:
statistic |
the dip statistic Dn, i.e.,
|
p.value |
the p-value for the test, see details. |
method |
character string describing the test, and whether Monte Carlo simulation was used. |
data.name |
a character string giving the name(s) of the data. |
see also the package vignette, which describes the procedure in more details.
Martin Maechler
see those in dip
.
For goodness-of-fit testing, notably of continuous distributions,
ks.test
.
## a first non-trivial case (d.t <- dip.test(c(0,0, 1,1))) # "perfect bi-modal for n=4" --> p-value = 0 stopifnot(d.t$p.value == 0) data(statfaculty) plot(density(statfaculty)); rug(statfaculty) (d.t <- dip.test(statfaculty)) x <- c(rnorm(50), rnorm(50) + 3) plot(density(x)); rug(x) ## border-line bi-modal ... BUT (most of the times) not significantly: dip.test(x) dip.test(x, simulate=TRUE, B=5000) ## really large n -- get a message dip.test(runif(4e5))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.