diff --git a/source/tools/stats.h b/source/tools/stats.h index b09a4be575..e865142fd5 100644 --- a/source/tools/stats.h +++ b/source/tools/stats.h @@ -111,6 +111,15 @@ namespace emp { return sqrt(Variance(elements)); } + /// Calculate the standard error of the values in a container + /// If values are pointers, they will be automatically de-referenced + /// Values must be numeric. + template + emp::sfinae_decoy + StandardError(C & elements) { + return StandardDeviation(elements) / sqrt(elements.size()); + } + /// Count the number of unique elements in a container template typename std::enable_if::value, int>::type diff --git a/tests/tools/stats.cc b/tests/tools/stats.cc index d86d3a6fec..9ea1985565 100644 --- a/tests/tools/stats.cc +++ b/tests/tools/stats.cc @@ -33,6 +33,10 @@ TEST_CASE("Test stats", "[tools]") { REQUIRE(emp::StandardDeviation(vec2) == Approx(0.5).epsilon(0.001)); REQUIRE(emp::StandardDeviation(deque1) == Approx(1.0488).epsilon(0.001)); + REQUIRE(emp::StandardError(vec1) == Approx(0.3333).epsilon(0.001)); + REQUIRE(emp::StandardError(vec2) == Approx(0.25).epsilon(0.001)); + REQUIRE(emp::StandardError(deque1) == Approx(0.4281).epsilon(0.001)); + REQUIRE(emp::Sum(vec1) == 10); REQUIRE(emp::Sum(vec2) == 5); REQUIRE(emp::Sum(deque1) == 27);