dip.test
Hartigans' Dip Test for Unimodality
Compute Hartigans' dip statistic $Dn$, and its pvalue 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 nonunimodal, i.e., at least bimodal. Using the language of medical testing, you would call the test “Test for Multimodality”.
 Keywords
 distribution, htest
Usage
dip.test(x, simulate.p.value = FALSE, B = 2000)
Arguments
 x
 numeric vector; sample to be tested for unimodality.
 simulate.p.value
 a logical indicating whether to compute pvalues by Monte Carlo simulation.
 B
 an integer specifying the number of replicates used in the Monte Carlo test.
Details
If simulate.p.value
is FALSE
, the pvalue is computed
via linear interpolation (of $sqrt(n) * Dn$) in the
qDiptab
table.
Otherwise the pvalue is computed from a Monte Carlo simulation of a
uniform distribution (runif(n)
) with B
replicates.
Value

A list with class
"htest"
containing the following
components:Note
see also the package vignette, which describes the procedure in more details.
References
see those in dip
.
See Also
For goodnessoffit testing, notably of continuous distributions,
ks.test
.
Examples
## a first nontrivial case
(d.t < dip.test(c(0,0, 1,1))) # "perfect bimodal for n=4" > pvalue = 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)
## borderline bimodal ... 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))