Learn R Programming

multimode (version 1.0)

locmodes: Location of modes and antimodes

Description

Given a certain number of modes, this function provides the estimation of the location of modes and antimodes and their density value.

Usage

locmodes(data,mod0=1,lowsup=-Inf,uppsup=Inf,n=2^15,tol=10^(-5),display=F,
addplot=NULL,xlab=NULL,ylab=NULL,addLegend=NULL,posLegend=NULL)

Arguments

data

Sample in which the critical bandwidth is computed.

mod0

Number of modes for which the critical bandwidth is calculated. Default mod0=1.

lowsup

Lower limit for the random variable support in the computation of the critical bandwidth. Default is -Inf.

uppsup

Upper limit for the random variable support in the computation of the critical bandwidth. Default is Inf.

n

The number of equally spaced points at which the density is to be estimated. When n > 512, it is rounded up to a power of 2 as in the density function. Default n=2^15.

tol

Accuracy requested in the computation of the critical bandwidth. Default tol=10^(-5).

display

Logical, if TRUE the kernel density estimation is plotted adding the estimated location of the modes and the antimodes. Default is FALSE.

addplot

Logical, if TRUE the plot is added to the current one. Default if display=TRUE is FALSE.

xlab

A title for the x axis. See title.

ylab

A title for the y axis. See title.

addLegend

Logical, if TRUE the legend is added in the plot. Default if display=TRUE is TRUE.

posLegend

The vector of two elements of coordinates to be used to position the legend. It can be specified by keyword as in the function legend. Default if display=TRUE is "topright".

Value

locations

Vector with the estimated locations of modes (odd positions of the vector) and antimodes (even positions).

fvalue

Vector with estimated density values at modes (odd positions of the vector) and antimodes (even positions).

cbw

Critical bandwidth of the sample for mod0 modes.

Details

Given a certain number of modes, mod0, with locmodes the estimation of the location of modes and antimodes, their density value and the corresponding critical bandwidth is provided. To obtain these estimates, the kernel density estimation with gaussian kernel and the critical bandwidth for mod0 modes is employed. If the compact support is unknown, the critical bandwidth of Silverman (1981) is computed and if such a support is provided, then the one proposed by Hall and York (2001) is calculated. Note that when the support is unknown the critical bandwidth may create artificial modes in the tails.

Since a dichotomy method is employed for computing the critical bandwidth, the parameter tol is used to determine a stopping time in such a way that the error committed in the computation of the critical bandwidth is less than tol.

If display=TRUE, then the kernel density estimation using the critical bandwidth for mod0 modes is plotted. Additionally, the estimated location of modes (dashed lines), antimodes (point lines) and support (solid lines) can be also plotted. If addLegend=TRUE, a legend (in the position posLegend) with this information is included.

The NAs will be automatically removed.

References

Ameijeiras--Alonso, J., Crujeiras, R.M. and Rodr<U+00ED>guez--Casal, A. (2016). Mode testing, critical bandwidth and excess mass, arXiv preprint: 1609.05188.

Hall, P. and York, M. (2001). On the calibration of Silverman's test for multimodality, Statistica Sinica, 11, 515--536.

Silverman, B. W. (1981). Using kernel density estimates to investigate multimodality, Journal of the Royal Statistical Society. Series B, 43, 97--99.

Examples

Run this code
# NOT RUN {
# Testing for unimodality
set.seed(2016)
data=rnorm(50)
modetest(data)
#There is no evidence to reject the null hypothesis of unimodality
#Estimated location of the mode and its density value
locmodes(data)
# }
# NOT RUN {
#Estimated locations of the five modes in the claw of Marron and Wand (1992)
library(nor1mix)
set.seed(2016)
n<-200
data<-nor1mix::rnorMix(n,MW.nm10)
#Adding the plot of the estimated locations
locmodes(data,5,display=T)
#Assuming that the compact support is [-1.5,1.5]
locmodes(data,5,-1.5,1.5,display=T)
# }

Run the code above in your browser using DataLab