vec_stats.h File Reference

File containing statistics template functions. More...

#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <o2scl/err_hnd.h>
#include <gsl/gsl_ieee_utils.h>
#include <gsl/gsl_sort.h>

Go to the source code of this file.


Detailed Description

Idea for future:
Add chi squared test?
Idea for future:
Consider generalizing to other data types

Definition in file vec_stats.h.


Functions

template<class vec_t >
double vector_mean (size_t n, vec_t &data)
 Compute the mean of the first n elements of a vector.
template<class vec_t >
double vector_variance_fmean (size_t n, vec_t &data, double mean)
 Compute variance with specified mean known in advance.
template<class vec_t >
double vector_variance (size_t n, vec_t &data, double mean)
 Compute the variance with specified mean.
template<class vec_t >
double vector_variance (size_t n, vec_t &data)
 Compute the variance.
template<class vec_t >
double vector_stddev_fmean (size_t n, vec_t &data, double mean)
 Standard deviation with specified mean known in advance.
template<class vec_t >
double vector_stddev (size_t n, vec_t &data)
 Standard deviation with specified mean.
template<class vec_t >
double vector_stddev (size_t n, vec_t &data, double mean)
 Standard deviation with specified mean.
template<class vec_t >
double vector_absdev (size_t n, vec_t &data, double mean)
 Absolute deviation from the specified mean.
template<class vec_t >
double vector_absdev (size_t n, vec_t &data)
 Absolute deviation from the computed mean.
template<class vec_t >
double vector_skew (size_t n, vec_t &data, double mean, double stddev)
 Skewness with specified mean and standard deviation.
template<class vec_t >
double vector_skew (size_t n, vec_t &data)
 Skewness with computed mean and standard deviation.
template<class vec_t >
double vector_kurtosis (size_t n, vec_t &data, double mean, double stddev)
 Kurtosis with specified mean and standard deviation.
template<class vec_t >
double vector_kurtosis (size_t n, vec_t &data)
 Kurtosis with computed mean and standard deviation.
template<class vec_t >
double vector_lag1_autocorr (size_t n, vec_t &data, double mean)
 Lag-1 autocorrelation.
template<class vec_t >
double vector_lag1_autocorr (size_t n, vec_t &data)
 Lag-1 autocorrelation.
template<class vec_t >
double vector_covariance (size_t n, vec_t &data1, vec_t &data2, double mean1, double mean2)
 Covariance.
template<class vec_t >
double vector_covariance (size_t n, vec_t &data1, vec_t &data2)
 Covariance.
template<class vec_t >
double vector_correlation (size_t n, vec_t &data1, vec_t &data2)
 Pearson's correlation.
template<class vec_t >
double vector_pvariance (size_t n1, vec_t &data1, size_t n2, vec_t &data2)
 Pooled variance.
template<class vec_t >
double vector_quantile_sorted (size_t n, vec_t &data, const double f)
 Quantile.
template<class vec_t >
double vector_median_sorted (size_t n, vec_t &data)
 Median of sorted data.
template<class vec_t >
double wvector_mean (size_t n, vec_t &data, vec_t &weights)
 Compute the mean of weighted data.
template<class vec_t >
double wvector_factor (size_t n, vec_t &weights)
 Compute a factor for weighted data.
template<class vec_t , class vec2_t >
double wvector_variance_fmean (size_t n, vec_t &data, vec_t &weights, double wmean)
 Compute the variance of a weighted vector with a mean known in advance.
template<class vec_t , class vec2_t >
double wvector_variance (size_t n, vec_t &data, vec2_t &weights)
 Compute the variance of a weighted vector where mean is computed automatically.
template<class vec_t , class vec2_t >
double wvector_variance (size_t n, vec_t &data, vec2_t &weights, double wmean)
 Compute the variance of a weighted vector with specified mean.
template<class vec_t , class vec2_t >
double wvector_stddev_fmean (size_t n, vec_t &data, vec2_t &weights, double wmean)
 Compute the standard deviation of a weighted vector with a mean known in advance.
template<class vec_t , class vec2_t >
double wvector_stddev (size_t n, vec_t &data, vec2_t &weights)
 Compute the standard deviation of a weighted vector where mean is computed automatically.
template<class vec_t , class vec2_t >
double wvector_stddev (size_t n, vec_t &data, vec2_t &weights, double wmean)
 Compute the standard deviation of a weighted vector with specified mean.
template<class vec_t , class vec2_t >
double wvector_sumsq_fmean (size_t n, vec_t &data, vec2_t &weights, double wmean)
 Desc.
template<class vec_t , class vec2_t >
double wvector_sumsq (size_t n, vec_t &data, vec2_t &weights)
 Desc.
template<class vec_t , class vec2_t >
double wvector_absdev (size_t n, vec_t &data, vec2_t &weights, double wmean)
 Desc.
template<class vec_t , class vec2_t >
double wvector_skew (size_t n, vec_t &data, vec2_t &weights, double wmean, double wsd)
 Desc.
template<class vec_t , class vec2_t >
double wvector_skew (size_t n, vec_t &data, vec2_t &weights)
 Desc.
template<class vec_t , class vec2_t >
double wvector_kurtosis (size_t n, vec_t &data, vec2_t &weights, double wmean, double wsd)
 Desc.
template<class vec_t , class vec2_t >
double wvector_kurtosis (size_t n, vec_t &data, vec2_t &weights)
 Desc.

Function Documentation

double vector_absdev ( size_t  n,
vec_t &  data 
) [inline]

This function computes

\[ \sum_i \left| x_i - \frac{1}{N} \left(\sum_j x_j\right) \right| \]

where the value of $ \mu $ is given in mean.

If n is zero, this function will return zero without calling the error handler.

Definition at line 229 of file vec_stats.h.

double vector_absdev ( size_t  n,
vec_t &  data,
double  mean 
) [inline]

This function computes

\[ \sum_i | x_i - \mu | \]

where the value of $ \mu $ is given in mean.

If n is zero, this function will return zero without calling the error handler.

Definition at line 205 of file vec_stats.h.

double vector_correlation ( size_t  n,
vec_t &  data1,
vec_t &  data2 
) [inline]

If n is zero, this function will call the error handler.

Definition at line 439 of file vec_stats.h.

double vector_covariance ( size_t  n,
vec_t &  data1,
vec_t &  data2 
) [inline]

This function computes

\[ \frac{1}{n-1} \sum_i \left(x_i - {\bar{x}}\right) \left(y_i - {\bar{y}}\right) \]

where $ {\bar{x}} $ and $ {\bar{y}} $ are the averages of data1 and data2 and are computed automatically.

If n is zero, this function will return zero without calling the error handler.

Definition at line 413 of file vec_stats.h.

double vector_covariance ( size_t  n,
vec_t &  data1,
vec_t &  data2,
double  mean1,
double  mean2 
) [inline]

This function computes

\[ \frac{1}{n-1} \sum_i \left(x_i - {\bar{x}}\right) \left(y_i - {\bar{y}}\right) \]

where $ {\bar{x}} $ and $ {\bar{y}} $ are specified in mean1 and mean2, respectively.

If n is zero, this function will return zero without calling the error handler.

Definition at line 387 of file vec_stats.h.

double vector_kurtosis ( size_t  n,
vec_t &  data 
) [inline]

This function computes

\[ -3 + \frac{1}{N} \sum_i \left[ \frac{ \left(x_i - \mu \right)}{ \sigma }\right]^4 \]

where the values of $ \mu $ and $ \sigma $ are computed using vector_mean() and vector_stddev().

If n is zero, this function will return zero without calling the error handler.

Definition at line 316 of file vec_stats.h.

double vector_kurtosis ( size_t  n,
vec_t &  data,
double  mean,
double  stddev 
) [inline]

This function computes

\[ -3 + \frac{1}{N} \sum_i \left[ \frac{ \left(x_i - \mu \right)}{ \sigma }\right]^4 \]

where the values of $ \mu $ and $ \sigma $ are given in mean and stddev.

If n is zero, this function will return zero without calling the error handler.

Definition at line 292 of file vec_stats.h.

double vector_lag1_autocorr ( size_t  n,
vec_t &  data 
) [inline]

This function computes

\[ \left[ \sum_i \left(x_i - \mu\right) \left(x_{i-1} - \mu \right) \right] \left[ \sum_i \left(x_i - \mu\right)^2 \right]^{-1} \]

If n is zero, this function will call the error handler.

Definition at line 368 of file vec_stats.h.

double vector_lag1_autocorr ( size_t  n,
vec_t &  data,
double  mean 
) [inline]

This function computes

\[ \left[ \sum_i \left(x_i - \mu\right) \left(x_{i-1} - \mu \right) \right] \left[ \sum_i \left(x_i - \mu\right)^2 \right]^{-1} \]

If n is zero, this function will call the error handler.

Definition at line 336 of file vec_stats.h.

double vector_mean ( size_t  n,
vec_t &  data 
) [inline]

If n is zero, this will return zero.

Definition at line 52 of file vec_stats.h.

double vector_median_sorted ( size_t  n,
vec_t &  data 
) [inline]

Todo:
Document this
If n is zero, this function will return zero without calling the error handler.

Definition at line 524 of file vec_stats.h.

double vector_pvariance ( size_t  n1,
vec_t &  data1,
size_t  n2,
vec_t &  data2 
) [inline]

Todo:
Document this
If n is zero, this function will return zero without calling the error handler.

Definition at line 490 of file vec_stats.h.

double vector_quantile_sorted ( size_t  n,
vec_t &  data,
const double  f 
) [inline]

Todo:
Document this
If n is zero, this function will return zero without calling the error handler.

Definition at line 505 of file vec_stats.h.

double vector_skew ( size_t  n,
vec_t &  data 
) [inline]

This function computes

\[ \frac{1}{N} \sum_i \left[ \frac{ \left(x_i - \mu \right)}{ \sigma }\right]^3 \]

where the values of $ \mu $ and $ \sigma $ are computed using vector_mean() and vector_stddev().

If n is zero, this function will return zero without calling the error handler.

Definition at line 272 of file vec_stats.h.

double vector_skew ( size_t  n,
vec_t &  data,
double  mean,
double  stddev 
) [inline]

This function computes

\[ \frac{1}{N} \sum_i \left[ \frac{ \left(x_i - \mu \right)}{ \sigma }\right]^3 \]

where the values of $ \mu $ and $ \sigma $ are given in mean and stddev.

If n is zero, this function will return zero without calling the error handler.

Definition at line 248 of file vec_stats.h.

double vector_stddev ( size_t  n,
vec_t &  data,
double  mean 
) [inline]

This function computes

\[ \sqrt{\frac{1}{N-1} \sum_{i} \left( x_i - \mu \right)^2} \]

where the value of $ \mu $ is given in mean.

If n is 0 or 1, this function will call the error handler.

Definition at line 181 of file vec_stats.h.

double vector_stddev ( size_t  n,
vec_t &  data 
) [inline]

This function computes

\[ \sqrt{\frac{1}{N-1} \sum_{i} \left( x_i - \mu \right)^2} \]

where $ \mu $ is the mean computed with vector_mean().

If n is 0 or 1, this function will call the error handler.

Definition at line 157 of file vec_stats.h.

double vector_stddev_fmean ( size_t  n,
vec_t &  data,
double  mean 
) [inline]

This function computes

\[ \sqrt{\frac{1}{N} \sum_{i} \left( x_i - \mu \right)^2} \]

where the value of $ \mu $ is given in mean.

If n is zero, this function will return zero without calling the error handler.

Definition at line 139 of file vec_stats.h.

double vector_variance ( size_t  n,
vec_t &  data 
) [inline]

This function computes

\[ \frac{1}{N-1} \sum_{i} \left( x_i - \mu \right)n^2 \]

where $ \mu $ is the mean computed with vector_mean().

If n is 0 or 1, this function will call the error handler.

Definition at line 115 of file vec_stats.h.

double vector_variance ( size_t  n,
vec_t &  data,
double  mean 
) [inline]

This function computes

\[ \frac{1}{N-1} \sum_{i} \left( x_i - \mu \right)^2 \]

where the value of $ \mu $ is given in mean.

If n is 0 or 1, this function will call the error handler.

Definition at line 92 of file vec_stats.h.

double vector_variance_fmean ( size_t  n,
vec_t &  data,
double  mean 
) [inline]

This function computes

\[ \frac{1}{N} \sum_{i} \left( x_i - \mu \right)^2 \]

where the value of $ \mu $ is given in mean.

Definition at line 70 of file vec_stats.h.

double wvector_factor ( size_t  n,
vec_t &  weights 
) [inline]

This function is used in wvector_variance(size_t n, vec_t &data, vec2_t &weights, double wmean) and wvector_stddev(size_t n, vec_t &data, vec2_t &weights, double wmean) .

Definition at line 567 of file vec_stats.h.


Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page