Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

stddev Class Reference

Calculate the unbiased standard deviation. More...

#include <stddev.h>

List of all members.

Public Methods

 stddev ()
 ~stddev ()
double mean ()
double sd (const double *v, const size_t N)
 calculate the standard deviation of N values in v. More...

double sd (const double *v, const size_t N, const double mean)
 calculate the standard deviation, given the mean. More...


Private Methods

 stddev (const stddev &rhs)
double calc_mean_ (const double *v, const size_t N)
 Calculate the arithmetic mean (a.k.a. More...


Private Attributes

double mean_


Detailed Description

Calculate the unbiased standard deviation.

Copyright and Use

You may use this source code without limitation and without fee as long as you include:

This software was written and is copyrighted by Ian Kaplan, Bear Products International, www.bearcave.com, 2001.

This software is provided "as is", without any warranty or claim as to its usefulness. Anyone who uses this source code uses it at their own risk. Nor is any support provided by Ian Kaplan and Bear Products International.

Please send any bug fixes or suggested source changes to:

     iank@bearcave.com

Definition at line 35 of file stddev.h.


Constructor & Destructor Documentation

stddev::stddev ( const stddev & rhs ) [private]
 

stddev::stddev ( ) [inline]
 

Definition at line 43 of file stddev.h.

00043 { mean_ = 0;}

stddev::~stddev ( ) [inline]
 

Definition at line 44 of file stddev.h.

00044 {}


Member Function Documentation

double stddev::calc_mean_ ( const double * v,
const size_t N ) [private]
 

Calculate the arithmetic mean (a.k.a.

average)

Definition at line 10 of file stddev.cpp.

Referenced by sd().

00011 {
00012   double mean = 0.0;
00013   double sum = 0.0;
00014 
00015   for (size_t i = 0; i < N; i++) {
00016     sum = sum + v[i];
00017   }
00018   mean = sum / static_cast<double>(N);
00019   return mean;
00020 } // calc_mean_

double stddev::mean ( ) [inline]
 

Definition at line 46 of file stddev.h.

Referenced by main().

00046 { return mean_; }

double stddev::sd ( const double * v,
const size_t N,
const double mean )
 

calculate the standard deviation, given the mean.

Definition at line 26 of file stddev.cpp.

00029 {
00030   double stdDev = 0.0;
00031   mean_ = mean;
00032 
00033   // calculate the standard deviation sum
00034   double stdDevSum = 0;
00035   double x;
00036   for (size_t i = 0; i < N; i++) {
00037     x = v[i] - mean_;
00038     stdDevSum = stdDevSum + (x * x);
00039   }
00040   double variance = stdDevSum / static_cast<double>(N-1);
00041   stdDev = sqrt( variance );  
00042   return stdDev;
00043 } // sd

double stddev::sd ( const double * v,
const size_t N )
 

calculate the standard deviation of N values in v.

This is a so called "unbiased" estimate of the standard deviation.

Definition at line 50 of file stddev.cpp.

Referenced by main(), and pdf::pdf_stddev().

00051 {
00052   double stdDev = 0.0;
00053   if (v != 0) {
00054     double mean = calc_mean_(v, N);
00055     stdDev = sd( v, N, mean );
00056   }
00057   return stdDev;
00058 } // sd


Member Data Documentation

double stddev::mean_ [private]
 

Definition at line 40 of file stddev.h.


The documentation for this class was generated from the following files:
Generated at Wed May 21 21:19:27 2003 for Basic Statistics Functions by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001