⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statistics.texi

📁 开放gsl矩阵运算
💻 TEXI
📖 第 1 页 / 共 2 页
字号:
@cindex statistics@cindex mean@cindex standard deviation@cindex variance@cindex estimated standard deviation@cindex estimated variance@cindex t-test@cindex range@cindex min@cindex maxThis chapter describes the statistical functions in the library.  Thebasic statistical functions include routines to compute the mean,variance and standard deviation.  More advanced functions allow you tocalculate absolute deviations, skewness, and kurtosis as well as themedian and arbitrary percentiles.  The algorithms use recurrencerelations to compute average quantities in a stable way, without largeintermediate values that might overflow. The functions are available in versions for datasets in the standardfloating-point and integer types.  The versions for double precisionfloating-point data have the prefix @code{gsl_stats} and are declared inthe header file @file{gsl_stats_double.h}.  The versions for integerdata have the prefix @code{gsl_stats_int} and are declared in the headerfiles @file{gsl_stats_int.h}. @menu* Mean and standard deviation and variance::  * Absolute deviation::          * Higher moments (skewness and kurtosis)::  * Autocorrelation::             * Covariance::                  * Weighted Samples::            * Maximum and Minimum values::  * Median and Percentiles::      * Example statistical programs::  * Statistics References and Further Reading::  @end menu@node Mean and standard deviation and variance@section Mean, Standard Deviation and Variance@deftypefn Statistics double gsl_stats_mean (const double @var{data}[], size_t @var{stride}, size_t @var{n})This function returns the arithmetic mean of @var{data}, a dataset oflength @var{n} with stride @var{stride}.  The arithmetic mean, or@dfn{sample mean}, is denoted by @math{\Hat\mu} and defined as,@tex\beforedisplay$${\Hat\mu} = {1 \over N} \sum x_i$$\afterdisplay@end tex@ifinfo@example\Hat\mu = (1/N) \sum x_i@end example@end ifinfo@noindentwhere @math{x_i} are the elements of the dataset @var{data}.  Forsamples drawn from a gaussian distribution the variance of@math{\Hat\mu} is @math{\sigma^2 / N}.@end deftypefn@deftypefn Statistics double gsl_stats_variance (const double @var{data}[], size_t @var{stride}, size_t @var{n})This function returns the estimated, or @dfn{sample}, variance of@var{data}, a dataset of length @var{n} with stride @var{stride}.  Theestimated variance is denoted by @math{\Hat\sigma^2} and is defined by,@tex\beforedisplay$${\Hat\sigma}^2 = {1 \over (N-1)} \sum (x_i - {\Hat\mu})^2$$\afterdisplay@end tex@ifinfo@example\Hat\sigma^2 = (1/(N-1)) \sum (x_i - \Hat\mu)^2@end example@end ifinfo@noindentwhere @math{x_i} are the elements of the dataset @var{data}.  Note thatthe normalization factor of @math{1/(N-1)} results from the derivationof @math{\Hat\sigma^2} as an unbiased estimator of the populationvariance @math{\sigma^2}.  For samples drawn from a gaussian distributionthe variance of @math{\Hat\sigma^2} itself is @math{2 \sigma^4 / N}.This function computes the mean via a call to @code{gsl_stats_mean}.  Ifyou have already computed the mean then you can pass it directly to@code{gsl_stats_variance_m}.@end deftypefn@deftypefn Statistics double gsl_stats_variance_m (const double @var{data}[], size_t @var{stride}, size_t @var{n}, double @var{mean})This function returns the sample variance of @var{data} relative to thegiven value of @var{mean}.  The function is computed with @math{\Hat\mu}replaced by the value of @var{mean} that you supply,@tex\beforedisplay$${\Hat\sigma}^2 = {1 \over (N-1)} \sum (x_i - mean)^2$$\afterdisplay@end tex@ifinfo@example\Hat\sigma^2 = (1/(N-1)) \sum (x_i - mean)^2@end example@end ifinfo@end deftypefn@deftypefn Statistics double gsl_stats_sd (const double @var{data}[], size_t @var{stride}, size_t @var{n})@deftypefnx Statistics double gsl_stats_sd_m (const double @var{data}[], size_t @var{stride}, size_t @var{n}, double @var{mean})The standard deviation is defined as the square root of the variance.These functions return the square root of the corresponding variancefunctions above.@end deftypefn@deftypefn Statistics double gsl_stats_variance_with_fixed_mean (const double @var{data}[], size_t @var{stride}, size_t @var{n}, double @var{mean})This function computes an unbiased estimate of the variance of@var{data} when the population mean @var{mean} of the underlyingdistribution is known @emph{a priori}.  In this case the estimator forthe variance uses the factor @math{1/N} and the sample mean@math{\Hat\mu} is replaced by the known population mean @math{\mu},@tex\beforedisplay$${\Hat\sigma}^2 = {1 \over N} \sum (x_i - \mu)^2$$\afterdisplay@end tex@ifinfo@example\Hat\sigma^2 = (1/N) \sum (x_i - \mu)^2@end example@end ifinfo@noindent@end deftypefn@deftypefn Statistics double gsl_stats_sd_with_fixed_mean (const double @var{data}[], size_t @var{stride}, size_t @var{n}, double @var{mean})This function calculates the standard deviation of @var{data} for a afixed population mean @var{mean}.  The result is the square root of thecorresponding variance function.@end deftypefn@node Absolute deviation@section Absolute deviation@deftypefn Statistics double gsl_stats_absdev (const double @var{data}[], size_t @var{stride}, size_t @var{n})This function computes the absolute deviation from the mean of@var{data}, a dataset of length @var{n} with stride @var{stride}.  Theabsolute deviation from the mean is defined as,@tex\beforedisplay$$absdev  = {1 \over N} \sum |x_i - {\Hat\mu}|$$\afterdisplay@end tex@ifinfo@exampleabsdev  = (1/N) \sum |x_i - \Hat\mu|@end example@end ifinfo@noindentwhere @math{x_i} are the elements of the dataset @var{data}.  Theabsolute deviation from the mean provides a more robust measure of thewidth of a distribution than the variance.  This function computes themean of @var{data} via a call to @code{gsl_stats_mean}.@end deftypefn@deftypefn Statistics double gsl_stats_absdev_m (const double @var{data}[], size_t @var{stride}, size_t @var{n}, double @var{mean})This function computes the absolute deviation of the dataset @var{data}relative to the given value of @var{mean},@tex\beforedisplay$$absdev  = {1 \over N} \sum |x_i - mean|$$\afterdisplay@end tex@ifinfo@exampleabsdev  = (1/N) \sum |x_i - mean|@end example@end ifinfo@noindentThis function is useful if you have already computed the mean of@var{data} (and want to avoid recomputing it), or wish to calculate theabsolute deviation relative to another value (such as zero, or themedian).@end deftypefn@node Higher moments (skewness and kurtosis)@section Higher moments (skewness and kurtosis)@deftypefn Statistics double gsl_stats_skew (const double @var{data}[], size_t @var{stride}, size_t @var{n})This function computes the skewness of @var{data}, a dataset of length@var{n} with stride @var{stride}.  The skewness is defined as,@tex\beforedisplay$$skew = {1 \over N} \sum  {\left( x_i - {\Hat\mu} \over {\Hat\sigma} \right)}^3$$\afterdisplay@end tex@ifinfo@exampleskew = (1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^3@end example@end ifinfo@noindentwhere @math{x_i} are the elements of the dataset @var{data}.  The skewnessmeasures the asymmetry of the tails of a distribution.The function computes the mean and estimated standard deviation of@var{data} via calls to @code{gsl_stats_mean} and @code{gsl_stats_sd}.@end deftypefn@deftypefn Statistics double gsl_stats_skew_m_sd (const double @var{data}[], size_t @var{stride}, size_t @var{n}, double @var{mean}, double @var{sd})This function computes the skewness of the dataset @var{data} using thegiven values of the mean @var{mean} and standard deviation @var{sd},@tex\beforedisplay$$skew = {1 \over N}     \sum {\left( x_i - mean \over sd \right)}^3$$\afterdisplay@end tex@ifinfo@exampleskew = (1/N) \sum ((x_i - mean)/sd)^3@end example@end ifinfo@noindentThese functions are useful if you have already computed the mean andstandard deviation of @var{data} and want to avoid recomputing them.@end deftypefn@deftypefn Statistics double gsl_stats_kurtosis (const double @var{data}[], size_t @var{stride}, size_t @var{n})This function computes the kurtosis of @var{data}, a dataset of length@var{n} with stride @var{stride}.  The kurtosis is defined as,@tex\beforedisplay$$kurtosis = \left( {1 \over N} \sum  {\left(x_i - {\Hat\mu} \over {\Hat\sigma} \right)}^4  \right)  - 3$$\afterdisplay@end tex@ifinfo@examplekurtosis = ((1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^4)  - 3@end example@end ifinfo@noindentThe kurtosis measures how sharply peaked a distribution is, relative toits width.  The kurtosis is normalized to zero for a gaussiandistribution.@end deftypefn@deftypefn Statistics double gsl_stats_kurtosis_m_sd (const double @var{data}[], size_t @var{stride}, size_t @var{n}, double @var{mean}, double @var{sd})This function computes the kurtosis of the dataset @var{data} using thegiven values of the mean @var{mean} and standard deviation @var{sd},@tex\beforedisplay$$kurtosis = {1 \over N}  \left( \sum {\left(x_i - mean \over sd \right)}^4 \right)   - 3$$\afterdisplay@end tex@ifinfo@examplekurtosis = ((1/N) \sum ((x_i - mean)/sd)^4) - 3@end example@end ifinfo@noindentThis function is useful if you have already computed the mean andstandard deviation of @var{data} and want to avoid recomputing them.@end deftypefn@node Autocorrelation@section Autocorrelation@deftypefun double gsl_stats_lag1_autocorrelation (const double data[], const size_t @var{stride}, const size_t @var{n})This function computes the lag-1 autocorrelation of the dataset @var{data}.@tex\beforedisplay$$a_1 = {\sum_{i = 1}^{n} (x_{i} - \Hat\mu) (x_{i-1} - \Hat\mu)\over\sum_{i = 1}^{n} (x_{i} - \Hat\mu) (x_{i} - \Hat\mu)}$$\afterdisplay@end tex@ifinfo@examplea_1 = @{\sum_@{i = 1@}^@{n@} (x_@{i@} - \Hat\mu) (x_@{i-1@} - \Hat\mu)       \over       \sum_@{i = 1@}^@{n@} (x_@{i@} - \Hat\mu) (x_@{i@} - \Hat\mu)@}@end example@end ifinfo@noindent@end deftypefun@deftypefun double gsl_stats_lag1_autocorrelation_m (const double data[], const size_t @var{stride}, const size_t @var{n}, const double @var{mean})This function computes the lag-1 autocorrelation of the dataset@var{data} using the given value of the mean @var{mean}.@end deftypefun@node Covariance@section Covariance@cindex covariance, of two datasets@deftypefun double gsl_stats_covariance (const double @var{data1}[], const size_t @var{stride1}, const double data2[], const size_t @var{stride2}, const size_t @var{n})This function computes the covariance of the datasets @var{data1} and@var{data2} which must both be of the same length @var{n}.@tex\beforedisplay$$covar = {1 \over (n - 1)} \sum_{i = 1}^{n} (x_{i} - \Hat x) (y_{i} - \Hat y)$$\afterdisplay@end tex@ifinfo@examplecovar = (1/(n - 1)) \sum_@{i = 1@}^@{n@} (x_i - \Hat x) (y_i - \Hat y)@end example@end ifinfo@noindent@end deftypefun@deftypefun double gsl_stats_covariance_m (const double @var{data1}[], const size_t @var{stride1}, const double @var{data2}[], const size_t @var{n}, const double @var{mean1}, const double @var{mean2})This function computes the covariance of the datasets @var{data1} and@var{data2} using the given values of the means, @var{mean1} and@var{mean2}.@end deftypefun@node Weighted Samples@section Weighted SamplesThe functions described in this section allow the computation ofstatistics for weighted samples.  The functions accept an array ofsamples, @math{x_i}, with associated weights, @math{w_i}.  Each sample@math{x_i} is considered as having been drawn from a Gaussiandistribution with variance @math{\sigma_i^2}.  The sample weight@math{w_i} is defined as the reciprocal of this variance, @math{w_i =1/\sigma_i^2}.  Setting a weight to zero corresponds to removing asample from a dataset.@deftypefn Statistics double gsl_stats_wmean (const double @var{w}[], size_t @var{wstride}, const double @var{data}[], size_t @var{stride}, size_t @var{n})This function returns the weighted mean of the dataset @var{data} withstride @var{stride} and length @var{n}, using the set of weights @var{w}with stride @var{wstride} and length @var{n}.  The weighted mean is defined as,@tex\beforedisplay$${\Hat\mu} = {{\sum w_i x_i} \over {\sum w_i}}$$\afterdisplay@end tex@ifinfo@example\Hat\mu = (\sum w_i x_i) / (\sum w_i)@end example@end ifinfo@end deftypefn

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -