statcpp
C++17 Header-Only Statistics Library
Loading...
Searching...
No Matches
Namespaces | Functions
dispersion_spread.hpp File Reference

Dispersion and variance calculation functions. More...

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <functional>
#include <iterator>
#include <stdexcept>
#include <type_traits>
#include <vector>
#include "statcpp/basic_statistics.hpp"
#include "statcpp/order_statistics.hpp"
Include dependency graph for dispersion_spread.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  statcpp
 

Functions

template<typename Iterator >
double statcpp::range (Iterator first, Iterator last)
 Range (maximum - minimum)
 
template<typename Iterator , typename Projection >
double statcpp::range (Iterator first, Iterator last, Projection proj)
 Range of projected values using a lambda expression.
 
template<typename Iterator >
double statcpp::var (Iterator first, Iterator last, std::size_t ddof=0)
 Variance (ddof = Delta Degrees of Freedom)
 
template<typename Iterator >
double statcpp::var (Iterator first, Iterator last, double precomputed_mean, std::size_t ddof)
 Variance using precomputed mean (with ddof)
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::var (Iterator first, Iterator last, Projection proj, std::size_t ddof=0)
 Variance of projected values using a lambda expression (with ddof)
 
template<typename Iterator , typename Projection >
double statcpp::var (Iterator first, Iterator last, Projection proj, double precomputed_mean, std::size_t ddof)
 Variance of projected values using precomputed mean (with ddof)
 
template<typename Iterator >
double statcpp::population_variance (Iterator first, Iterator last)
 Population variance.
 
template<typename Iterator >
double statcpp::population_variance (Iterator first, Iterator last, double precomputed_mean)
 Population variance using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::population_variance (Iterator first, Iterator last, Projection proj)
 Population variance of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::population_variance (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Population variance of projected values using precomputed mean.
 
template<typename Iterator >
double statcpp::sample_variance (Iterator first, Iterator last)
 Sample variance (unbiased variance)
 
template<typename Iterator >
double statcpp::sample_variance (Iterator first, Iterator last, double precomputed_mean)
 Sample variance using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::sample_variance (Iterator first, Iterator last, Projection proj)
 Sample variance of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::sample_variance (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Sample variance of projected values using precomputed mean.
 
template<typename Iterator >
double statcpp::variance (Iterator first, Iterator last)
 Variance (alias for sample_variance)
 
template<typename Iterator >
double statcpp::variance (Iterator first, Iterator last, double precomputed_mean)
 Variance using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::variance (Iterator first, Iterator last, Projection proj)
 Variance of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::variance (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Variance of projected values using precomputed mean.
 
template<typename Iterator >
double statcpp::stdev (Iterator first, Iterator last, std::size_t ddof=0)
 Standard deviation (ddof = Delta Degrees of Freedom)
 
template<typename Iterator >
double statcpp::stdev (Iterator first, Iterator last, double precomputed_mean, std::size_t ddof)
 Standard deviation using precomputed mean (with ddof)
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::stdev (Iterator first, Iterator last, Projection proj, std::size_t ddof=0)
 Standard deviation of projected values using a lambda expression (with ddof)
 
template<typename Iterator , typename Projection >
double statcpp::stdev (Iterator first, Iterator last, Projection proj, double precomputed_mean, std::size_t ddof)
 Standard deviation of projected values using precomputed mean (with ddof)
 
template<typename Iterator >
double statcpp::population_stddev (Iterator first, Iterator last)
 Population standard deviation.
 
template<typename Iterator >
double statcpp::population_stddev (Iterator first, Iterator last, double precomputed_mean)
 Population standard deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::population_stddev (Iterator first, Iterator last, Projection proj)
 Population standard deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::population_stddev (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Population standard deviation of projected values using precomputed mean.
 
template<typename Iterator >
double statcpp::sample_stddev (Iterator first, Iterator last)
 Sample standard deviation.
 
template<typename Iterator >
double statcpp::sample_stddev (Iterator first, Iterator last, double precomputed_mean)
 Sample standard deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::sample_stddev (Iterator first, Iterator last, Projection proj)
 Sample standard deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::sample_stddev (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Sample standard deviation of projected values using precomputed mean.
 
template<typename Iterator >
double statcpp::stddev (Iterator first, Iterator last)
 Standard deviation (alias for sample_stddev)
 
template<typename Iterator >
double statcpp::stddev (Iterator first, Iterator last, double precomputed_mean)
 Standard deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::stddev (Iterator first, Iterator last, Projection proj)
 Standard deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::stddev (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Standard deviation of projected values using precomputed mean.
 
template<typename Iterator >
double statcpp::coefficient_of_variation (Iterator first, Iterator last)
 Coefficient of variation.
 
template<typename Iterator >
double statcpp::coefficient_of_variation (Iterator first, Iterator last, double precomputed_mean)
 Coefficient of variation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::coefficient_of_variation (Iterator first, Iterator last, Projection proj)
 Coefficient of variation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::coefficient_of_variation (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Coefficient of variation of projected values using precomputed mean.
 
template<typename Iterator >
double statcpp::iqr (Iterator first, Iterator last)
 Interquartile range (accepts a sorted range)
 
template<typename Iterator , typename Projection >
double statcpp::iqr (Iterator first, Iterator last, Projection proj)
 Interquartile range of projected values (projection results must be in sorted order)
 
template<typename Iterator >
double statcpp::mean_absolute_deviation (Iterator first, Iterator last)
 Mean absolute deviation.
 
template<typename Iterator >
double statcpp::mean_absolute_deviation (Iterator first, Iterator last, double precomputed_mean)
 Mean absolute deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::mean_absolute_deviation (Iterator first, Iterator last, Projection proj)
 Mean absolute deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double statcpp::mean_absolute_deviation (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Mean absolute deviation of projected values using precomputed mean.
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_variance (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted variance (reliability weights / analytic weights)
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_variance (Iterator first, Iterator last, WeightIterator weight_first)
 Weighted variance (reliability weights / analytic weights)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_variance (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted variance (projection version)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_variance (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 Weighted variance (projection version)
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted standard deviation.
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first)
 Weighted standard deviation.
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted standard deviation (projection version)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 Weighted standard deviation (projection version)
 
template<typename Iterator >
double statcpp::geometric_stddev (Iterator first, Iterator last)
 Geometric standard deviation.
 
template<typename Iterator , typename Projection >
double statcpp::geometric_stddev (Iterator first, Iterator last, Projection proj)
 Geometric standard deviation (projection version)
 

Detailed Description

Dispersion and variance calculation functions.

Provides functions for measuring data spread, including variance, standard deviation, range, and interquartile range. Uses iterator-based interface compatible with various containers.

Note
Numerical stability: Variance and standard deviation functions use the two-pass algorithm (first pass computes the mean, second pass computes the sum of squared deviations from the mean). This is numerically stable for typical datasets. For extreme cases where all values are very large with tiny relative differences (e.g., values near 1e15 differing by 1e-2), precision may be limited by the ~15 significant digits of IEEE 754 double-precision arithmetic. This limitation is inherent to floating-point representation and applies to all algorithms including Welford's method. R uses the same two-pass approach.

Definition in file dispersion_spread.hpp.