Maxima – 224 – descriptive – 1

elea4

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.709.

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")$

Compiling /usr/share/maxima/5.41.0/share/draw/grcommon.lisp.
End of Pass 1.
End of Pass 2.
OPTIMIZE levels: Safety=2, Space=3, Speed=3
Finished compiling 
/home/juhan/.maxima/binary/5_41_0/gcl/GCL_2_6_12/share/draw/grcommon.o.
Compiling /usr/share/maxima/5.41.0/share/draw/gnuplot.lisp.
End of Pass 1.

;; Note: Tail-recursive call of BIPART was replaced by iteration.
;; Note: Tail-recursive call of BIPART was replaced by iteration.
End of Pass 2.
OPTIMIZE levels: Safety=2, Space=3, Speed=3
Finished compiling 
/home/juhan/.maxima/binary/5_41_0/gcl/GCL_2_6_12/share/draw/gnuplot.o.
Compiling /usr/share/maxima/5.41.0/share/draw/vtk.lisp.
End of Pass 1.
End of Pass 2.
OPTIMIZE levels: Safety=2, Space=3, Speed=3
Finished compiling 
/home/juhan/.maxima/binary/5_41_0/gcl/GCL_2_6_12/share/draw/vtk.o.
Compiling /usr/share/maxima/5.41.0/share/draw/picture.lisp.
End of Pass 1.
End of Pass 2.
OPTIMIZE levels: Safety=2, Space=3, Speed=3
Finished compiling 
/home/juhan/.maxima/binary/5_41_0/gcl/GCL_2_6_12/share/draw/picture.o.
(%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,

(%i5) map (mean, [[a, b, c], [d, e]]);
                               c + b + a  e + d
(%o5)                         [---------, -----]
                                   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

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

and multivariate samples in matrices as in

(%i7) 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 ]
(%o7)                          [              ]
                               [ 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:

* 224 $ find /usr -name pidigits.data
/usr/share/maxima/5.41.0/share/descriptive/pidigits.data

* 224 $ head /usr/share/maxima/5.41.0/share/descriptive/pidigits.data
      3
      1
      4
      1
      5
      9
      2
      6
      5
      3
* 224 $

In order to load these digits in Maxima,

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

(%i9) length (s1);
(%o9)                                 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 discused 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:

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

(%i11) length (s2);
(%o11)                                100
(%i12) s2 [%]; /* last record */
(%o12)                  [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,

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

(%i14) length (s3);
(%o14)                                100
(%i15) s3 [1]; /* first record */
(%o15)                  [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,

(%i16) a : 1$

(%i17) matrix ([a, 3], [b, 5]);
                                   [ 1  3 ]
(%o17)                             [      ]
                                   [ b  5 ]

Posta un commento o usa questo indirizzo per il trackback.

Trackback

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: