diptest (version 0.75-3)

dip.test: Hartigans' Dip Test for Unimodality

Description

Compute Hartigans' dip statistic $D_n$, and its P-value for the test for unimodality, by interpolating tabulated quantiles of $\sqrt{n} D_n$.

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 p-values by Monte Carlo simulation.
B
an integer specifying the number of replicates used in the Monte Carlo test.

Value

  • A list with class "htest" containing the following components:
  • statisticthe dip statistic $D_n$, i.e., dip(x).
  • p.valuethe p-value for the test, see details.
  • methodcharacter string describing the test, and whether Monte Carlo simulation was used.
  • data.namea character string giving the name(s) of the data.

Details

If simulate.p.value is FALSE, the p-value is computed via linear interpolation (of $\sqrt{n} D_n$) in the qDiptab table. Otherwise the p-value is computed from a Monte Carlo simulation of a uniform distribution (runif(n)) with B replicates.

References

see those in dip.

See Also

For goodness-of-fit testing, notably of continuous distributions, ks.test.

Examples

Run this code
## 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))

Run the code above in your browser using DataCamp Workspace