standard deviation (Descriptive Statistics)


Import

#include <archr/stats/standard_deviation.h>
#include <archr/stats/standard_deviation.hpp>
import archr.stats
atomsLoads('archr')

Synopsis

 float archr_stats_stdevp_f32(const float *first, size_t nbelem);
(1)
 double archr_stats_stdevp_f64(const double *first, size_t nbelem);
(2)
 float archr_stats_stdevp2_f32(const float *first, size_t nbelem, float m);
(3)
 double archr_stats_stdevp2_f64(const double *first, size_t nbelem, double m);
(4)
 float archr_stats_stdev_f32(const float *first, size_t nbelem);
(5)
 double archr_stats_stdev_f64(const double *first, size_t nbelem);
(6)
 float archr_stats_stdev2_f32(const float *first, size_t nbelem, float m);
(7)
 double archr_stats_stdev2_f64(const double *first, size_t nbelem, double m);
(8)
 float archr_stats_standard_deviation_f32(const float *first, size_t nbelem);
(9)
 double archr_stats_standard_deviation_f64(const double *first, size_t nbelem);
(10)
 float archr_stats_standard_deviation2_f32(const float *first, size_t nbelem, float m);
(11)
 double archr_stats_standard_deviation2_f64(const double *first, size_t nbelem, double m);
(12)
 float stdevp(const float *first, size_t nbelem);
(1)
 double stdevp(const double *first, size_t nbelem);
(2)
 float stdevp(const float *first, size_t nbelem, float m);
(3)
 double stdevp(const double *first, size_t nbelem, double m);
(4)
 float stdevp(const float *first, const float *last);
(5)
 double stdevp(const double *first, const double *last);
(6)
 float stdevp(const float *first, const float *last, float m);
(7)
 double stdevp(const double *first, const double *last, double m);
(8)
template <typename Range> typename Range::value_type stdevp(const Range& data);
(9)
template <typename Range> typename Range::value_type stdevp(const Range& data, float m);
(10)
template <typename Range> typename Range::value_type stdevp(const Range& data, double m);
(11)
 float stdev(const float *first, size_t nbelem);
(12)
 double stdev(const double *first, size_t nbelem);
(13)
 float stdev(const float *first, size_t nbelem, float m);
(14)
 double stdev(const double *first, size_t nbelem, double m);
(15)
 float stdev(const float *first, const float *last);
(16)
 double stdev(const double *first, const double *last);
(17)
 float stdev(const float *first, const float *last, float m);
(18)
 double stdev(const double *first, const double *last, double m);
(19)
template <typename Range> typename Range::value_type stdev(const Range& data);
(20)
template <typename Range> typename Range::value_type stdev(const Range& data, float m);
(21)
template <typename Range> typename Range::value_type stdev(const Range& data, double m);
(22)
 float standard_deviation(const float *first, size_t nbelem);
(23)
 double standard_deviation(const double *first, size_t nbelem);
(24)
 float standard_deviation(const float *first, size_t nbelem, float m);
(25)
 double standard_deviation(const double *first, size_t nbelem, double m);
(26)
 float standard_deviation(const float *first, const float *last);
(27)
 double standard_deviation(const double *first, const double *last);
(28)
 float standard_deviation(const float *first, const float *last, float m);
(29)
 double standard_deviation(const double *first, const double *last, double m);
(30)
template <typename Range> typename Range::value_type standard_deviation(const Range& data);
(31)
template <typename Range> typename Range::value_type standard_deviation(const Range& data, float m);
(32)
template <typename Range> typename Range::value_type standard_deviation(const Range& data, double m);
(33)
subroutine archr_stats_standard_deviation_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(1)
subroutine archr_stats_standard_deviation_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(2)
subroutine archr_stats_standard_deviation2_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem, real(4) :: m)
(3)
subroutine archr_stats_standard_deviation2_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem, real(8) :: m)
(4)
subroutine archr_stats_stdevp_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(5)
subroutine archr_stats_stdevp_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(6)
subroutine archr_stats_stdevp2_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem, real(4) :: m)
(7)
subroutine archr_stats_stdevp2_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem, real(8) :: m)
(8)
subroutine archr_stats_stdev_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(9)
subroutine archr_stats_stdev_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(10)
subroutine archr_stats_stdev2_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem, real(4) :: m)
(11)
subroutine archr_stats_stdev2_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem, real(8) :: m)
(12)
def standard_deviation(first):
    return r
(1)
def standard_deviation(first, m):
    return r
(2)
def stdevp(first):
    return r
(3)
def stdevp(first, m):
    return r
(4)
def stdev(first):
    return r
(5)
def stdev(first, m):
    return r
(6)
function r = archr_stats_stdevp(first)
(1)
function r = archr_stats_stdevp(first, m)
(2)
function r = archr_stats_standard_deviation(first)
(3)
function r = archr_stats_standard_deviation(first, m)
(4)
function r = archr_stats_stdev(first)
(5)
function r = archr_stats_stdev(first, m)
(6)

Description

This function computes the standard deviation of the elements stored in:

Note that the stdevp_* function variants are provided as a convenience alias for migration from spreadsheet or Matlab like code.

Parameters

first

the beginning of the range of elements to process.

last

the end of the range of elements to process.

m

the mean of the range of elements.

nbelem

the number of elements to process.

Return value

The standard deviation of the elements in the given range using the following formula:

$$\sigma(X) = \sqrt{V(X)}$$

with \(V(X)\) being the variance of the given range.

If m is not provided, the mean of the elements range is computed beforehand.

Example

#include <archr/stats/standard_deviation.h>
#include <stdio.h>

int main()
{
  float v[] = {1,-2,3,-4,5,-6};

  printf("standard_deviation(1,-2,3,-4,5,-6) = %f\n", archr_stats_standard_deviation_f32(&v[0],6) );

  puts("");

  printf("standard_deviation(1,-2,3,-4,5,-6) with m = -0.5 = %f\n", archr_stats_standard_deviation2_f32(&v[0], 6, -0.5));

  return 0;
}

Possible Output

standard_deviation(1,-2,3,-4,5,-6) = 3.862210
standard_deviation(1,-2,3)      = 2.054805

standard_deviation(1,-2,3,-4,5,-6) with m = -0.5 = 3.862210
standard_deviation(1,-2,3)         with m =  2/3 = 2.054805
#include <archr/stats/standard_deviation.hpp>
#include <iostream>
#include <vector>

int main()
{
  std::vector<float> v{1,-2,3,-4,5,-6};

  std::cout << "standard_deviation(1,-2,3,-4,5,-6) = " << archr::stats::standard_deviation(v) << "\n";
  std::cout << "standard_deviation(1,-2,3,-4,5)    = " << archr::stats::standard_deviation(v.data(), 5) << "\n";
  std::cout << "standard_deviation(1,-2,3)         = " << archr::stats::standard_deviation(v.data(), v.data() + 3) << "\n";
  std::cout << "\n";

  std::cout << "standard_deviation(1,-2,3,-4,5,-6) with m = -0.5 = " << archr::stats::standard_deviation(v,-0.5) << "\n";
  std::cout << "standard_deviation(1,-2,3,-4,5)    with m =  0.6 = " << archr::stats::standard_deviation(v.data(), 5, 0.6) << "\n";
  std::cout << "standard_deviation(1,-2,3)         with m =  2/3 = " << archr::stats::standard_deviation(v.data(), v.data() + 3, 2./3) << "\n";

  return 0;
}

Possible Output

standard_deviation(1,-2,3,-4,5,-6) = 3.86221
standard_deviation(1,-2,3,-4,5)    = 3.2619
standard_deviation(1,-2,3)         = 2.0548

standard_deviation(1,-2,3,-4,5,-6) with m = -0.5 = 3.86221
standard_deviation(1,-2,3,-4,5)    with m =  0.6 = 3.2619
standard_deviation(1,-2,3)         with m =  2/3 = 2.0548

Possible Output