This chapter describes the statistical functions provided by the PLT Scheme Science Collection. The basic statistical functions include functions to compute the mean, variance, and standard deviation, More advanced functions allow you to calculate absolute deviation, skewness, and kurtosis, as well as the median and arbitrary percentiles. The algorithms use recurrance relations to compute average quantities in a stable way, without large intermediate values that might overflow.

The functions described in this chapter are defined in the "statistics.ss" file in the science collection and are made available using the form:

8.2Absolute Deviation

Returns the absolute devistion of data relative to the given value of the mean mu. If mu is not provided, it is calculated by a call to (meandata). This function is also useful if you want to calculate the absolute deviation to any value other than the mean, such as zero or the median.

8.3Higher Moments (Skewness and Kurtosis)

Returns the skewness of data using the given values of the mean mu and standard deviation sigma. The skewness measures the symmetry of the tails of a distribution. If mu and sigma are not provided, they are calculated by calls to (meandata) and (standard-deviationdatamu).

Returns the kurtosis of data using the given values of the mean mu and standard deviation sigma. The kurtosis measures how sharply peaked a distribution is relative to its width. If mu and sigma are not provided, they are calculated by calls to (meandata) and (standard-deviationdatamu).

Returns the covariance of data1 and data2, which must both be the same length, using the given values of mu1 and mu2. If the values of mu1 and mu2 are not given, they are calculated using calls to (meandata1) and (meandata2), respectively.

Returns the weighted standard deviation of data using weights w. The standard deviation is defined as the square root of the variance. The result is the square root of the corresponding weighted-variance function.

Returns the weighted absolute devistion of data using weights w relative to the given value of the weighted mean wmu. If wmu is not provided, it is calculated by a call to (weighted-meanwdata). This function is also useful if you want to calculate the weighted absolute deviation to any value other than the mean, such as zero or the weighted median.

Returns the weighted skewness of data using weights w using the given values of the weighted mean wmu and weighted standard deviation wsigma. The skewness measures the symmetry of the tails of a distribution. If wmu and wsigma are not provided, they are calculated by calls to (weighted-meanwdata) and (weighted-standard-deviationwdatawmu).

Returns the weighted kurtosis of data using weights w using the given values of the weighted mean wmu and weighted standard deviation wsigma. The kurtosis measures how sharply peaked a distribution is relative to its width. If wmu and wsigma are not provided, they are calculated by calls to (weighted-meanwdata) and (weighted-standard-deviationwdatawmu).

Returns the indices of the minimum and maximum values in data as multiple values. When there are several equal minimum or maximum elements, the index of the first ones are chosen.

8.8Median and Percentiles

Thw median and percentile functions described in this section operate on sorted data. The contracts for these functions enforce this. Also, for convenience we use quantiles measured on a scale of 0 to 1 instead of percentiled, which ise a scale of 0 to 100).

Returns the median value of sorted-data. When the dataset has an odd number of elements, the median is the value of element (n - 1)/2. When the dataset has an even number of elements, the median is the mean of the two nearest middle values, elements (n - 1)/2 and n/2.

Returns a quantile value of sorted-data. The quantile is determined by the value f, a fraction between 0 and 1. For example to compute the 75th percentile, f should have the value 0.75.

The quantile is found by interpolation using the formula:

quantile = 1 - delta(x[i]) + delta(x(i + 1))

where i is floor((n - 1) × f) and delta is (n - 1) × f - 1.

8.9Statistics Example

This example generates two vectors from a unit Gaussian distribution and a vector of conse squared weighting data. All of the vectors are of length 1,000. Thes data are used to test all of the statistics functions.