variance (sampled) (Descriptive Statistics)


Import

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

Synopsis

 float archr_stats_sample_variance_f32(const float *first, size_t nbelem);
(1)
 double archr_stats_sample_variance_f64(const double *first, size_t nbelem);
(2)
 float archr_stats_sample_variance2_f32(const float *first, size_t nbelem, float m);
(3)
 double archr_stats_sample_variance2_f64(const double *first, size_t nbelem, double m);
(4)
 float archr_stats_sample_varp_f32(const float *first, size_t nbelem);
(5)
 double archr_stats_sample_varp_f64(const double *first, size_t nbelem);
(6)
 float archr_stats_sample_varp2_f32(const float *first, size_t nbelem, float m);
(7)
 double archr_stats_sample_varp2_f64(const double *first, size_t nbelem, double m);
(8)
 float sample_varp(const float *first, size_t nbelem);
(1)
 double sample_varp(const double *first, size_t nbelem);
(2)
 float sample_varp(const float *first, size_t nbelem, float m);
(3)
 double sample_varp(const double *first, size_t nbelem, double m);
(4)
 float sample_varp(const float *first, const float *last);
(5)
 double sample_varp(const double *first, const double *last);
(6)
 float sample_varp(const float *first, const float *last, float m);
(7)
 double sample_varp(const double *first, const double *last, double m);
(8)
template <typename Range> typename Range::value_type sample_varp(const Range& data);
(9)
template <typename Range> typename Range::value_type sample_varp(const Range& data, float m);
(10)
template <typename Range> typename Range::value_type sample_varp(const Range& data, double m);
(11)
 float sample_variance(const float *first, size_t nbelem);
(12)
 double sample_variance(const double *first, size_t nbelem);
(13)
 float sample_variance(const float *first, size_t nbelem, float m);
(14)
 double sample_variance(const double *first, size_t nbelem, double m);
(15)
 float sample_variance(const float *first, const float *last);
(16)
 double sample_variance(const double *first, const double *last);
(17)
 float sample_variance(const float *first, const float *last, float m);
(18)
 double sample_variance(const double *first, const double *last, double m);
(19)
template <typename Range> typename Range::value_type sample_variance(const Range& data);
(20)
template <typename Range> typename Range::value_type sample_variance(const Range& data, float m);
(21)
template <typename Range> typename Range::value_type sample_variance(const Range& data, double m);
(22)
subroutine archr_stats_sample_varp_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(1)
subroutine archr_stats_sample_varp_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(2)
subroutine archr_stats_sample_varp2_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem, real(4) :: m)
(3)
subroutine archr_stats_sample_varp2_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem, real(8) :: m)
(4)
subroutine archr_stats_sample_variance_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(5)
subroutine archr_stats_sample_variance_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(6)
subroutine archr_stats_sample_variance2_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem, real(4) :: m)
(7)
subroutine archr_stats_sample_variance2_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem, real(8) :: m)
(8)
def sample_varp(first):
    return r
(1)
def sample_varp(first, m):
    return r
(2)
def sample_variance(first):
    return r
(3)
def sample_variance(first, m):
    return r
(4)
function r = archr_stats_sample_variance(first)
(1)
function r = archr_stats_sample_variance(first, m)
(2)
function r = archr_stats_sample_varp(first)
(3)
function r = archr_stats_sample_varp(first, m)
(4)

Description

This function computes the bias-corrected variance (or sample variance) of the elements stored in:

Note that the var_* 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.

nbelem

the number of elements to process.

m

the mean of the range of elements.

Return value

The bias-corrected variance of the elements in the given range using the following formula:

$$\textrm{V(X,n)} = \frac{1}{n-1}\sum_{i=1}^{n} (X[i] - m)^{2}$$

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

Example

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

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

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

  puts("");

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

  return 0;
}

Possible Output

sample_standard_deviation(1,-2,3,-4,5,-6) = 4.230839
sample_standard_deviation(1,-2,3)      = 2.516612

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

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

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

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

  return 0;
}

Possible Output

sample_standard_deviation(1,-2,3,-4,5,-6) = 4.23084
sample_standard_deviation(1,-2,3,-4,5)    = 3.64692
sample_standard_deviation(1,-2,3)         = 2.51661

sample_standard_deviation(1,-2,3,-4,5,-6) with m = -0.5 = 4.23084
sample_standard_deviation(1,-2,3,-4,5)    with m =  0.6 = 3.64692
sample_standard_deviation(1,-2,3)         with m =  2/3 = 2.51661

Possible Output