## Methods

getZScore(x, mu, sigma)
mean(input)

std(X[, flag][, dim])
zscore(mat[, flag][, dim])

## Methods

static

### getZScore(x, mu, sigma) → number

Calculates the z-score for a point sampled from a Gaussian distribution. The z-score indicates how many standard deviations an element is from the meam and can be calculated using the following formula: `z = (x - mu) / sigma`.

#### Example

    // import modules
    var stat = require('qminer').statistics;
    // calculate the z-score of the sampled point
    var point = 10;
    var mu    = 5;
    var sigma = 5;
    var zScore = stat.getZScore(point, mu, sigma); // returns 1

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
x | Number |  | The sampled point.
mu | Number |  | Mean of the distribution.
sigma | Number |  | Variance of the distribution.

Returns

  `number`B The z-score of the sampled point.

static

### mean(input) → (number or module:la.Vector)

Calculates the mean value(s).

#### Example

    // import modules
    var qm = require('qminer');
    var la = qm.la;
    var statistics = qm.statistics;
    // create a matrix
    var mat = new la.Matrix([[1, 2, 1], [-1, 2, -1], [3, 2, 3]]);
    // calculate the mean of the matrix columns
    // vector contains the elements [1, 2, 1]
    var mean = statistics.mean(mat);

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
input | (module:la.Vector or module:la.Matrix) |  | The input the method is used on.

Returns

  `(number or module:la.Vector)`B
  1. If input is module:la.Vector, returns the mean of the vector.
  2. If input is module:la.Matrix, returns a vector of where the i-th value is the mean of i-th column.

static

### std(X[, flag][, dim]) → (number or module:la.Vector)

Calculates the standard deviation(s).

#### Example

    // import modules
    var qm = require('qminer');
    var la = qm.la;
    var statistics = qm.statistics;
    // create a matrix
    var mat = new la.Matrix([[1, 2, 1], [-1, 2, -1], [3, 2, 3]]);
    // calculate the standard deviation of the matrix columns
    var mean = statistics.std(mat);

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
X | (module:la.Vector or module:la.Matrix) |  | The input the method is used on.
flag | number | Yes | If set to to 0, it normalizes X by n-1; If set to 1 to, it normalizes by n. Defaults to `0`.
dim | number | Yes | Computes the standard deviations along the dimension of X specified by parameter `dim`. If set to 1, calculates the column standard deviation. If set to 2, calculates the row standard deviation. Defaults to `1`.

Returns

  `(number or module:la.Vector)`B
  1. If X is module:la.Vector, returns standard deviation of the vector.
  2. If X is module:la.Matrix, returns a vector where the i-th value is the standard deviation of the i-th column(row).

static

### zscore(mat[, flag][, dim]) → Object

Returns an object containing the standard deviation of each column of matrix, mean vector and z-score matrix.

#### Example

    // import modules
    var qm = require('qminer');
    var la = qm.la;
    var statistics = qm.statistics;
    // create a matrix
    var mat = new la.Matrix([[1, 2, 1], [-1, 2, -1], [3, 2, 3]]);
    // calculate the standard deviation of the matrix columns
    var mean = statistics.zscore(mat);

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
mat | module:la.Matrix |  | The matrix.
flag | number | Yes | If set to 0, it normalizes mat by n-1; if set to 1, it normalizes by n. Defaults to `0`.
dim | number | Yes | Computes the standard deviations along the dimension of mat specified by parameter `dim`. If set to 1, calculates the column standard deviation. If set to 2, calculates the row standard deviation. Defaults to `1`.

Returns

  `Object`B The object `zscoreResult` containing:
  `zscoreResult.sigma` - module:la.Vector of standard deviations of mat used to compute the z-scores.
  `zscoreResult.mu` - module:la.Vector of mean values of mat used to compute the z-scores.
  `zscoreResult.Z` - module:la.Matrix of z-scores that has mean 0 and variance 1.