Introduction to descriptive
===========================

Package descriptive contains a set of functions for making descriptive statistical computations and graphing. Together with the source code there are three data sets in your Maxima tree: pidigits.data, wind.data and biomed.data.

Any statistics manual can be used as a reference to the functions in package descriptive.

For comments, bugs or suggestions, please contact me at 'RIOTORTO AT YAHOO DOT COM'.

Here is a simple example on how the descriptive functions in descriptive do they work, depending on the nature of their arguments, lists or matrices,

     (%i1) load ("descriptive")$

     (%i2) /* univariate sample */   mean ([a, b, c]);
                                 c + b + a
     (%o2)                       ---------
                                     3

     (%i3) matrix ([a, b], [c, d], [e, f]);
                                 [ a  b ]
                                 [      ]
     (%o3)                       [ c  d ]
                                 [      ]
                                 [ e  f ]

     (%i4) /* multivariate sample */ mean (%);
                           e + c + a  f + d + b
     (%o4)                [---------, ---------]
                               3          3

Note that in multivariate samples the mean is calculated for each column.

In case of several samples with possible different sizes, the Maxima function map can be used to get the desired results for each sample,

     (%i1) load ("descriptive")$

     (%i2) map (mean, [[a, b, c], [d, e]]);
                             c + b + a  e + d
     (%o2)                  [---------, -----]
                                 3        2

In this case, two samples of sizes 3 and 2 were stored into a list.

Univariate samples must be stored in lists like

     (%i1) s1 : [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5];
     (%o1)           [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]

and multivariate samples in matrices as in

     (%i1) s2 : matrix ([13.17, 9.29], [14.71, 16.88], [18.50, 16.88],
                  [10.58, 6.63], [13.33, 13.25], [13.21,  8.12]);
                             [ 13.17  9.29  ]
                             [              ]
                             [ 14.71  16.88 ]
                             [              ]
                             [ 18.5   16.88 ]
     (%o1)                   [              ]
                             [ 10.58  6.63  ]
                             [              ]
                             [ 13.33  13.25 ]
                             [              ]
                             [ 13.21  8.12  ]

In this case, the number of columns equals the random variable dimension and the number of rows is the sample size.

Data can be introduced by hand, but big samples are usually stored in plain text files. For example, file pidigits.data contains the first 100 digits of number %pi:

           3
           1
           4
           1
           5
           9
           2
           6
           5
           3 ...

In order to load these digits in Maxima,

     (%i1) s1 : read_list (file_search ("pidigits.data"))$

     (%i2) length (s1);
     (%o2)                          100

On the other hand, file wind.data contains daily average wind speeds at 5 meteorological stations in the Republic of Ireland (This is part of a data set taken at 12 meteorological stations. The original file is freely downloadable from the StatLib Data Repository and its analysis is discussed in Haslett, J., Raftery, A. E. (1989) SPACE-TIME MODELLING WITH LONG-MEMORY DEPENDENCE: ASSESSING IRELAND'S WIND POWER RESOURCE, WITH DISCUSSION. Applied Statistics 38, 1-50). This loads the data:

     (%i1) s2 : read_matrix (file_search ("wind.data"))$

     (%i2) length (s2);
     (%o2)                          100

     (%i3) s2 [%]; /* last record */
     (%o3)            [3.58, 6.0, 4.58, 7.62, 11.25]

Some samples contain non numeric data. As an example, file biomed.data (which is part of another bigger one downloaded from the StatLib Data Repository) contains four blood measures taken from two groups of patients, A and B, of different ages,

     (%i1) s3 : read_matrix (file_search ("biomed.data"))$

     (%i2) length (s3);
     (%o2)                          100

     (%i3) s3 [1]; /* first record */
     (%o3)            [A, 30, 167.0, 89.0, 25.6, 364]

The first individual belongs to group A, is 30 years old and his/her blood measures were 167.0, 89.0, 25.6 and 364.

One must take care when working with categorical data. In the next example, symbol a is assigned a value in some previous moment and then a sample with categorical value a is taken,

     (%i1) a : 1$

     (%i2) matrix ([a, 3], [b, 5]);
                                 [ 1  3 ]
     (%o2)                       [      ]
                                 [ b  5 ]

Categories: Descriptive statistics Share packages Package descriptive

Functions and Variables for data manipulation
=============================================

 -- Function: build_sample
     build_sample (LIST)
     build_sample (MATRIX)

     Builds a sample from a table of absolute frequencies. The input table can be a matrix or a list of lists, all of them of equal size. The number of columns or the length of the lists must be greater than 1. The last element of each row or list is interpreted as the absolute frequency. The output is always a sample in matrix form.

     Examples:

     Univariate frequency table.

          (%i1) load ("descriptive")$
          (%i2) sam1: build_sample([[6,1], [j,2], [2,1]]);
                                 [ 6 ]
                                 [   ]
                                 [ j ]
          (%o2)                  [   ]
                                 [ j ]
                                 [   ]
                                 [ 2 ]
          (%i3) mean(sam1);
                                2 j + 8
          (%o3)                [-------]
                                   4
          (%i4) barsplot(sam1) $

     Multivariate frequency table.

          (%i1) load ("descriptive")$
          (%i2) sam2: build_sample([[6,3,1], [5,6,2], [u,2,1],[6,8,2]]) ;
                                     [ 6  3 ]
                                     [      ]
                                     [ 5  6 ]
                                     [      ]
                                     [ 5  6 ]
          (%o2)                      [      ]
                                     [ u  2 ]
                                     [      ]
                                     [ 6  8 ]
                                     [      ]
                                     [ 6  8 ]
          (%i3) cov(sam2);
                 [   2                 2                            ]
                 [  u  + 158   (u + 28)     2 u + 174   11 (u + 28) ]
                 [  -------- - ---------    --------- - ----------- ]
          (%o3)  [     6          36            6           12      ]
                 [                                                  ]
                 [ 2 u + 174   11 (u + 28)            21            ]
                 [ --------- - -----------            --            ]
                 [     6           12                 4             ]
          (%i4) barsplot(sam2, grouping=stacked) $

     Categories: Package descriptive

 -- Function: continuous_freq
     continuous_freq (DATA)
     continuous_freq (DATA, M)

     Divides the range of DATA into intervals, and counts how many values fall into each one.

     A value X falls into an interval with left and right endpoints A and B if and only if X > A and X <= B, except for the first (least or leftmost) interval, for which X >= A and X <= B. That is, an interval excludes its left endpoint and includes its right endpoint, except for the first interval, which includes both the left and right endpoints.

     DATA must be a list of numbers, or 1-dimensional array (as created by make_array).

     M is optional, and equals either the number of classes (10 by default), or a list of two elements (the least and greatest values to be counted), or a list of three elements (the least and greatest values to be counted, and the number of classes), or a set containing the endpoints of the class intervals.

     It is assumed that class intervals are contiguous. That is, the right endpoint of one interval is equal to the left endpoint of the next.

     continuous_freq returns a list of two lists. The first list comprises all the endpoints of the class intervals, concatenated into a single list. The second list contains the class counts for the intervals corresponding to elements of the first list.

     If sample values are all equal, this function returns exactly one class of width 2.

     Examples:

     Optional argument indicates the number of classes we want. The first list in the output contains the interval limits, and the second the corresponding counts: there are 16 digits inside the interval [0, 1.8], 24 digits in (1.8, 3.6], and so on.

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) continuous_freq (s1, 5);
          (%o3) [[0, 1.8, 3.6, 5.4, 7.2, 9.0], [16, 24, 18, 17, 25]]

     Optional argument indicates we want 7 classes with limits -2 and 12:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) continuous_freq (s1, [-2,12,7]);
          (%o3) [[- 2, 0, 2, 4, 6, 8, 10, 12], [8, 20, 22, 17, 20, 13, 0]]

     Optional argument indicates we want the default number of classes with limits -2 and 12:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) continuous_freq (s1, [-2,12]);
                          3  4  11  18     32  39  46  53
          (%o3)  [[- 2, - -, -, --, --, 5, --, --, --, --, 12],
                          5  5  5   5      5   5   5   5
                         [0, 8, 20, 12, 18, 9, 8, 25, 0, 0]]

     The first argument may be an array.

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) a1 : make_array (fixnum, length (s1)) $
          (%i4) fillarray (a1, s1);
          (%o4) {Lisp Array:
          #(3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 \
          5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 0 5 8 2 0 9 7 4 9 4 4 5 9
            2 3 0 7 8 1 6 4 0 6 2 8 6 2 0 8 9 9 8 6 2 8 0 3 4 8 2 5 3 4 2 \
          1 1 7 0 6 7)}
          (%i5) continuous_freq (a1);
                     9   9  27  18  9  27  63  36  81
          (%o5) [[0, --, -, --, --, -, --, --, --, --, 9],
                     10  5  10  5   2  5   10  5   10
                                       [8, 8, 12, 12, 10, 8, 9, 8, 12, 13]]

     Categories: Package descriptive

 -- Function: discrete_freq (DATA)
     Counts absolute frequencies in discrete samples, both numeric and categorical. Its unique argument is a list, or 1-dimensional array (as created by make_array).

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) discrete_freq (s1);
          (%o3) [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
                                       [8, 8, 12, 12, 10, 8, 9, 8, 12, 13]]

     The first list gives the sample values and the second their absolute frequencies. Commands ? col and ? transpose should help you to understand the last input.

     The argument may be an array.

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) a1 : make_array (fixnum, length (s1)) $
          (%i4) fillarray (a1, s1);
          (%o4) {Lisp Array:
          #(3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 \
          5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 0 5 8 2 0 9 7 4 9 4 4 5 9
            2 3 0 7 8 1 6 4 0 6 2 8 6 2 0 8 9 9 8 6 2 8 0 3 4 8 2 5 3 4 2 \
          1 1 7 0 6 7)}
          (%i5) discrete_freq (a1);
          (%o5) [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
                                       [8, 8, 12, 12, 10, 8, 9, 8, 12, 13]]

     Categories: Package descriptive

 -- Function: standardize
     standardize (LIST)
     standardize (MATRIX)

     Subtracts to each element of the list the sample mean and divides the result by the standard deviation. When the input is a matrix, standardize subtracts to each row the multivariate mean, and then divides each component by the corresponding standard deviation.

     Categories: Package descriptive

 -- Function: subsample
     subsample (DATA_MATRIX, PREDICATE_FUNCTION)
     subsample (DATA_MATRIX, PREDICATE_FUNCTION, COL_NUM1, COL_NUM2, ...)

     This is a sort of variant of the Maxima submatrix function. The first argument is the data matrix, the second is a predicate function and optional additional arguments are the numbers of the columns to be taken. Its behaviour is better understood with examples.

     These are multivariate records in which the wind speed in the first meteorological station were greater than 18. See that in the lambda expression the I-th component is referred to as v[i].

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$

          (%i3) subsample (s2, lambda([v], v[1] > 18));
                        [ 19.38  15.37  15.12  23.09  25.25 ]
                        [                                   ]
                        [ 18.29  18.66  19.08  26.08  27.63 ]
          (%o3)         [                                   ]
                        [ 20.25  21.46  19.95  27.71  23.38 ]
                        [                                   ]
                        [ 18.79  18.96  14.46  26.38  21.84 ]

     In the following example, we request only the first, second and fifth components of those records with wind speeds greater or equal than 16 in station number 1 and less than 25 knots in station number 4. The sample contains only data from stations 1, 2 and 5. In this case, the predicate function is defined as an ordinary Maxima function.

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$
          (%i3) g(x):= x[1] >= 16 and x[4] < 25$

          (%i4) subsample (s2, g, 1, 2, 5);
                               [ 19.38  15.37  25.25 ]
                               [                     ]
                               [ 17.33  14.67  19.58 ]
          (%o4)                [                     ]
                               [ 16.92  13.21  21.21 ]
                               [                     ]
                               [ 17.25  18.46  23.87 ]

     Here is an example with the categorical variables of biomed.data. We want the records corresponding to those patients in group B who are older than 38 years.

          (%i1) load ("descriptive")$
          (%i2) s3 : read_matrix (file_search ("biomed.data"))$
          (%i3) h(u):= u[1] = B and u[2] > 38 $

          (%i4) subsample (s3, h);
                          [ B  39  28.0  102.3  17.1  146 ]
                          [                               ]
                          [ B  39  21.0  92.4   10.3  197 ]
                          [                               ]
                          [ B  39  23.0  111.5  10.0  133 ]
                          [                               ]
                          [ B  39  26.0  92.6   12.3  196 ]
          (%o4)           [                               ]
                          [ B  39  25.0  98.7   10.0  174 ]
                          [                               ]
                          [ B  39  21.0  93.2   5.9   181 ]
                          [                               ]
                          [ B  39  18.0  95.0   11.3  66  ]
                          [                               ]
                          [ B  39  39.0  88.5   7.6   168 ]

     Probably, the statistical analysis will involve only the blood measures,

          (%i1) load ("descriptive")$
          (%i2) s3 : read_matrix (file_search ("biomed.data"))$

          (%i3) subsample (s3, lambda([v], v[1] = B and v[2] > 38),
                           3, 4, 5, 6);
                             [ 28.0  102.3  17.1  146 ]
                             [                        ]
                             [ 21.0  92.4   10.3  197 ]
                             [                        ]
                             [ 23.0  111.5  10.0  133 ]
                             [                        ]
                             [ 26.0  92.6   12.3  196 ]
          (%o3)              [                        ]
                             [ 25.0  98.7   10.0  174 ]
                             [                        ]
                             [ 21.0  93.2   5.9   181 ]
                             [                        ]
                             [ 18.0  95.0   11.3  66  ]
                             [                        ]
                             [ 39.0  88.5   7.6   168 ]

     This is the multivariate mean of s3,

          (%i1) load ("descriptive")$
          (%i2) s3 : read_matrix (file_search ("biomed.data"))$

          (%i3) mean (s3);
                 65 B + 35 A  317          6 NA + 8144.999999999999
          (%o3) [-----------, ---, 87.178, ------------------------,
                     100      10                     100
                                                              3 NA + 19587
                                                      18.123, ------------]
                                                                  100

     Here, the first component is meaningless, since A and B are categorical, the second component is the mean age of individuals in rational form, and the fourth and last values exhibit some strange behaviour. This is because symbol NA is used here to indicate NON AVAILABLE data, and the two means are nonsense. A possible solution would be to take out from the matrix those rows with NA symbols, although this deserves some loss of information.

          (%i1) load ("descriptive")$
          (%i2) s3 : read_matrix (file_search ("biomed.data"))$
          (%i3) g(v):= v[4] # NA and v[6] # NA $

          (%i4) mean (subsample (s3, g, 3, 4, 5, 6));
          (%o4) [79.4923076923077, 86.2032967032967, 16.93186813186813,
                                                                      2514
                                                                      ----]
                                                                       13

     Categories: Package descriptive

 -- Function: transform_sample (MATRIX, VARLIST, EXPRLIST)

     Transforms the sample MATRIX, where each column is called according to VARLIST, following expressions in EXPRLIST.

     Examples:

     The second argument assigns names to the three columns. With these names, a list of expressions define the transformation of the sample.

          (%i1) load ("descriptive")$
          (%i2) data: matrix([3,2,7],[3,7,2],[8,2,4],[5,2,4]) $

          (%i3) transform_sample(data, [a,b,c], [c, a*b, log(a)]);
                                         [ 7  6   log(3) ]
                                         [               ]
                                         [ 2  21  log(3) ]
          (%o3)                          [               ]
                                         [ 4  16  log(8) ]
                                         [               ]
                                         [ 4  10  log(5) ]

     Add a constant column and remove the third variable.

          (%i1) load ("descriptive")$
          (%i2) data: matrix([3,2,7],[3,7,2],[8,2,4],[5,2,4]) $
          (%i3) transform_sample(data, [a,b,c], [makelist(1,k,length(data)),a,b]);

                                            [ 1  3  2 ]
                                            [         ]
                                            [ 1  3  7 ]
          (%o3)                             [         ]
                                            [ 1  8  2 ]
                                            [         ]
                                            [ 1  5  2 ]

     Categories: Package descriptive

Functions and Variables for descriptive statistics
==================================================

 -- Function: mean
     mean (LIST)
     mean (MATRIX)

     This is the sample mean, defined as

                                 n
                               ====
                       _   1   \
                       x = -    >    x
                           n   /      i
                               ====
                               i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) mean (s1);
                                         471
          (%o3)                          ---
                                         100

          (%i4) %, numer;
          (%o4)                         4.71

          (%i5) s2 : read_matrix (file_search ("wind.data"))$

          (%i6) mean (s2);
          (%o6)     [9.9485, 10.1607, 10.8685, 15.7166, 14.8441]

     Categories: Package descriptive

 -- Function: var
     var (LIST)
     var (MATRIX)

     This is the sample variance, defined as

                               n
                             ====
                     2   1   \          _ 2
                    s  = -    >    (x - x)
                         n   /       i
                             ====
                             i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) var (s1), numer;
          (%o3)                   8.425899999999999

     See also function var1

     Categories: Package descriptive

 -- Function: var1
     var1 (LIST)
     var1 (MATRIX)

     This is the sample variance, defined as

                               n
                             ====
                         1   \          _ 2
                        ---   >    (x - x)
                        n-1  /       i
                             ====
                             i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) var1 (s1), numer;
          (%o3)                    8.5110101010101

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) var1 (s2);
          (%o5) [17.39586540404041, 15.13912778787879, 15.63204924242424,
                                      32.50152569696971, 24.66977392929294]

     See also function var

     Categories: Package descriptive

 -- Function: std
     std (LIST)
     std (MATRIX)

     This is the square root of the function var, the variance with denominator n.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) std (s1), numer;
          (%o3)                   2.902740084816414

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) std (s2);
          (%o5) [4.149928523480858, 3.871399812729241, 3.933920277534866,
                                      5.672434260526957, 4.941970881136392]

     See also functions var and std1

     Categories: Package descriptive

 -- Function: std1
     std1 (LIST)
     std1 (MATRIX)

     This is the square root of the function var1 the variance with denominator n-1.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) std1 (s1), numer;
          (%o3)                   2.917363553109228

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) std1 (s2);
          (%o5) [4.170835096721089, 3.89090320978032, 3.953738641137555,
                                      5.701010936401517, 4.966867617451963]

     See also functions var1 and std

     Categories: Package descriptive

 -- Function: noncentral_moment
     noncentral_moment (LIST, K)
     noncentral_moment (MATRIX, K)

     The non central moment of order k, defined as

                                 n
                               ====
                           1   \      k
                           -    >    x
                           n   /      i
                               ====
                               i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) noncentral_moment (s1, 1), numer; /* the mean */
          (%o3)                         4.71

          (%i5) s2 : read_matrix (file_search ("wind.data"))$

          (%i6) noncentral_moment (s2, 5);
          (%o6) [319793.8724761505, 320532.1923892463,
                391249.5621381556, 2502278.205988911, 1691881.797742255]

     See also function central_moment

     Categories: Package descriptive

 -- Function: central_moment
     central_moment (LIST, K)
     central_moment (MATRIX, K)

     The central moment of order k, defined as

                              n
                            ====
                        1   \          _ k
                        -    >    (x - x)
                        n   /       i
                            ====
                            i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) central_moment (s1, 2), numer; /* the variance */
          (%o3)                   8.425899999999999

          (%i5) s2 : read_matrix (file_search ("wind.data"))$

          (%i6) central_moment (s2, 3);
          (%o6) [11.29584771375004, 16.97988248298583, 5.626661952750102,
                                       37.5986572057918, 25.85981904394192]

     See also functions central_moment and mean

     Categories: Package descriptive

 -- Function: cv
     cv (LIST)
     cv (MATRIX)

     The variation coefficient is the quotient between the sample standard deviation (std) and the mean

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) cv (s1), numer;
          (%o3)                   .6193977819764815

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) cv (s2);
          (%o5) [.4192426091090204, .3829365309260502, 0.363779605385983,
                                      .3627381836021478, .3346021393989506]

     See also functions std and mean

     Categories: Package descriptive

 -- Function: smin
     smin (LIST)
     smin (MATRIX)

     This is the minimum value of the sample LIST. When the argument is a matrix, smin returns a list containing the minimum values of the columns, which are associated to statistical variables.

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) smin (s1);
          (%o3)                           0

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) smin (s2);
          (%o5)             [0.58, 0.5, 2.67, 5.25, 5.17]

     See also function smax

     Categories: Package descriptive

 -- Function: smax
     smax (LIST)
     smax (MATRIX)

     This is the maximum value of the sample LIST. When the argument is a matrix, smax returns a list containing the maximum values of the columns, which are associated to statistical variables.

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) smax (s1);
          (%o3)                           9

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) smax (s2);
          (%o5)          [20.25, 21.46, 20.04, 29.63, 27.63]

     See also function smin

     Categories: Package descriptive

 -- Function: range
     range (LIST)
     range (MATRIX)

     The range is the difference between the extreme values.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) range (s1);
          (%o3)                           9

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) range (s2);
          (%o5)          [19.67, 20.96, 17.37, 24.38, 22.46]

     Categories: Package descriptive

 -- Function: quantile
     quantile (LIST, P)
     quantile (MATRIX, P)

     This is the P-quantile, with P a number in [0, 1], of the sample LIST. Although there are several definitions for the sample quantile (Hyndman, R. J., Fan, Y. (1996) SAMPLE QUANTILES IN STATISTICAL PACKAGES. American Statistician, 50, 361-365), the one based on linear interpolation is implemented in package descriptive-pkg

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) /* 1st and 3rd quartiles */
                   [quantile (s1, 1/4), quantile (s1, 3/4)], numer;
          (%o3)                      [2.0, 7.25]

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) quantile (s2, 1/4);
          (%o5)    [7.2575, 7.477500000000001, 7.82, 11.28, 11.48]

     Categories: Package descriptive

 -- Function: median
     median (LIST)
     median (MATRIX)

     Once the sample is ordered, if the sample size is odd the median is the central value, otherwise it is the mean of the two central values.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) median (s1);
                                          9
          (%o3)                           -
                                          2

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) median (s2);
          (%o5)         [10.06, 9.855, 10.73, 15.48, 14.105]

     The median is the 1/2-quantile.

     See also function quantile

     Categories: Package descriptive

 -- Function: qrange
     qrange (LIST)
     qrange (MATRIX)

     The interquartilic range is the difference between the third and first quartiles, quantile(LIST,3/4) - quantile(LIST,1/4),

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) qrange (s1);
                                         21
          (%o3)                          --
                                         4

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) qrange (s2);
          (%o5) [5.385, 5.572499999999998, 6.022500000000001,
                                      8.729999999999999, 6.649999999999999]

     See also function quantile

     Categories: Package descriptive

 -- Function: mean_deviation
     mean_deviation (LIST)
     mean_deviation (MATRIX)

     The mean deviation, defined as

                               n
                             ====
                         1   \          _
                         -    >    |x - x|
                         n   /       i
                             ====
                             i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) mean_deviation (s1);
                                         51
          (%o3)                          --
                                         20

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) mean_deviation (s2);
          (%o5) [3.287959999999999, 3.075342, 3.23907, 4.715664000000001,
                                                         4.028546000000002]

     See also function mean

     Categories: Package descriptive

 -- Function: median_deviation
     median_deviation (LIST)
     median_deviation (MATRIX)

     The median deviation, defined as

                           n
                         ====
                     1   \
                     -    >    |x - med|
                     n   /       i
                         ====
                         i = 1

     where med is the median of LIST.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) median_deviation (s1);
                                          5
          (%o3)                           -
                                          2

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) median_deviation (s2);
          (%o5)           [2.75, 2.755, 3.08, 4.315, 3.31]

     See also function mean

     Categories: Package descriptive

 -- Function: harmonic_mean
     harmonic_mean (LIST)
     harmonic_mean (MATRIX)

     The harmonic mean, defined as

                            n
                         --------
                          n
                         ====
                         \     1
                          >    --
                         /     x
                         ====   i
                         i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) y : [5, 7, 2, 5, 9, 5, 6, 4, 9, 2, 4, 2, 5]$

          (%i3) harmonic_mean (y), numer;
          (%o3)                   3.901858027632205

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) harmonic_mean (s2);
          (%o5) [6.948015590052786, 7.391967752360356, 9.055658197151745,
                                      13.44199028193692, 13.01439145898509]

     See also functions mean and geometric_mean

     Categories: Package descriptive

 -- Function: geometric_mean
     geometric_mean (LIST)
     geometric_mean (MATRIX)

     The geometric mean, defined as

                           /  n      \ 1/n
                           | /===\   |
                           |  ! !    |
                           |  ! !  x |
                           |  ! !   i|
                           | i = 1   |
                           \         /

     Example:

          (%i1) load ("descriptive")$
          (%i2) y : [5, 7, 2, 5, 9, 5, 6, 4, 9, 2, 4, 2, 5]$

          (%i3) geometric_mean (y), numer;
          (%o3)                   4.454845412337012

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) geometric_mean (s2);
          (%o5) [8.82476274347979, 9.22652604739361, 10.0442675714889,
                                      14.61274126349021, 13.96184163444275]

     See also functions mean and harmonic_mean

     Categories: Package descriptive

 -- Function: kurtosis
     kurtosis (LIST)
     kurtosis (MATRIX)

     The kurtosis coefficient, defined as

                              n
                            ====
                      1     \          _ 4
                     ----    >    (x - x)  - 3
                        4   /       i
                     n s    ====
                            i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) kurtosis (s1), numer;
          (%o3)                  - 1.273247946514421

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) kurtosis (s2);
          (%o5) [- .2715445622195385, 0.119998784429451,
               - .4275233490482861, - .6405361979019522, - .4952382132352935]

     See also functions mean var and skewness

     Categories: Package descriptive

 -- Function: skewness
     skewness (LIST)
     skewness (MATRIX)

     The skewness coefficient, defined as

                              n
                            ====
                      1     \          _ 3
                     ----    >    (x - x)
                        3   /       i
                     n s    ====
                            i = 1

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) skewness (s1), numer;
          (%o3)                  .009196180476450424

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) skewness (s2);
          (%o5) [.1580509020000978, .2926379232061854, .09242174416107717,
                                      .2059984348148687, .2142520248890831]

     See also functions mean, var and kurtosis

     Categories: Package descriptive

 -- Function: pearson_skewness
     pearson_skewness (LIST)
     pearson_skewness (MATRIX)

     Pearson's skewness coefficient, defined as

                          _
                       3 (x - med)
                       -----------
                            s

     where MED is the median of LIST.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) pearson_skewness (s1), numer;
          (%o3)                   .2159484029093895

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) pearson_skewness (s2);
          (%o5) [- .08019976629211892, .2357036272952649,
                   .1050904062491204, .1245042340592368, .4464181795804519]

     See also functions mean var and median

     Categories: Package descriptive

 -- Function: quartile_skewness
     quartile_skewness (LIST)
     quartile_skewness (MATRIX)

     The quartile skewness coefficient, defined as

                         c    - 2 c    + c
                          3/4      1/2    1/4
                         --------------------
                             c    - c
                              3/4    1/4

     where c_p is the P-quantile of sample LIST.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$

          (%i3) quartile_skewness (s1), numer;
          (%o3)                  .04761904761904762

          (%i4) s2 : read_matrix (file_search ("wind.data"))$

          (%i5) quartile_skewness (s2);
          (%o5) [- 0.0408542246982353, .1467025572005382,
                 0.0336239103362392, .03780068728522298, .2105263157894735]

     See also function quantile

     Categories: Package descriptive

 -- Function: km
     km (LIST, OPTION ...)
     km (MATRIX, OPTION ...)

     Kaplan Meier estimator of the survival, or reliability, function S(x)=1-F(x).

     Data can be introduced as a list of pairs, or as a two column matrix. The first component is the observed time, and the second component a censoring index (1 = non censored, 0 = right censored).

     The optional argument is the name of the variable in the returned expression, which is X by default.

     Examples:

     Sample as a list of pairs.

          (%i1) load ("descriptive")$

          (%i2) S: km([[2,1], [3,1], [5,0], [8,1]]);
                                 charfun((3 <= x) and (x < 8))
          (%o2) charfun(x < 0) + -----------------------------
                                               2
                          3 charfun((2 <= x) and (x < 3))
                        + -------------------------------
                                         4
                        + charfun((0 <= x) and (x < 2))

          (%i3) load ("draw")$

          (%i4) draw2d(
                  line_width = 3, grid = true,
                  explicit(S, x, -0.1, 10))$

     Estimate survival probabilities.

          (%i1) load ("descriptive")$
          (%i2) S(t):= ''(km([[2,1], [3,1], [5,0], [8,1]], t)) $

          (%i3) S(6);
                                      1
          (%o3)                       -
                                      2

     Categories: Package descriptive

 -- Function: cdf_empirical
     cdf_empirical (LIST, OPTION ...)
     cdf_empirical (MATRIX, OPTION ...)

     Empirical distribution function F(x).

     Data can be introduced as a list of numbers, or as an one column matrix.

     The optional argument is the name of the variable in the returned expression, which is X by default.

     Example:

     Empirical distribution function.

          (%i1) load ("descriptive")$

          (%i2) F(x):= ''(cdf_empirical([1,3,3,5,7,7,7,8,9]));
          (%o2) F(x) := (charfun(x >= 9) + charfun(x >= 8)
                         + 3 charfun(x >= 7) + charfun(x >= 5)
                         + 2 charfun(x >= 3) + charfun(x >= 1))/9

          (%i3) F(6);
                                     4
          (%o3)                      -
                                     9

          (%i4) load("draw")$
          (%i5) draw2d(
                  line_width = 3,
                  grid       = true,
                  explicit(F(z), z, -2, 12)) $

     Categories: Package descriptive

 -- Function: cov (MATRIX)
     The covariance matrix of the multivariate sample, defined as

                        n
                       ====
                    1  \           _        _
                S = -   >    (X  - X) (X  - X)'
                    n  /       j        j
                       ====
                       j = 1

     where X_j is the j-th row of the sample matrix.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$
          (%i3) fpprintprec : 7$  /* change precision for pretty output */

          (%i4) cov (s2);
                [ 17.22191  13.61811  14.37217  19.39624  15.42162 ]
                [                                                  ]
                [ 13.61811  14.98774  13.30448  15.15834  14.9711  ]
                [                                                  ]
          (%o4) [ 14.37217  13.30448  15.47573  17.32544  16.18171 ]
                [                                                  ]
                [ 19.39624  15.15834  17.32544  32.17651  20.44685 ]
                [                                                  ]
                [ 15.42162  14.9711   16.18171  20.44685  24.42308 ]

     See also function cov1

     Categories: Package descriptive

 -- Function: cov1 (MATRIX)
     The covariance matrix of the multivariate sample, defined as

                        n
                       ====
                   1   \           _        _
             S  = ---   >    (X  - X) (X  - X)'
              1   n-1  /       j        j
                       ====
                       j = 1

     where X_j is the j-th row of the sample matrix.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$
          (%i3) fpprintprec : 7$ /* change precision for pretty output */

          (%i4) cov1 (s2);
                [ 17.39587  13.75567  14.51734  19.59216  15.5774  ]
                [                                                  ]
                [ 13.75567  15.13913  13.43887  15.31145  15.12232 ]
                [                                                  ]
          (%o4) [ 14.51734  13.43887  15.63205  17.50044  16.34516 ]
                [                                                  ]
                [ 19.59216  15.31145  17.50044  32.50153  20.65338 ]
                [                                                  ]
                [ 15.5774   15.12232  16.34516  20.65338  24.66977 ]

     See also function cov

     Categories: Package descriptive

 -- Function: global_variances
     global_variances (MATRIX)
     global_variances (MATRIX, OPTIONS ...)

     Function global_variances returns a list of global variance measures:

       * TOTAL VARIANCE: trace(S_1),

       * MEAN VARIANCE: trace(S_1)/p,

       * GENERALIZED VARIANCE: determinant(S_1),

       * GENERALIZED STANDARD DEVIATION: sqrt(determinant(S_1)),

       * EFFECTIVE VARIANCE determinant(S_1)^(1/p), (defined in: Peña, D. (2002) ANÁLISIS DE DATOS MULTIVARIANTES; McGraw-Hill, Madrid.)

       * EFFECTIVE STANDARD DEVIATION: determinant(S_1)^(1/(2*p)).

     where P is the dimension of the multivariate random variable and S_1 the covariance matrix returned by cov1.

     Option:

       * 'data, default 'true, indicates whether the input matrix contains the sample data, in which case the covariance matrix cov1 must be calculated, or not, and then the covariance matrix (symmetric) must be given, instead of the data.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$

          (%i3) global_variances (s2);
          (%o3) [105.338342060606, 21.06766841212119, 12874.34690469686,
                   113.4651792608501, 6.636590811800795, 2.576158149609762]

     Calculate the global_variances from the covariance matrix.

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$
          (%i3) s : cov1 (s2)$

          (%i4) global_variances (s, data=false);
          (%o4) [105.338342060606, 21.06766841212119, 12874.34690469686,
                   113.4651792608501, 6.636590811800795, 2.576158149609762]

     See also cov and cov1

     Categories: Package descriptive

 -- Function: cor
     cor (MATRIX)
     cor (MATRIX, LOGICAL_VALUE)

     The correlation matrix of the multivariate sample.

     Option:

       * 'data, default 'true, indicates whether the input matrix contains the sample data, in which case the covariance matrix cov1 must be calculated, or not, and then the covariance matrix (symmetric) must be given, instead of the data.

     Example:

          (%i1) load ("descriptive")$
          (%i2) fpprintprec : 7 $
          (%i3) s2 : read_matrix (file_search ("wind.data"))$

          (%i4) cor (s2);
                [   1.0     .8476339  .8803515  .8239624  .7519506 ]
                [                                                  ]
                [ .8476339    1.0     .8735834  .6902622  0.782502 ]
                [                                                  ]
          (%o4) [ .8803515  .8735834    1.0     .7764065  .8323358 ]
                [                                                  ]
                [ .8239624  .6902622  .7764065    1.0     .7293848 ]
                [                                                  ]
                [ .7519506  0.782502  .8323358  .7293848    1.0    ]

     Calculate de correlation matrix from the covariance matrix.

          (%i1) load ("descriptive")$
          (%i2) fpprintprec : 7 $
          (%i3) s2 : read_matrix (file_search ("wind.data"))$
          (%i4) s : cov1 (s2)$

          (%i5) cor (s, data=false); /* this is faster */
                [   1.0     .8476339  .8803515  .8239624  .7519506 ]
                [                                                  ]
                [ .8476339    1.0     .8735834  .6902622  0.782502 ]
                [                                                  ]
          (%o5) [ .8803515  .8735834    1.0     .7764065  .8323358 ]
                [                                                  ]
                [ .8239624  .6902622  .7764065    1.0     .7293848 ]
                [                                                  ]
                [ .7519506  0.782502  .8323358  .7293848    1.0    ]

     See also cov and cov1

     Categories: Package descriptive

 -- Function: list_correlations
     list_correlations (MATRIX)
     list_correlations (MATRIX, OPTIONS ...)

     Function list_correlations returns a list of correlation measures:

       * PRECISION MATRIX: the inverse of the covariance matrix S_1,

                      -1     ij
                     S   = (s  )
                      1         i,j = 1,2,...,p

       * MULTIPLE CORRELATION VECTOR:  (R_1^2, R_2^2, ..., R_p^2), with

                      2          1
                     R  = 1 - -------
                      i        ii
                              s   s
                                   ii

          being an indicator of the goodness of fit of the linear multivariate regression model on X_i when the rest of variables are used as regressors.

       * PARTIAL CORRELATION MATRIX: with element (i, j) being

                                        ij
                                       s
                     r        = - ------------
                      ij.rest     / ii  jj\ 1/2
                                  |s   s  |
                                  \       /

     Option:

       * 'data, default 'true, indicates whether the input matrix contains the sample data, in which case the covariance matrix cov1 must be calculated, or not, and then the covariance matrix (symmetric) must be given, instead of the data.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$
          (%i3) z : list_correlations (s2)$
          (%i4) fpprintprec : 5$ /* for pretty output */

          (%i5) z[1];  /* precision matrix */
                [  .38486   - .13856   - .15626   - .10239    .031179  ]
                [                                                      ]
                [ - .13856   .34107    - .15233    .038447   - .052842 ]
                [                                                      ]
          (%o5) [ - .15626  - .15233    .47296    - .024816  - .10054  ]
                [                                                      ]
                [ - .10239   .038447   - .024816   .10937    - .034033 ]
                [                                                      ]
                [ .031179   - .052842  - .10054   - .034033   .14834   ]

          (%i6) z[2];  /* multiple correlation vector */
          (%o6)      [.85063, .80634, .86474, .71867, .72675]

          (%i7) z[3];  /* partial correlation matrix */
                [  - 1.0     .38244   .36627   .49908   - .13049 ]
                [                                                ]
                [  .38244    - 1.0    .37927  - .19907   .23492  ]
                [                                                ]
          (%o7) [  .36627    .37927   - 1.0    .10911    .37956  ]
                [                                                ]
                [  .49908   - .19907  .10911   - 1.0     .26719  ]
                [                                                ]
                [ - .13049   .23492   .37956   .26719    - 1.0   ]

     See also cov and cov1

     Categories: Package descriptive

 -- Function: principal_components
     principal_components (MATRIX)
     principal_components (MATRIX, OPTIONS ...)

     Calculates the principal components of a multivariate sample. Principal components are used in multivariate statistical analysis to reduce the dimensionality of the sample.

     Option:

       * 'data, default 'true, indicates whether the input matrix contains the sample data, in which case the covariance matrix cov1 must be calculated, or not, and then the covariance matrix (symmetric) must be given, instead of the data.

     The output of function principal_components is a list with the following results:

       * variances of the principal components,

       * percentage of total variance explained by each principal component,

       * rotation matrix.

     Examples:

     In this sample, the first component explains 83.13 per cent of total variance.

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$
          (%i3) fpprintprec:4 $
          (%i4) res: principal_components(s2);
          0 errors, 0 warnings
          (%o4) [[87.57, 8.753, 5.515, 1.889, 1.613],
          [83.13, 8.31, 5.235, 1.793, 1.531],

          [ .4149  .03379   - .4757  - 0.581   - .5126 ]
          [                                            ]
          [ 0.369  - .3657  - .4298   .7237    - .1469 ]
          [                                            ]
          [ .3959  - .2178  - .2181  - .2749    .8201  ]]
          [                                            ]
          [ .5548   .7744    .1857    .2319    .06498  ]
          [                                            ]
          [ .4765  - .4669   0.712   - .09605  - .1969 ]

          (%i5) /* accumulated percentages  */
              block([ap: copy(res[2])],
                for k:2 thru length(ap) do ap[k]: ap[k]+ap[k-1],
                ap);
          (%o5)                 [83.13, 91.44, 96.68, 98.47, 100.0]
          (%i6) /* sample dimension */
                p: length(first(res));
          (%o6)                                  5
          (%i7) /* plot percentages to select number of
                   principal components for further work */
               draw2d(
                  fill_density = 0.2,
                  apply(bars, makelist([k, res[2][k], 1/2], k, p)),
                  points_joined = true,
                  point_type    = filled_circle,
                  point_size    = 3,
                  points(makelist([k, res[2][k]], k, p)),
                  xlabel = "Variances",
                  ylabel = "Percentages",
                  xtics  = setify(makelist([concat("PC",k),k], k, p))) $

     In case de covariance matrix is known, it can be passed to the function, but option data=false must be used.

          (%i1) load ("descriptive")$
          (%i2) S: matrix([1,-2,0],[-2,5,0],[0,0,2]);
                                          [  1   - 2  0 ]
                                          [             ]
          (%o2)                           [ - 2   5   0 ]
                                          [             ]
                                          [  0    0   2 ]
          (%i3) fpprintprec:4 $
          (%i4) /* the argument is a covariance matrix */
                res: principal_components(S, data=false);
          0 errors, 0 warnings
                                                            [ - .3827  0.0  .9239 ]
                                                            [                     ]
          (%o4) [[5.828, 2.0, .1716], [72.86, 25.0, 2.145], [  .9239   0.0  .3827 ]]
                                                            [                     ]
                                                            [   0.0    1.0   0.0  ]
          (%i5) /* transformation to get the principal components
                   from original records */
                matrix([a1,b2,c3],[a2,b2,c2]).last(res);
                       [ .9239 b2 - .3827 a1  1.0 c3  .3827 b2 + .9239 a1 ]
          (%o5)        [                                                  ]
                       [ .9239 b2 - .3827 a2  1.0 c2  .3827 b2 + .9239 a2 ]

     Categories: Package descriptive

Functions and Variables for statistical graphs
==============================================

 -- Function: barsplot (DATA1, DATA2, ..., OPTION_1, OPTION_2, ...)

     Plots bars diagrams for discrete statistical variables, both for one or multiple samples.

     DATA can be a list of outcomes representing one sample, or a matrix of M rows and N columns, representing N samples of size M each.

     Available options are:

       * BOX_WIDTH (default, 3/4): relative width of rectangles. This value must be in the range [0,1].

       * GROUPING (default, clustered): indicates how multiple samples are shown. Valid values are: clustered and stacked.

       * GROUPS_GAP (default, 1): a positive integer number representing the gap between two consecutive groups of bars.

       * BARS_COLORS (default, []): a list of colors for multiple samples. When there are more samples than specified colors, the extra necessary colors are chosen at random. See color to learn more about them.

       * FREQUENCY (default, absolute): indicates the scale of the ordinates. Possible values are:  absolute, relative, and percent.

       * ORDERING (default, orderlessp): possible values are orderlessp or ordergreatp, indicating how statistical outcomes should be ordered on the X-axis.

       * SAMPLE_KEYS (default, []): a list with the strings to be used in the legend. When the list length is other than 0 or the number of samples, an error message is returned.

       * START_AT (default, 0): indicates where the plot begins to be plotted on the x axis.

       * All global draw options, except xtics, which is internally assigned by barsplot. If you want to set your own values for this option or want to build complex scenes, make use of barsplot_description. See example below.

       * The following local draw-pkg options: key color_draw fill_color fill_density and line_width See also barsplot

     There is also a function wxbarsplot for creating embedded histograms in interfaces wxMaxima and iMaxima.  barsplot in a multiplot context.

     Examples:

     Univariate sample in matrix form. Absolute frequencies.

          (%i1) load ("descriptive")$
          (%i2) m : read_matrix (file_search ("biomed.data"))$

          (%i3) barsplot(
                  col(m,2),
                  title        = "Ages",
                  xlabel       = "years",
                  box_width    = 1/2,
                  fill_density = 3/4)$

     Two samples of different sizes, with relative frequencies and user declared colors.

          (%i1) load ("descriptive")$
          (%i2) l1:makelist(random(10),k,1,50)$
          (%i3) l2:makelist(random(10),k,1,100)$

          (%i4) barsplot(
                  l1,l2,
                  box_width    = 1,
                  fill_density = 1,
                  bars_colors  = [black, grey],
                  frequency = relative,
                  sample_keys = ["A", "B"])$

     Four non numeric samples of equal size.

          (%i1) load ("descriptive")$

          (%i2) barsplot(
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  title  = "Asking for something to four groups",
                  ylabel = "# of individuals",
                  groups_gap   = 3,
                  fill_density = 0.5,
                  ordering     = ordergreatp)$

     Stacked bars.

          (%i1) load ("descriptive")$

          (%i2) barsplot(
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
                  title  = "Asking for something to four groups",
                  ylabel = "# of individuals",
                  grouping     = stacked,
                  fill_density = 0.5,
                  ordering     = ordergreatp)$

     For bars diagrams related options, see barsplot of package draw-pkg See also functions histogram and piechart

     Categories: Package descriptive Plotting

 -- Function: barsplot_description (...)

     Function barsplot_description creates a graphic object suitable for creating complex scenes, together with other graphic objects.

     Example: barsplot in a multiplot context.

          (%i1) load ("descriptive")$
          (%i2) l1:makelist(random(10),k,1,50)$
          (%i3) l2:makelist(random(10),k,1,100)$
          (%i4) bp1 :
                  barsplot_description(
                   l1,
                   box_width = 1,
                   fill_density = 0.5,
                   bars_colors = [blue],
                   frequency = relative)$
          (%i5) bp2 :
                  barsplot_description(
                   l2,
                   box_width = 1,
                   fill_density = 0.5,
                   bars_colors = [red],
                   frequency = relative)$
          (%i6) draw(gr2d(bp1), gr2d(bp2))$

     Categories: Package descriptive Plotting

 -- Function: boxplot (DATA)
     boxplot (DATA, OPTION_1, OPTION_2, ...)

     This function plots box-and-whisker diagrams. Argument DATA can be a list, which is not of great interest, since these diagrams are mainly used for comparing different samples, or a matrix, so it is possible to compare two or more components of a multivariate statistical variable. But it is also allowed DATA to be a list of samples with possible different sample sizes, in fact this is the only function in package descriptive that admits this type of data structure.

     The box is plotted from the first quartile to the third, with an horizontal segment situated at the second quartile or median. By default, lower and upper whiskers are plotted at the minimum and maximum values, respectively. Option RANGE can be used to indicate that values greater than quantile(x,3/4)+range*(quantile(x,3/4)-quantile(x,1/4)) or less than quantile(x,1/4)-range*(quantile(x,3/4)-quantile(x,1/4)) must be considered as outliers, in which case they are plotted as isolated points, and the whiskers are located at the extremes of the rest of the sample.

     Available options are:

       * BOX_WIDTH (default, 3/4): relative width of boxes. This  value must be in the range [0,1].

       * BOX_ORIENTATION (default, vertical): possible values: vertical and horizontal.

       * RANGE (default, inf): positive coefficient of the interquartilic range to set outliers boundaries.

       * OUTLIERS_SIZE (default, 1): circle size for isolated outliers.

       * All draw options, except points_joined, point_size, point_type, xtics, ytics, xrange, and yrange, which are internally assigned by boxplot. If you want to set your own values for this options or want to build complex scenes, make use of boxplot_description.

       * The following local draw options: key, color, and line_width.

     There is also a function wxboxplot for creating embedded histograms in interfaces wxMaxima and iMaxima.

     Examples:

     Box-and-whisker diagram from a multivariate sample.

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix(file_search("wind.data"))$

          (%i3) boxplot(s2,
                  box_width  = 0.2,
                  title      = "Windspeed in knots",
                  xlabel     = "Stations",
                  color      = red,
                  line_width = 2)$

     Box-and-whisker diagram from three samples of different sizes.

          (%i1) load ("descriptive")$

          (%i2) A :
                 [[6, 4, 6, 2, 4, 8, 6, 4, 6, 4, 3, 2],
                  [8, 10, 7, 9, 12, 8, 10],
                  [16, 13, 17, 12, 11, 18, 13, 18, 14, 12]]$

          (%i3) boxplot (A, box_orientation = horizontal)$

     Option RANGE can be used to handle outliers.

          (%i1) load ("descriptive")$
          (%i2) B: [[7, 15, 5, 8, 6, 5, 7, 3, 1],
                    [10, 8, 12, 8, 11, 9, 20],
                    [23, 17, 19, 7, 22, 19]] $

          (%i3) boxplot (B, range=1)$
          (%i4) boxplot (B, range=1.5, box_orientation = horizontal)$

          (%i5) draw2d(
                  boxplot_description(
                    B,
                    range            = 1.5,
                    line_width       = 3,
                    outliers_size    = 2,
                    color            = red,
                    background_color = light_gray),
                  xtics = {["Low",1],["Medium",2],["High",3]}) $

     Categories: Package descriptive Plotting

 -- Function: boxplot_description (...)

     Function boxplot_description creates a graphic object suitable for creating complex scenes, together with other graphic objects.

     Categories: Package descriptive Plotting

 -- Function: histogram
     histogram (LIST)
     histogram (LIST, OPTION_1, OPTION_2, ...)
     histogram (ONE_COLUMN_MATRIX)
     histogram (ONE_COLUMN_MATRIX, OPTION_1, OPTION_2, ...)
     histogram (ONE_ROW_MATRIX)
     histogram (ONE_ROW_MATRIX, OPTION_1, OPTION_2, ...)

     Constructs and displays a histogram from a data sample. Data must be stored as a list of numbers, or a matrix of one row or one column.

     Optional arguments:

       * nclasses (default, 10): the number of classes (also called bins) in the histogram, or a list of two numbers (the least and greatest values included in the histogram), or a list of three numbers (the least and greatest values included in the histogram, and the number of classes), or a set containing the endpoints of the class intervals, or a symbol specifying the name of one of three algorithms to automatically determine the number of classes: fd (Ref. [1]), scott (Ref. [2]), or sturges (Ref. [3]).

          A class interval excludes its left endpoint and includes its right endpoint, except for the first interval, which includes both the left and right endpoints. It is assumed that class intervals are contiguous. That is, the right endpoint of one interval is equal to the left endpoint of the next.

       * frequency (default, absolute): indicates the scale of the vertical axis. Possible values are:  absolute (heights of bars add up to number of data), relative (heights of bars add up to 1), percent (heights of bars add up to 100), and density (total area of histogram is 1).

       * htics (default, auto): format of tic marks on the horizontal axis. Possible values are: auto (tics are placed automatically), endpoints (tics are placed at the divisions between classes), intervals (classes are labeled with the corresponding intervals), or a list of labels, one for each class.

       * All global draw options, except xrange, yrange, and xtics, which are internally assigned by histogram. If you want to set your own values for these options, make use of histogram_description.

       * The following local draw-pkg options: key fill_color fill_density and line_width Note that the outlines of bars, as well as the interior of bars when fill_density is nonzero, are drawn with fill_color, not color.

     histogram honors the global option histogram_skyline. When histogram_skyline is true, histogram and histogram_description construct "skyline" plots, which shows the outline of the histogram bars, instead of drawing all the vertical segments. Otherwise (the default), histograms are displayed with bars showing vertical segments.

     There is also a function wxhistogram for creating embedded histograms in interfaces wxMaxima and iMaxima.

     See also continuous_freq which, like histogram, counts data in intervals, but returns the counts instead of displaying a graphic representation.

     See also barsplot

     Examples:

     A simple histogram with eight classes:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) histogram (
                     s1,
                     nclasses     = 8,
                     title        = "pi digits",
                     xlabel       = "digits",
                     ylabel       = "Absolute frequency",
                     fill_color   = grey,
                     fill_density = 0.6)$

     Setting the limits of the histogram to -2 and 12, with 3 classes. Also, we introduce predefined tics:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) histogram (
                     s1,
                     nclasses     = [-2,12,3],
                     htics        = ["A", "B", "C"],
                     terminal     = png,
                     fill_color   = "#23afa0",
                     fill_density = 0.6)$

     Bounds for varying class widths.

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) histogram (s1, nclasses = {0,3,6,7,11})$

     Freedman-Diaconis formula for the number of classes.

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) histogram(s1, nclasses=fd) $

     References:

     [1] Freedman, D., and Diaconis, P. (1981) On the histogram as a density estimator: L_2 theory. Zeitschrift für Wahrscheinlichkeitstheorie und verwandte Gebiete 57, 453-476.

     [2] Scott, D. W. (1979) On optimal and data-based histograms. Biometrika 66, 605-610.

     [3] Sturges, H. A. (1926) The choice of a class interval. Journal of the American Statistical Association 21, 65-66.

     Categories: Package descriptive Plotting

 -- Function: histogram_description (...)

     Creates a graphic object which represents a histogram. Such an object is suitable for creating complex scenes together with other graphic objects, to be displayed by draw2d.

     histogram_description takes the same arguments as the stand-alone function histogram. See histogram for more information.

     Example:

     We make use of histogram_description for setting xrange and adding an explicit curve into the scene:

          (%i1) load ("descriptive")$
          (%i2) ( load("distrib"),
                  m: 14, s: 2,
                  s2: random_normal(m, s, 1000) ) $
          (%i3) draw2d(
                  grid   = true,
                  xrange = [5, 25],
                  histogram_description(
                    s2,
                    nclasses     = 9,
                    frequency    = density,
                    fill_density = 0.5),
                  explicit(pdf_normal(x,m,s), x, m - 3*s, m + 3* s))$

     Categories: Package descriptive Plotting

 -- Option variable: histogram_skyline
     Default value: false

     When histogram_skyline is true, histogram and histogram_description construct "skyline" plots, which shows the outline of the histogram bars, instead of drawing all the vertical segments.

     The outline is drawn with the current fill_color (not the current color). The interior of the histogram is filled with fill_color, but only if fill_density is nonzero.

     Otherwise, histograms are displayed with bars showing vertical segments.

     Example:

     Construct a skyline histogram, and an ordinary histogram for comparison, on the same plot.

          (%i1) load ("descriptive") $
          (%i2) L: read_list (file_search ("pidigits.data")) $
          (%i3) histogram_skyline: true $
          (%i4) skyline_hist: histogram_description (L) $
          (%i5) histogram_skyline: false $
          (%i6) ordinary_hist: histogram_description (L) $
          (%i7) draw (gr2d (skyline_hist), gr2d (ordinary_hist)) $

     Continuing the preceding example. Set display options for fill_color and fill_density.

          (%i8) histogram_skyline: true $
          (%i9) skyline_hist: histogram_description (L, fill_color = blue, fill_density = 0.2) $
          (%i10) histogram_skyline: false $
          (%i11) ordinary_hist: histogram_description (L, fill_color = blue, fill_density = 0.2) $
          (%i12) draw (gr2d (skyline_hist), gr2d (ordinary_hist)) $

     Categories: Package descriptive Plotting

 -- Function: piechart
     piechart (LIST)
     piechart (LIST, OPTION_1, OPTION_2, ...)
     piechart (ONE_COLUMN_MATRIX)
     piechart (ONE_COLUMN_MATRIX, OPTION_1, OPTION_2, ...)
     piechart (ONE_ROW_MATRIX)
     piechart (ONE_ROW_MATRIX, OPTION_1, OPTION_2, ...)

     Similar to barsplot, but plots sectors instead of rectangles.

     Available options are:

       * SECTOR_COLORS (default, []): a list of colors for sectors. When there are more sectors than specified colors, the extra necessary colors are chosen at random. See color to learn more about them.

       * PIE_CENTER (default, [0,0]): diagram's center.

       * PIE_RADIUS (default, 1): diagram's radius.

       * All global draw options, except key, which is internally assigned by piechart. If you want to set your own values for this option or want to build complex scenes, make use of piechart_description.

       * The following local draw options: key, color, fill_density and line_width. See also ellipse

     There is also a function wxpiechart for creating embedded histograms in interfaces wxMaxima and iMaxima.

     Example:

          (%i1) load ("descriptive")$
          (%i2) s1 : read_list (file_search ("pidigits.data"))$
          (%i3) piechart(
                  s1,
                  xrange  = [-1.1, 1.3],
                  yrange  = [-1.1, 1.1],
                  title   = "Digit frequencies in pi")$

     See also function barsplot

     Categories: Package descriptive Plotting

 -- Function: piechart_description (...)

     Function piechart_description creates a graphic object suitable for creating complex scenes, together with other graphic objects.

     Categories: Package descriptive Plotting

 -- Function: scatterplot
     scatterplot (LIST)
     scatterplot (LIST, OPTION_1, OPTION_2, ...)
     scatterplot (MATRIX)
     scatterplot (MATRIX, OPTION_1, OPTION_2, ...)

     Plots scatter diagrams both for univariate (LIST) and multivariate (MATRIX) samples.

     Available options are the same admitted by histogram.

     There is also a function wxscatterplot for creating embedded histograms in interfaces wxMaxima and iMaxima.

     Examples:

     Univariate scatter diagram from a simulated Gaussian sample.

          (%i1) load ("descriptive")$
          (%i2) load ("distrib")$

          (%i3) scatterplot(
                  random_normal(0,1,200),
                  xaxis      = true,
                  point_size = 2,
                  dimensions = [600,150])$

     Two dimensional scatter plot.

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$

          (%i3) scatterplot(
                 submatrix(s2, 1,2,3),
                 title      = "Data from stations #4 and #5",
                 point_type = diamant,
                 point_size = 2,
                 color      = blue)$

     Three dimensional scatter plot.

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$
          (%i3) scatterplot(submatrix (s2, 1,2), nclasses=4)$

     Five dimensional scatter plot, with five classes histograms.

          (%i1) load ("descriptive")$
          (%i2) s2 : read_matrix (file_search ("wind.data"))$

          (%i3) scatterplot(
                  s2,
                  nclasses     = 5,
                  frequency    = relative,
                  fill_color   = blue,
                  fill_density = 0.3,
                  xtics        = 5)$

     For plotting isolated or line-joined points in two and three dimensions, see points. See also histogram

     Categories: Package descriptive Plotting

 -- Function: scatterplot_description (...)

     Function scatterplot_description creates a graphic object suitable for creating complex scenes, together with other graphic objects.

     Categories: Package descriptive Plotting

 -- Function: starplot (DATA1, DATA2, ..., OPTION_1, OPTION_2, ...)

     Plots star diagrams for discrete statistical variables, both for one or multiple samples.

     DATA can be a list of outcomes representing one sample, or a matrix of M rows and N columns, representing N samples of size M each.

     Available options are:

       * STARS_COLORS (default, []): a list of colors for multiple samples. When there are more samples than specified colors, the extra necessary colors are chosen at random. See color to learn more about them.

       * FREQUENCY (default, absolute): indicates the scale of the radii. Possible values are:  absolute and relative.

       * ORDERING (default, orderlessp): possible values are orderlessp or ordergreatp, indicating how statistical outcomes should be ordered.

       * SAMPLE_KEYS (default, []): a list with the strings to be used in the legend. When the list length is other than 0 or the number of samples, an error message is returned.

       * STAR_CENTER (default, [0,0]): diagram's center.

       * STAR_RADIUS (default, 1): diagram's radius.

       * All global draw options, except points_joined, point_type, and key, which are internally assigned by starplot. If you want to set your own values for this options or want to build complex scenes, make use of starplot_description.

       * The following local draw option: line_width.

     There is also a function wxstarplot for creating embedded histograms in interfaces wxMaxima and iMaxima.

     Example:

     Plot based on absolute frequencies. Location and radius defined by the user.

          (%i1) load ("descriptive")$
          (%i2) l1: makelist(random(10),k,1,50)$
          (%i3) l2: makelist(random(10),k,1,200)$

          (%i4) starplot(
                  l1, l2,
                  stars_colors = [blue,red],
                  sample_keys = ["1st sample", "2nd sample"],
                  star_center = [1,2],
                  star_radius = 4,
                  proportional_axes = xy,
                  line_width = 2 ) $

     Categories: Package descriptive Plotting

 -- Function: starplot_description (...)

     Function starplot_description creates a graphic object suitable for creating complex scenes, together with other graphic objects.

     Categories: Package descriptive Plotting

 -- Function: stemplot
     stemplot (DATA)
     stemplot (DATA, OPTION)

     Plots stem and leaf diagrams.

     Unique available option is:

       * LEAF_UNIT (default, 1): indicates the unit of the leaves; must be a power of 10.

     Example:

          (%i1) load ("descriptive")$
          (%i2) load("distrib")$

          (%i3) stemplot(
                  random_normal(15, 6, 100),
                  leaf_unit = 0.1);
          -5|4
           0|37
           1|7
           3|6
           4|4
           5|4
           6|57
           7|0149
           8|3
           9|1334588
          10|07888
          11|01144467789
          12|12566889
          13|24778
          14|047
          15|223458
          16|4
          17|11557
          18|000247
          19|4467799
          20|00
          21|1
          22|2335
          23|01457
          24|12356
          25|455
          27|79
          key: 6|3 =  6.3
          (%o3)                  done

     Categories: Package descriptive Plotting