MathMath

Help › Functions

Statistics

mean stdev Stdev max min hist histogram var Var median mode gmean hmean skew kurt cvar corr

mean(A, …) As in Mathcad

The average of all the elements.

Takes numbers, vectors and matrices, any mix, and averages every element. See also stdev, var and median.

Units

The answer is in the units of the first element.

Refused

  • Elements that aren't numbers.
mean⎝⎛​⎝⎛​126​⎠⎞​⎠⎞​=3
mean(2,4,9)=5

stdev(A, …) As in Mathcad

The population standard deviation of all the elements: the root of the mean squared distance from the mean.

Divides by n, the number of elements. Stdev divides by n − 1 instead, for a sample. See also mean.

Units

The answer is in the units of the first element.

Refused

  • Elements that aren't numbers.
stdev⎝⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎛​⎝⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎛​24445579​⎠⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎞​⎠⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎞​=2

Stdev(A, …) As in Mathcad

The sample standard deviation of all the elements: divides by n − 1.

Use it when the elements are a sample of something larger. stdev divides by n, for the whole population, and so is a little smaller. One element alone gives NaN, as 0 divided by 0.

Units

The answer is in the units of the first element.

Refused

  • Elements that aren't numbers.
Stdev⎝⎛​⎝⎛​123​⎠⎞​⎠⎞​=1
stdev⎝⎛​⎝⎛​123​⎠⎞​⎠⎞​=0.816

max(A, …) As in Mathcad

The largest element.

Takes numbers, vectors and matrices, any mix. See also min.

Units

The elements must be in compatible units; the answer keeps them.

Refused

  • No elements.
  • Elements in different units.
max⎝⎛​⎝⎛​394​⎠⎞​⎠⎞​=9
max(2,7,5)=7

min(A, …) As in Mathcad

The smallest element.

Takes numbers, vectors and matrices, any mix. See also max.

Units

The elements must be in compatible units; the answer keeps them.

Refused

  • No elements.
  • Elements in different units.
min⎝⎛​⎝⎛​394​⎠⎞​⎠⎞​=3
min(2,7,5)=2

hist(bounds, data) As in Mathcad

A vector of counts: how many data values fall in each interval between consecutive bounds.

bounds is a vector in rising order. Interval i holds the values above bounds[i] up to and including bounds[i+1], so a value on a boundary counts in the interval to its left. Values outside all the intervals are not counted. The answer has one fewer elements than bounds. histogram picks equal intervals for you.

hist⎝⎜⎜⎛​⎝⎛​024​⎠⎞​,⎝⎜⎜⎛​1234​⎠⎟⎟⎞​⎠⎟⎟⎞​=(22​)

histogram(n, data) As in Mathcad

A histogram with n equal intervals spanning the data: a matrix whose first column is each interval's midpoint and second its count.

The intervals run from the smallest value to the largest, and the smallest value counts in the first. A value on a boundary counts in the interval to its left. For intervals you choose, use hist. The two columns plot directly against each other.

Units

The midpoints take the data's units; the counts have none.

Refused

  • n below 1.
histogram⎝⎜⎜⎛​2,⎝⎜⎜⎛​1234​⎠⎟⎟⎞​⎠⎟⎟⎞​=(1.753.25​22​)

var(A, …) As in Mathcad

The variance of all the elements, dividing by their number n: the population variance.

Var divides by n − 1, for a sample. Takes numbers, vectors and matrices, any mix. Its square root is stdev.

Units

In the square of the elements' units.

V≔⎝⎜⎜⎜⎜⎛​24459​⎠⎟⎟⎟⎟⎞​
var(V)=5.36

Var(A, …) As in Mathcad

The sample variance of all the elements, dividing by n − 1.

var divides by n. Its square root is Stdev.

Units

In the square of the elements' units.

Refused

  • Fewer than two values.
V≔⎝⎜⎜⎜⎜⎛​24459​⎠⎟⎟⎟⎟⎞​
Var(V)=6.7

median(A, …) As in Mathcad

The middle value of all the elements, or the mean of the middle two when there's an even number.

Units

In the elements' units.

median⎝⎜⎜⎛​⎝⎜⎜⎛​2945​⎠⎟⎟⎞​⎠⎟⎟⎞​=4.5

mode(A, …) As in Mathcad

The value that appears most often among all the elements.

Refused

  • No value appearing more than once, or two values tied for most often, as in Mathcad.
mode⎝⎜⎜⎜⎜⎛​⎝⎜⎜⎜⎜⎛​24459​⎠⎟⎟⎟⎟⎞​⎠⎟⎟⎟⎟⎞​=4

gmean(A, …) As in Mathcad

The geometric mean of all the elements: the nth root of their product.

Refused

  • A value of 0 or below.
gmean⎝⎛​⎝⎛​124​⎠⎞​⎠⎞​=2

hmean(A, …) As in Mathcad

The harmonic mean of all the elements: n over the sum of their reciprocals.

Refused

  • A value of 0 or below.
hmean⎝⎛​⎝⎛​124​⎠⎞​⎠⎞​=1.714

skew(A, …) As in Mathcad

The sample skewness of all the elements: how lopsided they are, positive when the long tail is above the mean.

n/((n − 1)(n − 2))·Σ((x − mean)/s)³, with s the sample standard deviation, as in Mathcad.

Refused

  • Fewer than three values.
skew⎝⎜⎜⎜⎜⎛​⎝⎜⎜⎜⎜⎛​24459​⎠⎟⎟⎟⎟⎞​⎠⎟⎟⎟⎟⎞​=1.228

kurt(A, …) As in Mathcad

The sample kurtosis of all the elements, in excess of a normal distribution's: positive for heavy tails.

Mathcad's formula, with the sample standard deviation and the n − 1, n − 2, n − 3 corrections.

Refused

  • Fewer than four values.
kurt⎝⎜⎜⎜⎜⎛​⎝⎜⎜⎜⎜⎛​24459​⎠⎟⎟⎟⎟⎞​⎠⎟⎟⎟⎟⎞​=2.399

cvar(A, B) As in Mathcad

The covariance of two arrays of the same size, dividing by n.

Elements pair up by position. cvar(A, A) is var(A).

Units

In the product of the two arrays' units.

Refused

  • Arrays of different sizes.
cvar⎝⎛​⎝⎛​123​⎠⎞​,⎝⎛​247​⎠⎞​⎠⎞​=1.667

corr(A, B) As in Mathcad

The correlation of two arrays of the same size: from −1 to 1, 1 when one rises in step with the other.

Refused

  • Arrays of different sizes.
  • An array whose values are all the same.
corr⎝⎛​⎝⎛​123​⎠⎞​,⎝⎛​247​⎠⎞​⎠⎞​=0.993