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

Basic statistical computation functions. More...

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <stdexcept>
#include <type_traits>
#include <vector>
Include dependency graph for basic_statistics.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 >
auto statcpp::sum (Iterator first, Iterator last)
 Sum.
 
template<typename Iterator , typename Projection >
auto statcpp::sum (Iterator first, Iterator last, Projection proj)
 Sum of projected values using a lambda expression.
 
template<typename Iterator >
std::size_t statcpp::count (Iterator first, Iterator last)
 Data count.
 
template<typename Iterator >
double statcpp::mean (Iterator first, Iterator last)
 Arithmetic mean.
 
template<typename Iterator , typename Projection >
double statcpp::mean (Iterator first, Iterator last, Projection proj)
 Arithmetic mean of projected values using a lambda expression.
 
template<typename Iterator >
double statcpp::median (Iterator first, Iterator last)
 Median (accepts a sorted range)
 
template<typename Iterator , typename Projection >
double statcpp::median (Iterator first, Iterator last, Projection proj)
 Median of projected values using a lambda expression (projection results must be in sorted order)
 
template<typename Iterator >
auto statcpp::mode (Iterator first, Iterator last)
 Mode (returns the smallest value when there are multiple modes: guarantees deterministic behavior)
 
template<typename Iterator , typename Projection >
auto statcpp::mode (Iterator first, Iterator last, Projection proj)
 Mode of projected values using a lambda expression.
 
template<typename Iterator >
auto statcpp::modes (Iterator first, Iterator last) -> std::vector< typename std::iterator_traits< Iterator >::value_type >
 Returns all modes (returns a vector sorted in ascending order)
 
template<typename Iterator , typename Projection >
auto statcpp::modes (Iterator first, Iterator last, Projection proj) -> std::vector< std::invoke_result_t< Projection, typename std::iterator_traits< Iterator >::value_type > >
 Returns all modes of projected values using a lambda expression.
 
template<typename Iterator >
double statcpp::geometric_mean (Iterator first, Iterator last)
 Geometric mean.
 
template<typename Iterator , typename Projection >
double statcpp::geometric_mean (Iterator first, Iterator last, Projection proj)
 Geometric mean of projected values using a lambda expression.
 
template<typename Iterator >
double statcpp::harmonic_mean (Iterator first, Iterator last)
 Harmonic mean.
 
template<typename Iterator , typename Projection >
double statcpp::harmonic_mean (Iterator first, Iterator last, Projection proj)
 Harmonic mean of projected values using a lambda expression.
 
template<typename Iterator >
double statcpp::trimmed_mean (Iterator first, Iterator last, double proportion)
 Trimmed mean (accepts a sorted range. proportion: exclusion ratio per side, 0.0 to less than 0.5)
 
template<typename Iterator , typename Projection >
double statcpp::trimmed_mean (Iterator first, Iterator last, double proportion, Projection proj)
 Trimmed mean of projected values using a lambda expression (projection results must be in sorted order)
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted mean.
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_mean (Iterator first, Iterator last, WeightIterator weight_first)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted mean (projection version)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_mean (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 
template<typename T1 , typename T2 >
double statcpp::logarithmic_mean (T1 a, T2 b)
 Logarithmic Mean.
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted harmonic mean (safe range version)
 
template<typename Iterator , typename WeightIterator >
double statcpp::weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first)
 Weighted harmonic mean.
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted harmonic mean (safe range version with projection)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 Weighted harmonic mean (projection version)
 
template<typename Iterator >
std::size_t statcpp::argmin (Iterator first, Iterator last)
 Returns the index of the minimum value.
 
template<typename Iterator , typename Projection >
std::size_t statcpp::argmin (Iterator first, Iterator last, Projection proj)
 Returns the index of the minimum value (projection version)
 
template<typename Iterator >
std::size_t statcpp::argmax (Iterator first, Iterator last)
 Returns the index of the maximum value.
 
template<typename Iterator , typename Projection >
std::size_t statcpp::argmax (Iterator first, Iterator last, Projection proj)
 Returns the index of the maximum value (projection version)
 

Detailed Description

Basic statistical computation functions.

Provides functions to compute basic descriptive statistics such as mean, median, mode, etc. Uses iterator-based interface compatible with various containers.

Note
NaN handling: Functions in statcpp follow IEEE 754 NaN propagation semantics. If input data contains NaN values, the result will typically be NaN. To exclude NaN values before computation, use remove_na() from data_wrangling.hpp to filter input data.

Definition in file basic_statistics.hpp.