Defined in header <scicpp/core.hpp>
Compute the variance. ddof is the delta degrees of freedom
ddof
= 0, class Array
, class Predicate
>var
(const Array &f, Predicate filter)¶Compute the variance of an array using only the values satisfying the filter predicate.
Compute the variance of an array.
Compute the variance of an array, ignoring NaNs.
ddof
= 1, class Array
>tvar
(const Array &f, const std::array<T, 2> &limits, const std::array<bool, 2> &inclusive)¶Compute the variance of an array, ignoring values outside the given limits. Use the optional parameter inclusive to specify whether the limits are included (by default they are included). Note that by default here ddof = 1.
#include <cstdio>
#include <scicpp/core.hpp>
int main()
{
const std::array a{-1., 1., 2., 3.};
// Compute the variance of the array
const auto v = scicpp::stats::var(a);
// Compute the variance of the positive values of the array
const auto v_pos = scicpp::stats::var(a, [](auto x) { return x >= 0; });
printf("v = %f, v_pos = %f\n", v, v_pos);
}