stat is a library which adds to LME advanced statistical functions.
The following statement makes available functions defined in stat:
use stat
Bootstrap estimate.
(stats, samples) = bootstrp(n, fun, D1, ...)
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.
D = rand(1000, 1); bootstrp(5, @std, D) 0.2938 0.2878 0.2793 0.2859 0.2844
Geometric mean of a set of values.
m = geomean(M) m = geomean(M, dim)
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
Harmonic mean of a set of values.
m = harmmean(M) m = harmmean(M, dim)
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.
Interquartile range.
m = iqr(M) m = iqr(M, dim)
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.
Kurtosis of a set of values.
k = kurtosis(M) k = kurtosis(M, dim)
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.
kurtosis(rand(1, 10000)) 1.8055
Mean absolute deviation.
m = mad(M) m = mad(M, dim)
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.
Moment of a set of values.
m = moment(M, order) m = moment(M, order, dim)
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.
moment(randn(1, 10000), 3) 3.011
Mean after discarding NaNs.
y = nanmean(M) y = nanmean(M, dim)
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.
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
Median after discarding NaNs.
y = nanmedian(M) y = nanmedian(M, dim)
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.
Standard deviation after discarding NaNs.
y = nanstd(M) y = nanstd(M, p) y = nanstd(M, p, dim)
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.
Sum after discarding NaNs.
y = nansum(M) y = nansum(M, dim)
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.
Pairwise distance between observations.
d = pdist(M) d = pdist(M, metric) d = pdist(M, metric, p)
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:
euclid | euclidean distance |
seuclid | standardized euclidean distance |
mahal | Mahalanobis distance |
cityblock | sum of absolute values |
minkowski | Minkowski metric with paramater p |
Percentile.
m = prctile(M, prc) m = prctile(M, prc, dim)
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.
Mean absolute deviation.
m = range(M) m = range(M, dim)
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.
Skewness of a set of values.
s = skewness(M) s = skewness(M, dim)
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.
skewness(randn(1, 10000).^2) 2.6833
Resize the output of pdist to a square matrix.
D = squareform(d)
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).
Trimmed mean of a set of values.
m = trimmean(M, prc) m = trimmean(M, prc, dim)
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.
Variance of a set of values.
s2 = var(M) s2 = var(M, p) s2 = var(M, p, dim)
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.
Z score (normalized deviation).
Y = zscore(X) Y = zscore(X, dim)
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.