Library - stat

stat is a library which adds to LME advanced statistical functions.

The following statement makes available functions defined in stat:

use stat

bootstrp

Bootstrap estimate.

Syntax

(stats, samples) = bootstrp(n, fun, D1, ...)

Description

bootstrp(n,fun,D) picks random observations from the rows of matrix (or column vector) D to form n sets which have all the same size as D; then it applies function fun (a function name or reference or an inline function) to each set and returns the results in the columns of stats. Up to three different set of data can be provided.

bootstrp gives an idea of the robustness of the estimate with respect to the choice of the observations.

Example

D = rand(1000, 1);
bootstrp(5, @std, D)
    0.2938
    0.2878
    0.2793
    0.2859
    0.2844

geomean

Geometric mean of a set of values.

Syntax

m = geomean(M)
m = geomean(M, dim)

Description

geomean(M) gives the geometric mean of the columns of matrix M or of the row vector M. The dimension along which geomean proceeds may be specified with a second argument.

The geometric mean of vector v of length n is defined as prod(v)^(1/n).

See also

harmmean, mean

harmmean

Harmonic mean of a set of values.

Syntax

m = harmmean(M)
m = harmmean(M, dim)

Description

harmmean(M) gives the harmonic mean of the columns of matrix M or of the row vector M. The dimension along which harmmean proceeds may be specified with a second argument.

The inverse of the harmonic mean is the arithmetic mean of the inverse of the observations.

See also

geomean, mean

iqr

Interquartile range.

Syntax

m = iqr(M)
m = iqr(M, dim)

Description

iqr(M) gives the interquartile range of the columns of matrix M or of the row vector M. The dimension along which iqr proceeds may be specified with a second argument.

The interquartile range is the difference between the 75th percentile and the 25th percentile.

See also

trimmean, prctile

kurtosis

Kurtosis of a set of values.

Syntax

k = kurtosis(M)
k = kurtosis(M, dim)

Description

kurtosis(M) gives the kurtosis of the columns of matrix M or of the row vector M. The dimension along which kurtosis proceeds may be specified with a second argument.

The kurtosis measures how much values are far away from the mean. It is 3 for a normal distribution, and positive for a distribution which has more values far away from the mean.

Example

kurtosis(rand(1, 10000))
  1.8055

See also

var, skewness, moment

mad

Mean absolute deviation.

Syntax

m = mad(M)
m = mad(M, dim)

Description

mad(M) gives the mean absolute deviation of the columns of matrix M or of the row vector M. The dimension along which mad proceeds may be specified with a second argument.

The mean absolute deviation is the mean of the absolute value of the deviation between each observation and the arithmetic mean.

See also

trimmean, mean

moment

Moment of a set of values.

Syntax

m = moment(M, order)
m = moment(M, order, dim)

Description

moment(M,order) gives the moment of the specified order of the columns of matrix M or of the row vector M. The dimension along which moment proceeds may be specified with a third argument.

Example

moment(randn(1, 10000), 3)
  3.011

See also

var, skewness, kurtosis

nanmean

Mean after discarding NaNs.

Syntax

y = nanmean(M)
y = nanmean(M, dim)

Description

nanmean(v) returns the arithmetic mean of the elements of vector v. nanmean(M) returns a row vector whose elements are the means of the corresponding columns of matrix M. nanmean(M,dim) returns the mean of matrix M along dimension dim; the result is a row vector if dim is 1, or a column vector if dim is 2. In all cases, NaN values are ignored.

Examples

nanmean([1,2,nan;nan,6,7])
  1 4 7
nanmean([1,2,nan;nan,6,7],2)
  1.5
  6.5
nanmean([nan,nan])
  nan

See also

nanmedian, nanstd, mean

nanmedian

Median after discarding NaNs.

Syntax

y = nanmedian(M)
y = nanmedian(M, dim)

Description

nanmedian(v) gives the median of vector v, i.e. the value x such that half of the elements of v are smaller and half of the elements are larger. NaN values are ignored.

nanmedian(M) gives a row vector which contains the median of the columns of M. With a second argument, nanmedian(M,dim) operates along dimension dim.

See also

nanmean, median

nanstd

Standard deviation after discarding NaNs.

Syntax

y = nanstd(M)
y = nanstd(M, p)
y = nanstd(M, p, dim)

Description

nanstd(v) gives the standard deviation of vector v, normalized by 1 less than the number of values. NaNs are ignored. With a second argument, nanstd(v,p) normalizes by 1 less than the number of values if p is true, or by the number of values if p is false.

nanstd(M) gives a row vector which contains the standard deviation of the columns of M. With a third argument, median(M,p,dim) operates along dimension dim.

See also

nanmean, std

nansum

Sum after discarding NaNs.

Syntax

y = nansum(M)
y = nansum(M, dim)

Description

nansum(v) returns the sum of the elements of vector v. NaNs are ignored. nansum(M) returns a row vector whose elements are the sums of the corresponding columns of matrix M. nansum(M,dim) returns the sum of matrix M along dimension dim; the result is a row vector if dim is 1, or a column vector if dim is 2.

See also

nanmean, sum

pdist

Pairwise distance between observations.

Syntax

d = pdist(M)
d = pdist(M, metric)
d = pdist(M, metric, p)

Description

pdist calculates the distance between pairs of rows of the observation matrix M. The result is a column vector which contains the distances between rows i and j with i<j. It can be resized to a square matrix with squareform.

By default, the metric used to calculate the distance is the euclidean distance; but it can be specified with a second argument:

euclideuclidean distance
seuclidstandardized euclidean distance
mahalMahalanobis distance
cityblocksum of absolute values
minkowskiMinkowski metric with paramater p

See also

squareform

prctile

Percentile.

Syntax

m = prctile(M, prc)
m = prctile(M, prc, dim)

Description

prctile(M,prc) gives the smallest values larger than prc of the elements of each column of matrix M or of the row vector M. The dimension along which prctile proceeds may be specified with a third argument.

See also

trimmean, iqr

range

Mean absolute deviation.

Syntax

m = range(M)
m = range(M, dim)

Description

range(M) gives the differences between the maximum and minimum values of the columns of matrix M or of the row vector M. The dimension along which range proceeds may be specified with a second argument.

See also

iqr

skewness

Skewness of a set of values.

Syntax

s = skewness(M)
s = skewness(M, dim)

Description

skewness(M) gives the skewness of the columns of matrix M or of the row vector M. The dimension along which skewness proceeds may be specified with a second argument.

The skewness measures how asymmetric a distribution is. It is 0 for a symmetric distribution, and positive for a distribution which has more values much larger than the mean.

Example

skewness(randn(1, 10000).^2)
  2.6833

See also

var, kurtosis, moment

squareform

Resize the output of pdist to a square matrix.

Syntax

D = squareform(d)

Description

squareform(d) resize d, which should be the output of pdist, into a symmetric square matrix D, so that the distance between observations i and j is D(i,j).

See also

pdist

trimmean

Trimmed mean of a set of values.

Syntax

m = trimmean(M, prc)
m = trimmean(M, prc, dim)

Description

trimmean(M,prc) gives the arithmetic mean of the columns of matrix M or of the row vector M once prc/2 percent of the values have been removed from each end. The dimension along which trimmean proceeds may be specified with a third argument.

trimmean is less sensitive to outliers than the regular arithmetic mean.

See also

prctile, geomean, mean

var

Variance of a set of values.

Syntax

s2 = var(M)
s2 = var(M, p)
s2 = var(M, p, dim)

Description

var(M) gives the variance of the columns of matrix M or of the row vector M. The variance is normalized with the number of observations minus 1, or by the number of observations if a second argument is true. The dimension along which kurtosis proceeds may be specified with a third argument.

See also

kurtosis, skewness, moment

zscore

Z score (normalized deviation).

Syntax

Y = zscore(X)
Y = zscore(X, dim)

Description

zscore(X) normalizes the columns of matrix M or the row vector M by dividing subtracting their mean and dividing by their standard deviation. The dimension along which zscore proceeds may be specified with a second argument.


Copyright 2001, Calerga.

All rights reserved.