Common functions to handle "Dipeak" class results, which store
information about local extrema and their probability.
# S3 method for Dipeak
print(x, ...)
# S3 method for Dipeak
summary(object, ...)
# S3 method for Dipeak
mark(x, hist=NULL, opt=Diopt(), ...)The basic data frame returned from find.peaks includes the columns
posindex in data of local extremum
ismaxTRUE if a local maximum, FALSE if a minimum
valsddata at extremum, standardized by sd(x)
lhtdifference in valsd between maximum and minimum to its left, NA if no minimum or if a minimum
rhtdifference in valsd between maximum and minimum to its right, NA if no minimum or if a minimum
lminIDposition/index of minimum to the left, NA if not a valid maximum
rminIDposition/index of minimum to the right, NA if not a valid maximum
lsuppIDleft index of support, NA if not a valid maximum
rsuppIDright index (incl.) of support, NA if not a valid maximum
The indices are located in the data passed to the detector. Valid maxima have minima on both sides. There will always be two extrema at the first and last point.
Dimodal adds several columns. It shifts all indices to the original
data, compensating for the invalid points skipped during low-pass filtering
or interval spacing. Mapping indices back to the raw data and summarizing
the tests, it adds
xthe location of the peak in the original data
ppeakthe best probability of all tests run or NA if none or if not a maximum with minima to both sides
nacceptnumber of tests passing their acceptance level, 0 if none or ppeak is NA
x can be generated by calling the utility function shiftID.place on
the find.peaks result. Dimodal also adds an attribute "source" with
value "LP" or "Diw" depending on the filter used.
For low-pass testing the results may include
phtthe probability of the feature per the height model,
using the larger of lht and rht
hexcurthe feature height used for the excursion test
pexcurthe probability of the peak using bootstrap sampling of the difference of the low-pass spacing
For interval spacing tests the results may include those based on runs in its signed difference, between the bounding minima
nrunthe number of runs
pnrunthe probability of nrun using the Kaplansky-Riordan test
runlenthe length of the longest run
prunlenthe probability of runlen using a Markov chain model of the entire data sample
runhtthe feature height in the signed difference
prunhtthe probability of the peak with height runht using a permutation test of the runs
hexcurthe feature height in the interval spacing between minima
pexcurthe probability of the peak with height hexcur using bootstrap sampling from the interval spacing of the whole data
The methods return the object, invisibly.
an object of class "Dipeak"
an object of class "Dipeak"
the histogram being marked or NULL for a low-pass or interval spacing graph
local version of options to guide plots
extra arguments, ignored for all methods
A "Dipeak" object is a data frame that describes local extrema, including
their position in the low-pass or interval spacing and equivalent raw value,
their height and width, and any tests that have run to judge the significance
of the feature. The basic information comes from the find.peaks
detector, and the Dimodal analysis adds the feature analysis. The
class inherits from "data.frame".
The print method shows the position (index) and raw value of each maximum,
the minimum to either side, and if different the support. It then has
two tables with the statistic (test value) and probability for any tests
that have been run, as well as the acceptance levels. These come from the
options "alpha.ht" for the model test, "alpha.pkexcur.lp" and
"alpha.pkexcur.diw" for the excursion test, and "alpha.nrun" and
"alpha.runlen" and "alpha.runht" for the runs tests. If the
option "mark.alpha" is TRUE then probabilities at or below the
acceptance level are underlined. Set the option FALSE if your terminal
does not support ANSI escape codes, or see the crayon package for the
extensive tests needed to determine this automatically. These options are
set at the global level and cannot be overridden for a single call to print.
The pass column after the overall peak probability will contain the number
of accepted/passing tests, if any. Raw values and statistics are printed
with option "digits" significant digits. If the option is set to
zero then the standard options()$digits is used.
The summary method lists the position and raw value of each maximum, the
overall probability or best result from all tests, and a list of the tests
that pass per the Diopt acceptance levels.
Peaks and minima are marked in a spacing graph by vertical lines. Maxima
are drawn with dashes and are made thick if the peak passes any test.
Minima are drawn with dotted lines. The marks are colored per the option
"colID.peak" of the current palette. Histogram annotations include
only lines for peaks, drawn thick if significant. They run from the quantile
axis on the right to the distribution function curve, then down to the data
value. Marking the histogram assumes that Dimodal has added the x
column with the peak's original data value and has shifted positions.
select.peaks is a utility function that extracts only those rows with
valid peaks, which have a minima to each side.
find.peaks,
Dimodal,
Diopt,
data.frame,
select.peaks
shiftID.place
## We override the analysis option to avoid changepoints,
## which may not be available.
m <- Dimodal(faithful$eruptions, Diopt.local(analysis=c('diw','lp'), diw.window=16))
summary(m$lp.peaks)
m$diw.peaks
Run the code above in your browser using DataLab