Chapter 10: Statistics and Random Number Generation

.p>.CMCH10.DOC!SIMPLE_STATISTICS;simple_statistics

Computes basic univariate statistics.

Synopsis

#include <imsl.h>

float *imsl_f_simple_statistics (int n_observations, int _variables, float x[] ,¼, 0)

The type double procedure is imsl_d_simple_statistics.

Required Arguments

int n_observations   (Input)
The number of observations.

int n_variables   (Input)
The number of variables.

float x[]   (Input)
Array of size n_observations ´  n_variables containing the data matrix.

Return Value

A pointer to a matrix containing some simple statistics for each of the columns in x. If MEDIAN and MEDIAN_AND_SCALE are not used as optional arguments, the size of the matrix is 14 by n_variables. The columns of this matrix correspond to the columns of x and the rows contain the following statistics:

Row

Statistic

0

the mean

1

the variance

2

the standard deviation

3

the coefficient of skewness

4

the coefficient of excess (kurtosis)

5

the minimum value

6

the maximum value

7

the range

8

the coefficient of variation (when defined)

If the coefficient of variation is not defined, zero is returned.

9

the number of observations (the counts)

10

a lower confidence limit for the mean (assuming normality)

The default is a 95 percent confidence interval.

11

an upper confidence limit for the mean (assuming normality)

12

a lower confidence limit for the variance (assuming normality)

The default is a 95 percent confidence interval.

13

an upper confidence limit for the variance (assuming normality)

Synopsis with Optional Arguments

#include <imsl.h>

float *imsl_f_simple_statistics (int n_observations, int n_variables, float x[],
IMSL_CONFIDENCE_MEANS, float confidence_means,
IMSL_CONFIDENCE_VARIANCES, float confidence_variances,
IMSL_X_COL_DIM, int x_col_dim,
IMSL_STAT_COL_DIM, int stat_col_dim,
IMSL_MEDIAN,
IMSL_MEDIAN_AND_SCALE,
IMSL_RETURN_USER, float simple_statistics[],
0)

Optional Arguments

IMSL_CONFIDENCE_MEANS, float confidence_means   (Input)
The confidence level for a two-sided interval estimate of the means (assuming normality) in percent. Argument confidence_means must be between 0.0 and 100.0 and is often 90.0, 95.0, or 99.0. For a one-sided confidence interval with confidence level c, set confidence_means = 100.0  2(100  c). If IMSL_CONFIDENCE_MEANS is not specified, a 95 percent confidence interval is computed.

IMSL_CONFIDENCE_VARIANCES, float confidence_variances   (Input)
The confidence level for a two-sided interval estimate of the variances (assuming normality) in percent. The confidence intervals are symmetric in probability (rather than in length). For a one-sided confidence interval with confidence level c, set confidence_means = 100.0  2(100  c). If IMSL_CONFIDENCE_VARIANCES is not specified, a 95 percent confidence interval is computed.

IMSL_X_COL_DIM, int x_col_dim   (Input)
The column dimension of array x.
Default: x_col_dim = n_variables

IMSL_STAT_COL_DIM, int stat_col_dim   (Input)
The column dimension of the returned value array, or if IMSL_RETURN_USER is specified, the column dimension of array simple_statistics.
Default: stat_col_dim = n_variables

IMSL_MEDIAN, or

IMSL_MEDIAN_AND_SCALE
Exactly one of these optional arguments can be specified in order to indicate the additional simple robust statistics to be computed. If IMSL_MEDIAN is specified, the medians are computed and stored in one additional row (row number 14) in the returned matrix of simple statistics. If IMSL_MEDIAN_AND_SCALE is specified, the medians, the medians of the absolute deviations from the medians, and a simple robust estimate of scale are computed, then stored in three additional rows (rows 14, 15, and 16) in the returned matrix of simple statistics.

IMSL_RETURN_USER, float simple_statistics[]   (Output)
Store the matrix of statistics in the user-provided array simple_statistics. If neither IMSL_MEDIAN nor IMSL_MEDIAN_AND_SCALE is specified, the matrix is 14 by n_variables. If IMSL_MEDIAN is specified, the matrix is
15 by n_variables. If IMSL_MEDIAN_AND_SCALE is specified, the matrix is 17 by n_variables.

Description

For the data in each column of x, imsl_f_simple_statistics computes the sample mean, variance, minimum, maximum, and other basic statistics. It also computes confidence intervals for the mean and variance (under the hypothesis that the sample is from a normal population).

The definitions of some of the statistics are given below in terms of a single variable
x of which the i-th datum is xi.

Mean

Variance

Skewness

Excess or Kurtosis

Minimum

Maximum

Range

Coefficient of Variation

Median

Median Absolute Deviation

Simple Robust Estimate of Scale

where Φ-1(3/4) » 0.6745 is the inverse of the standard normal distribution function evaluated at 34. This standardizes MAD in order to make the scale estimate consistent at the normal distribution for estimating the standard deviation (Huber 1981, pp. 107108).

Example

This example uses data from Draper and Smith (1981). There are five variables and 13 observations.

#include <imsl.h>

#define N_VARIABLES            5
#define N_OBSERVATIONS         13

main()
{
    float       *simple_statistics;
    float       x[] = {7., 26.,  6., 60.,  78.5,
                       1., 29., 15., 52.,  74.3,
                      11., 56.,  8., 20., 104.3,
                      11., 31.,  8., 47.,  87.6,
                       7., 52.,  6., 33.,  95.9,
                      11., 55.,  9., 22., 109.2,
                       3., 71., 17.,  6., 102.7,
                       1., 31., 22., 44.,  72.5,
                       2., 54., 18., 22.,  93.1,
                      21., 47.,  4., 26., 115.9,
                       1., 40., 23., 34.,  83.8,
                      11., 66.,  9., 12., 113.3,
                      10., 68.,  8., 12., 109.4};
    char        *row_labels[] = {"means", "variances", "std. dev",
                                 "skewness", "kurtosis", "minima",
                                 "maxima", "ranges", "C.V.", "counts",
                                 "lower mean", "upper mean",
                                 "lower var", "upper var"};

    simple_statistics = imsl_f_simple_statistics(N_OBSERVATIONS,
                                                 N_VARIABLES, x, 0);

    imsl_f_write_matrix("* * * Statistics * * *\n", 14, N_VARIABLES,
                        simple_statistics,
                        IMSL_ROW_LABELS,  row_labels,
                        IMSL_WRITE_FORMAT, "%7.3f",
                        0);
}

Output

                * * * Statistics * * *

                  1        2        3        4        5
means         7.462   48.154   11.769   30.000   95.423
variances    34.603  242.141   41.026  280.167  226.314
std. dev      5.882   15.561    6.405   16.738   15.044
skewness      0.688   -0.047    0.611    0.330   -0.195
kurtosis      0.075   -1.323   -1.079   -1.014   -1.342
minima        1.000   26.000    4.000    6.000   72.500
maxima       21.000   71.000   23.000   60.000  115.900
ranges       20.000   45.000   19.000   54.000   43.400
C.V.          0.788    0.323    0.544    0.558    0.158
counts       13.000   13.000   13.000   13.000   13.000
lower mean    3.907   38.750    7.899   19.885   86.332
upper mean   11.016   57.557   15.640   40.115  104.514
lower var    17.793  124.512   21.096  144.065  116.373
upper var    94.289  659.817  111.792  763.434  616.688


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260