stat.tcl.
Note that there are also built-in statistical functions called
correlation
and
moving_correlation.
The
Tally Unary Operator "#"
also has statistical applications.
Three examples are provided for each function.
The first uses the vector v which is defined as follows (note the missing values):
% nap "v = {12 6 _ 7 3 15 _ 10 18 6}"
The second example produces statistics of each column of a matrix.
The third example produces statistics of each row of the same matrix.
This matrix is called m and is defined as follows:
% nap "m = {
{1.5 2.1 1.5 0.2}
{6.2 4.9 _ 0.2}
}"
am(x[,verb_rank])
% [nap "am(v)"] 9.625 % [nap "am(m)"] 3.85 3.5 1.5 0.2 % [nap "am(m,1)"] 1.325 3.76667
gm(x[,verb_rank])
% [nap "gm(v)"] 8.38752 % [nap "gm(m)"] 3.04959 3.2078 1.5 0.2 % [nap "gm(m,1)"] 0.985957 1.82476
median(x[,verb_rank])
% [nap "median(v)"] 8.5 % [nap "median(m)"] 3.85 3.5 1.5 0.2 % [nap "median(m,1)"] 1.5 4.9
mode(x[,verb_rank])
% [nap "mode(v)"] 6 % [nap "mode(m)"] 3.85 3.5 1.5 0.2 % [nap "mode(m,1)"] 1.50625 3.7625
percentile(x,pc
[,verb_rank
[,nc]])
pc = vector of required percentiles
nc = number of class intervals (default: 256)
The following examples calculate the following percentiles:
% [nap "percentile(v, {0 50 100})"]
3 8.50781 18
% [nap "percentile(m, {0 50 100})"]
1.50000 2.10000 1.50000 0.20000
3.85918 3.50547 1.50000 0.20000
6.20000 4.90000 1.50000 0.20000
% [nap "percentile(m, {0 50 100}, 1)"]
0.20000 0.20000
1.50254 4.92266
2.10000 6.20000
rms(x[,verb_rank])
% [nap "rms(v)"] 10.7413 % [nap "rms(m)"] 4.51054 3.76962 1.5 0.2 % [nap "rms(m,1)"] 1.49583 4.56399
sd(x[,verb_rank])
% [nap "sd(v)"] 4.76806 % [nap "sd(m)"] 2.35 1.4 0 0 % [nap "sd(m,1)"] 0.694172 2.57725
sd1(x[,verb_rank])
% [nap "sd1(v)"] 5.09727 % [nap "sd1(m)"] 3.3234 1.9799 _ 0 % [nap "sd1(m,1)"] 0.801561 3.15647
var(x[,verb_rank])
% [nap "var(v)"] 22.7344 % [nap "var(m)"] 5.5225 1.96 0 0 % [nap "var(m,1)"] 0.481875 6.64222
var1(x[,verb_rank])
% [nap "var1(v)"] 25.9821 % [nap "var1(m)"] 11.045 3.92 _ 0 % [nap "var1(m,1)"] 0.6425 9.96333
moving_average(x,shape_window[,step])
shape_window is either a scalar or a vector with an element for each dimension.
If it is a scalar then it is treated as a vector with
rank(x)
identical elements.
Similarly, step is either a scalar or a vector with an element for each dimension.
If it is a scalar then it is treated as a vector with
rank(x)
identical elements.
The value -1 is treated like 1, except that missing values are prepended & appended
(along this dimension of x) to produce a result with the same dimension size
as x.
The following examples illustrate the application of
moving_average
to a vector.
% nap "v = {12 6 _ 7 3 15 _ 10 18 5}"
% [nap "moving_average(v, 3)"] value
9 6.5 5 8.33333 9 12.5 14 11
% [nap "moving_average(v, 3, 3)"] value
9 8.33333 14
% [nap "moving_average(v, 3, -1)"] value
9 9 6.5 5 8.33333 9 12.5 14 11 11.5
The following examples illustrate the application of
moving_average
to a matrix.
% nap "m = {
{1 2 1 4 0 0}
{5 4 2 9 2 7}
{0 1 1 3 1 4}
}"
% [nap "moving_average(m, {3 3})"] value
1.88889 3.00000 2.55556 3.33333
% [nap "moving_average(m, {3 3}, {3 3})"] value
1.88889 3.33333
% [nap "moving_average(m, 3, 3)"] value
1.88889 3.33333
% [nap "moving_average(m, 3, -1)"] value
3.00000 2.50000 3.66667 3.00000 3.66667 2.25000
2.16667 1.88889 3.00000 2.55556 3.33333 2.33333
2.50000 2.16667 3.33333 3.00000 4.33333 3.50000
% [nap "moving_average(m, {1 3})"] value
1.333333 2.333333 1.666667 1.333333
3.666667 5.000000 4.333333 6.000000
0.666667 1.666667 1.666667 2.666667