| OpenMS 2.5.0

Functions
Statistics functions
Math

Various statistical functions. More...

## Functions

template<typename IteratorType >
static void | checkIteratorsNotNULL (IteratorType begin, IteratorType end)
| Helper function checking if two iterators are not equal. More...
template<typename IteratorType >
static void | checkIteratorsEqual (IteratorType begin, IteratorType end)
| Helper function checking if two iterators are equal. More...
template<typename IteratorType1 , typename IteratorType2 >
static void | checkIteratorsAreValid (IteratorType1 begin_b, IteratorType1 end_b, IteratorType2 begin_a, IteratorType2 end_a)
| Helper function checking if an iterator and a co-iterator both have a next element. More...
template<typename IteratorType >
static double | sum (IteratorType begin, IteratorType end)
| Calculates the sum of a range of values. More...
template<typename IteratorType >
static double | mean (IteratorType begin, IteratorType end)
| Calculates the mean of a range of values. More...
template<typename IteratorType >
static double | median (IteratorType begin, IteratorType end, bool sorted=false)
| Calculates the median of a range of values. More...
template<typename IteratorType >
double | MAD (IteratorType begin, IteratorType end, double median_of_numbers)
| median absolute deviation (MAD) More...
template<typename IteratorType >
static double | quantile1st (IteratorType begin, IteratorType end, bool sorted=false)
| Calculates the first quantile of a range of values. More...
template<typename IteratorType >
static double | quantile3rd (IteratorType begin, IteratorType end, bool sorted=false)
| Calculates the third quantile of a range of values. More...
template<typename IteratorType >
static double | variance (IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
| Calculates the variance of a range of values. More...
template<typename IteratorType >
static double | sd (IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
| Calculates the standard deviation of a range of values. More...
template<typename IteratorType >
static double | absdev (IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
| Calculates the absolute deviation of a range of values. More...
template<typename IteratorType1 , typename IteratorType2 >
static double | covariance (IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
| Calculates the covariance of two ranges of values. More...
template<typename IteratorType1 , typename IteratorType2 >
static double | meanSquareError (IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
| Calculates the mean square error for the values in [begin_a, end_a) and [begin_b, end_b) More...
template<typename IteratorType1 , typename IteratorType2 >
static double | classificationRate (IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
| Calculates the classification rate for the values in [begin_a, end_a) and [begin_b, end_b) More...
template<typename IteratorType1 , typename IteratorType2 >
static double | matthewsCorrelationCoefficient (IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
| Calculates the Matthews correlation coefficient for the values in [begin_a, end_a) and [begin_b, end_b) More...
template<typename IteratorType1 , typename IteratorType2 >
static double | pearsonCorrelationCoefficient (IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
| Calculates the Pearson correlation coefficient for the values in [begin_a, end_a) and [begin_b, end_b) More...
template<typename IteratorType1 , typename IteratorType2 >
static double | rankCorrelationCoefficient (IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
| calculates the rank correlation coefficient for the values in [begin_a, end_a) and [begin_b, end_b) More...

## Detailed Description

Various statistical functions.

These functions are defined in OpenMS/MATH/STATISTICS/StatisticFunctions.h .

## Function Documentation

## ◆ absdev()

static double OpenMS::Math::absdev | ( | IteratorType | begin,
|  | IteratorType | end,
|  | double | mean = `std::numeric_limits<double>::max()`
| ) |  |

static

Calculates the absolute deviation of a range of values.

Exceptions

  Exception::InvalidRange | is thrown if the range is empty

References OpenMS::Math::checkIteratorsNotNULL(), OpenMS::Math::mean(), and OpenMS::Math::sum().

## ◆ checkIteratorsAreValid()

static void OpenMS::Math::checkIteratorsAreValid | ( | IteratorType1 | begin_b,
|  | IteratorType1 | end_b,
|  | IteratorType2 | begin_a,
|  | IteratorType2 | end_a
| ) |  |

static

Helper function checking if an iterator and a co-iterator both have a next element.

Exceptions

  Exception::InvalidRange | is thrown if the iterator do not end simultaneously

Referenced by OpenMS::Math::classificationRate(), OpenMS::Math::covariance(), OpenMS::Math::matthewsCorrelationCoefficient(), OpenMS::Math::meanSquareError(), OpenMS::Math::pearsonCorrelationCoefficient(), and OpenMS::Math::rankCorrelationCoefficient().

## ◆ checkIteratorsEqual()

static void OpenMS::Math::checkIteratorsEqual | ( | IteratorType | begin,
|  | IteratorType | end
| ) |  |

static

Helper function checking if two iterators are equal.

Exceptions

  Exception::InvalidRange | is thrown if the iterators are not equal

Referenced by OpenMS::Math::classificationRate(), OpenMS::Math::covariance(), OpenMS::Math::matthewsCorrelationCoefficient(), OpenMS::Math::meanSquareError(), OpenMS::Math::pearsonCorrelationCoefficient(), and OpenMS::Math::rankCorrelationCoefficient().

## ◆ checkIteratorsNotNULL()

static void OpenMS::Math::checkIteratorsNotNULL | ( | IteratorType | begin,
|  | IteratorType | end
| ) |  |

static

Helper function checking if two iterators are not equal.

Exceptions

  Exception::InvalidRange | is thrown if the range is NULL

Referenced by OpenMS::Math::absdev(), OpenMS::Math::classificationRate(), OpenMS::Math::covariance(), OpenMS::Math::matthewsCorrelationCoefficient(), OpenMS::Math::mean(), OpenMS::Math::meanSquareError(), OpenMS::Math::median(), OpenMS::Math::pearsonCorrelationCoefficient(), OpenMS::Math::quantile1st(), OpenMS::Math::quantile3rd(), OpenMS::Math::rankCorrelationCoefficient(), OpenMS::Math::sd(), and OpenMS::Math::variance().

## ◆ classificationRate()

static double OpenMS::Math::classificationRate | ( | IteratorType1 | begin_a,
|  | IteratorType1 | end_a,
|  | IteratorType2 | begin_b,
|  | IteratorType2 | end_b
| ) |  |

static

Calculates the classification rate for the values in [begin_a, end_a) and [begin_b, end_b)

Calculates the classification rate for the data given by the two iterator ranges.

Exceptions

  Exception::InvalidRange | is thrown if the iterator ranges are not of the same length or empty.

References OpenMS::Math::checkIteratorsAreValid(), OpenMS::Math::checkIteratorsEqual(), and OpenMS::Math::checkIteratorsNotNULL().

## ◆ covariance()

static double OpenMS::Math::covariance | ( | IteratorType1 | begin_a,
|  | IteratorType1 | end_a,
|  | IteratorType2 | begin_b,
|  | IteratorType2 | end_b
| ) |  |

static

Calculates the covariance of two ranges of values.

Note that the two ranges must be of equal size.

Exceptions

  Exception::InvalidRange | is thrown if the range is empty

References OpenMS::Math::checkIteratorsAreValid(), OpenMS::Math::checkIteratorsEqual(), OpenMS::Math::checkIteratorsNotNULL(), OpenMS::Math::mean(), and OpenMS::Math::sum().

## ◆ MAD()

double OpenMS::Math::MAD | ( | IteratorType | begin,
|  | IteratorType | end,
|  | double | median_of_numbers
| ) |  |

median absolute deviation (MAD)

Computes the MAD, defined as

MAD = median( | x_i - median(x) | ) for a vector x with indices i in [1,n].

Sortedness of the input is not required (nor does it provide a speedup). For efficiency, you must provide the median separately, in order to avoid potentially duplicate efforts (usually one computes the median anyway externally).

Parameters

  begin | Start of range
  end | End of range (past-the-end iterator)
  median_of_numbers | The precomputed median of range `begin` - `end`.

Returns
  the MAD

References OpenMS::Math::median().

Referenced by UTILProteomicsLFQ::centroidAndCorrectPrecursors_().

## ◆ matthewsCorrelationCoefficient()

static double OpenMS::Math::matthewsCorrelationCoefficient | ( | IteratorType1 | begin_a,
|  | IteratorType1 | end_a,
|  | IteratorType2 | begin_b,
|  | IteratorType2 | end_b
| ) |  |

static

Calculates the Matthews correlation coefficient for the values in [begin_a, end_a) and [begin_b, end_b)

Calculates the Matthews correlation coefficient for the data given by the two iterator ranges. The values in [begin_a, end_a) have to be the predicted labels and the values in [begin_b, end_b) have to be the real labels.

Exceptions

  Exception::InvalidRange | is thrown if the iterator ranges are not of the same length or empty.

References OpenMS::Math::checkIteratorsAreValid(), OpenMS::Math::checkIteratorsEqual(), and OpenMS::Math::checkIteratorsNotNULL().

## ◆ mean()

static double OpenMS::Math::mean | ( | IteratorType | begin,
|  | IteratorType | end
| ) |  |

static

Calculates the mean of a range of values.

Exceptions

  Exception::InvalidRange | is thrown if the range is NULL

References OpenMS::Math::checkIteratorsNotNULL(), and OpenMS::Math::sum().

Referenced by OpenMS::Math::absdev(), MetaProSIPDecomposition::calculateDecompositionWeightsIsotopicPatterns(), OpenMS::Math::covariance(), IsotopeWaveletTransform< PeakType >::getSdIntens_(), OpenMS::makePeakPositionUnique(), BasicStatistics< CoordinateType >::normalDensity_sqrt2pi(), MRMTransitionGroupPicker::recalculatePeakBorders_(), OpenMS::Math::sd(), BasicStatistics< CoordinateType >::setMean(), SummaryStatistics< T >::SummaryStatistics(), and OpenMS::Math::variance().

## ◆ meanSquareError()

static double OpenMS::Math::meanSquareError | ( | IteratorType1 | begin_a,
|  | IteratorType1 | end_a,
|  | IteratorType2 | begin_b,
|  | IteratorType2 | end_b
| ) |  |

static

Calculates the mean square error for the values in [begin_a, end_a) and [begin_b, end_b)

Calculates the mean square error for the data given by the two iterator ranges.

Exceptions

  Exception::InvalidRange | is thrown if the iterator ranges are not of the same length or empty.

References OpenMS::Math::checkIteratorsAreValid(), OpenMS::Math::checkIteratorsEqual(), and OpenMS::Math::checkIteratorsNotNULL().

## ◆ median()

static double OpenMS::Math::median | ( | IteratorType | begin,
|  | IteratorType | end,
|  | bool | sorted = `false`
| ) |  |

static

Calculates the median of a range of values.

Parameters

  begin | Start of range
  end | End of range (past-the-end iterator)
  sorted | Is the range already sorted? If not, it will be sorted.

Returns
  Median (as floating point, since we need to support average of middle values)

Exceptions

  Exception::InvalidRange | is thrown if the range is NULL

References OpenMS::Math::checkIteratorsNotNULL().

Referenced by UTILProteomicsLFQ::centroidAndCorrectPrecursors_(), MetaProSIPReporting::createCSVReport(), UTILProteomicsLFQ::estimateMedianChromatographicFWHM_(), NucleicAcidSearchEngine::generateLFQInput_(), OpenMS::Math::MAD(), OpenMS::makePeakPositionUnique(), OpenMS::Math::quantile1st(), OpenMS::Math::quantile3rd(), and SummaryStatistics< T >::SummaryStatistics().

## ◆ pearsonCorrelationCoefficient()

static double OpenMS::Math::pearsonCorrelationCoefficient | ( | IteratorType1 | begin_a,
|  | IteratorType1 | end_a,
|  | IteratorType2 | begin_b,
|  | IteratorType2 | end_b
| ) |  |

static

Calculates the Pearson correlation coefficient for the values in [begin_a, end_a) and [begin_b, end_b)

Calculates the linear correlation coefficient for the data given by the two iterator ranges.

If one of the ranges contains only the same values 'nan' is returned.

Exceptions

  Exception::InvalidRange | is thrown if the iterator ranges are not of the same length or empty.

References OpenMS::Math::checkIteratorsAreValid(), OpenMS::Math::checkIteratorsEqual(), and OpenMS::Math::checkIteratorsNotNULL().

Referenced by MetaProSIPXICExtraction::correlateXICsToMono(), and MaxLikeliFitter1D::fitOffset_().

## ◆ quantile1st()

static double OpenMS::Math::quantile1st | ( | IteratorType | begin,
|  | IteratorType | end,
|  | bool | sorted = `false`
| ) |  |

static

Calculates the first quantile of a range of values.

The range is divided into half and the median for the first half is returned.

Parameters

  begin | Start of range
  end | End of range (past-the-end iterator)
  sorted | Is the range already sorted? If not, it will be sorted.

Exceptions

  Exception::InvalidRange | is thrown if the range is NULL

References OpenMS::Math::checkIteratorsNotNULL(), and OpenMS::Math::median().

Referenced by SummaryStatistics< T >::SummaryStatistics().

## ◆ quantile3rd()

static double OpenMS::Math::quantile3rd | ( | IteratorType | begin,
|  | IteratorType | end,
|  | bool | sorted = `false`
| ) |  |

static

Calculates the third quantile of a range of values.

The range is divided into half and the median for the second half is returned.

Parameters

  begin | Start of range
  end | End of range (past-the-end iterator)
  sorted | Is the range already sorted? If not, it will be sorted.

Exceptions

  Exception::InvalidRange | is thrown if the range is NULL

References OpenMS::Math::checkIteratorsNotNULL(), and OpenMS::Math::median().

Referenced by SummaryStatistics< T >::SummaryStatistics().

## ◆ rankCorrelationCoefficient()

static double OpenMS::Math::rankCorrelationCoefficient | ( | IteratorType1 | begin_a,
|  | IteratorType1 | end_a,
|  | IteratorType2 | begin_b,
|  | IteratorType2 | end_b
| ) |  |

static

calculates the rank correlation coefficient for the values in [begin_a, end_a) and [begin_b, end_b)

Calculates the rank correlation coefficient for the data given by the two iterator ranges.

If one of the ranges contains only the same values 'nan' is returned.

Exceptions

  Exception::InvalidRange | is thrown if the iterator ranges are not of the same length or empty.

References OpenMS::Math::checkIteratorsAreValid(), OpenMS::Math::checkIteratorsEqual(), OpenMS::Math::checkIteratorsNotNULL(), and OpenMS::Math::computeRank().

## ◆ sd()

static double OpenMS::Math::sd | ( | IteratorType | begin,
|  | IteratorType | end,
|  | double | mean = `std::numeric_limits<double>::max()`
| ) |  |

static

Calculates the standard deviation of a range of values.

The `mean` can be provided explicitly to save computation time. If left at default, it will be computed internally.

Exceptions

  Exception::InvalidRange | is thrown if the range is empty

References OpenMS::Math::checkIteratorsNotNULL(), OpenMS::Math::mean(), and OpenMS::Math::variance().

## ◆ sum()

static double OpenMS::Math::sum | ( | IteratorType | begin,
|  | IteratorType | end
| ) |  |

static

Calculates the sum of a range of values.

Referenced by OpenMS::Math::absdev(), ComplementFilter::apply(), SpectraMerger::average(), OpenMS::Math::covariance(), OpenSwath::dotProd(), MetaProSIPClustering::getRIAClusterCenter(), OpenMS::makePeakPositionUnique(), OpenSwath::manhattanDist(), OpenMS::Math::mean(), BasicStatistics< CoordinateType >::normalApproximationHelper_(), BasicStatistics< CoordinateType >::setSum(), and OpenMS::Math::variance().

## ◆ variance()

static double OpenMS::Math::variance | ( | IteratorType | begin,
|  | IteratorType | end,
|  | double | mean = `std::numeric_limits<double>::max()`
| ) |  |

static

Calculates the variance of a range of values.

The `mean` can be provided explicitly to save computation time. If left at default, it will be computed internally.

Exceptions

  Exception::InvalidRange | is thrown if the range is empty

References OpenMS::Math::checkIteratorsNotNULL(), OpenMS::Math::mean(), and OpenMS::Math::sum().

Referenced by BasicStatistics< CoordinateType >::normalDensity_sqrt2pi(), OpenMS::Math::sd(), BasicStatistics< CoordinateType >::setVariance(), and SummaryStatistics< T >::SummaryStatistics().