This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Session 6: Statistics


Objectives

In this session, we will learn the following:

  • Scilab functions to obtain basic statistics of the elements of a matrix

Scilab Functions for Statistics

Scilab provides the following functions for computing simple statistics of matrices:

  1. sum() - sum of array elements
  2. mean() - mean of array elements
  3. median() - median of array elements
  4. st_deviation() or stdev() - standard deviation of array elements
  5. stdevf() - standard deviation of array elements using frequencies
  6. nanstdev() - standard deviatin ignoring NaN (not a number) values

Each of these functions can be used in one of hree ways:

  1. To calculate the statistical quantity for all elements of the array. x = sum(a) computes the sum of all elements of matrix a and assigns it to x.
  2. y = sum(a, 'r') or y = sum(a, 1) return a row vector wherein the number in each column is the sum of the elements of the respective column of matrix a. Thus, y is a row vector having the same number of columns as matrix a.
  3. z = sum(a, 'c') or z = sum(a, 2) return a column vector wherein the number in each row is the sum of the elements of the respective row of matrix a. Thus, z is a column vector having the same number of of rows as matrix a.

Other functions can be used in the same way as the function sum().  Let us try out an example:

-->a = [73 24 89 94; 20 24 66 22; 55 22 31 32];
-->sum(a)
 ans  =
    552.
-->sum(a, 'r')
 ans  =
    148.  70.  186.  148.
-->sum(a, 'c')
 ans  =
    280.
    132.
    140.
-->sum(a, 1)
 ans  =
    148.  70.  186.  148.
-->sum(a, 2)
 ans  =
    280.
    132.
    140.

Task Discussion