\HeaderA{isPeak}{Locate Peaks in a Spectrum}{isPeak}
\keyword{nonparametric}{isPeak}
\begin{Description}\relax
Find local maxima of a spectrum.
\end{Description}
\begin{Usage}
\begin{verbatim}
isPeak(f,SoN = 2,span = 81,sm.span=11,plot=FALSE,add = FALSE,
zerothrsh=2,area.w = 0.003, ratio = 0.2, ...) \end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{f}] a matrix of two columns representing a spectrum, with the 
first column the m/z value and second the intensity
\item[\code{SoN}] signal to noise ratio criterion for peak detection
\item[\code{span}] parameter for estimating local variance before 
peak detection; default is 81 points, that is, 40 
points to the left and right of a point of which the 
variance is being estimated.
\item[\code{sm.span}] parameter for smoothing the spectrum before 
peak detection; default is 11 points, that is, 5 
points to the left and right of a point being smoothed
\item[\code{plot}] logical, plot the smoothed spectrum and peaks? 
\item[\code{add}] add to the existing raw and baseline-substracted plot?
\item[\code{zerothrsh}] ignore peaks whose intensity values are below zerothrsh.
\item[\code{area.w}] the neighbourhood of a peak m/z,
mz*(1-area.w, 1+area.w).
\item[\code{ratio}] if area/max(area) > ratio, the peak is retained.
\item[\code{...}] further arguments that get passed on to \code{plot}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
A spectrum is smoothed first using the nearest `span' 
neighbours. A larger span `sm.span' is needed to estimate
the local variation so that it is not overestimated due to
the peaks nearby.  Then potential peaks are identified using 
Ripley's `peaks' function with `span' points.

Peaks that satify the conditions that the (smoothed) signal 
to noise ratio is greater than `SoN' and that the smoothed 
signal is greater than 1.64 * mad(sm) are returned.
\end{Details}
\begin{Value}
A data frame with five components, `peak',`smooth',`mz' and
`sigmas', each of length the number of rows in `f'. 
`peak' is logical indicating whethere there is a peak or not 
(Y/N), `smooth' the smooth of the spectrum, `mz' the same as 
`f[,1]', `sigmas' the estimates of local variation and `area' the area associated with each peak after the first pass.
\end{Value}
\begin{Author}\relax
Xiaochun Li
\end{Author}
\begin{Examples}
\begin{ExampleCode}
example(bslnoff)
pkobj <- isPeak(bseoff,span=81,sm.span=11,plot=TRUE)

\end{ExampleCode}
\end{Examples}

