Modality Analyzer
How many modes the data appears to have, and whether that appearance survives smoothing.
Why this is here at all. An analyst reaching for a mixture has usually looked at a plot and counted humps. That count is the input the fitting workflow is built around, so it is worth knowing whether it is a property of the data or of the bin width that happened to be chosen.
Modes bound the component count from below, and only from below. A two-component mixture of equal-variance normals is unimodal whenever its means differ by less than twice the standard deviation, so seeing one hump does not mean one component. Seeing three humps does mean at least three components. The test here is therefore evidence about a floor rather than about the count itself.
A class rather than an object because the operations share expensive state: the binning, the mode trace, the bisection and every bootstrap replicate reuse the same sorted array and bin grid. This follows PDFModeler, which caches its histogram for the same reason and splits instance members from stateless functions over supplied data in the same way.
The stream is a property of the analyzer, not an argument to its methods. That is the library's convention — Bootstrap, DPopulation and RVariable all acquire their stream once at construction and expose RNStreamControlIfc so that repositioning is something the caller asks for explicitly. Taking a stream number per call, as this class first did, cannot be made reproducible: an explicit number hands every caller the same stream object at whatever position the last caller left it, and a stream number of zero means the next stream, so consecutive calls draw from different streams. Both were measured; five identical calls at an explicit number returned five different p-values.
Parameters
the observations, which need not be sorted
how many cells the data is binned into
the random number stream number, defaults to 0, which means the next stream
the provider of random number streams, defaults to the library's shared provider. Supply a provider of its own to an analyzer that must be independent of everything else drawing from the shared one — which is what concurrent callers need, since a stream is not safe to share between threads.
Constructors
Properties
If true, the stream will automatically participate in having its stream advanced to the next sub-stream via stream managers
Tells the stream to start producing antithetic variates
If true, the stream will automatically participate in having its stream reset to its start stream via stream managers
The observations in non-decreasing order.
The number of the stream the resampling draws from. The smoothing noise draws from the next one.
Functions
Positions the RNG at the beginning of its next substream
Everything the pre-fit description needs about modality, in one object.
The smallest bandwidth at which the estimate has at most this many modes.
A geometric sweep of bandwidths spanning the range over which the mode count changes.
The kernel density estimate at a bandwidth, over the analyzer's grid.
The grid the density is evaluated on.
How many modes the estimate has at a bandwidth.
Where the modes of the estimate sit at a bandwidth.
Modes against bandwidth over a sweep, which is the display an analyst reads to see whether an apparent structure survives smoothing.
The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.
Resets the position of the RNG at the start of the current substream
Silverman's test of "at most this many modes", by the smoothed bootstrap.