- publishing free software manuals
 GNU Scientific Library Reference Manual - Third Edition (v1.12) by M. Galassi, J. Davies, J. Theiler, B. Gough, G. Jungman, P. Alken, M. Booth, F. RossiPaperback (6"x9"), 592 pages, 60 figuresISBN 0954612078RRP £24.95 (\$39.95)

20.1 Mean, Standard Deviation and Variance

Function: double gsl_stats_mean (const double data[], size_t stride, size_t n)
This function returns the arithmetic mean of data, a dataset of length n with stride stride. The arithmetic mean, or sample mean, is denoted by \Hat\mu and defined as,
\Hat\mu = (1/N) \sum x_i


where x_i are the elements of the dataset data. For samples drawn from a gaussian distribution the variance of \Hat\mu is \sigma^2 / N.

Function: double gsl_stats_variance (const double data[], size_t stride, size_t n)
This function returns the estimated, or sample, variance of data, a dataset of length n with stride stride. The estimated variance is denoted by \Hat\sigma^2 and is defined by,
\Hat\sigma^2 = (1/(N-1)) \sum (x_i - \Hat\mu)^2


where x_i are the elements of the dataset data. Note that the normalization factor of 1/(N-1) results from the derivation of \Hat\sigma^2 as an unbiased estimator of the population variance \sigma^2. For samples drawn from a gaussian distribution the variance of \Hat\sigma^2 itself is 2 \sigma^4 / N.

This function computes the mean via a call to gsl_stats_mean. If you have already computed the mean then you can pass it directly to gsl_stats_variance_m.

Function: double gsl_stats_variance_m (const double data[], size_t stride, size_t n, double mean)
This function returns the sample variance of data relative to the given value of mean. The function is computed with \Hat\mu replaced by the value of mean that you supply,
\Hat\sigma^2 = (1/(N-1)) \sum (x_i - mean)^2

Function: double gsl_stats_sd (const double data[], size_t stride, size_t n)
Function: double gsl_stats_sd_m (const double data[], size_t stride, size_t n, double mean)
The standard deviation is defined as the square root of the variance. These functions return the square root of the corresponding variance functions above.
Function: double gsl_stats_tss (const double data[], size_t stride, size_t n)
Function: double gsl_stats_tss_m (const double data[], size_t stride, size_t n, double mean)
These functions return the total sum of squares (TSS) of data about the mean. For gsl_stats_tss_m the user-supplied value of mean is used, and for gsl_stats_tss it is computed using gsl_stats_mean.
TSS =  \sum (x_i - mean)^2

Function: double gsl_stats_variance_with_fixed_mean (const double data[], size_t stride, size_t n, double mean)
This function computes an unbiased estimate of the variance of data when the population mean mean of the underlying distribution is known a priori. In this case the estimator for the variance uses the factor 1/N and the sample mean \Hat\mu is replaced by the known population mean \mu,
\Hat\sigma^2 = (1/N) \sum (x_i - \mu)^2

Function: double gsl_stats_sd_with_fixed_mean (const double data[], size_t stride, size_t n, double mean)
This function calculates the standard deviation of data for a fixed population mean mean. The result is the square root of the corresponding variance function.
 ISBN 0954612078 GNU Scientific Library Reference Manual - Third Edition (v1.12) See the print edition