Statistics2 Package

This package contains some statistic functions.
There is a whole set of functions, called Wstat functions, which replicate some of the normal statistical functions available in MathTablet adding the capability of dealing with weighted data.
Function Description
Wavg Wavg(a,w)
or
Wavg(m)

Returns the weighted average value for each columns of a matrix.
Wstd Wstd(a,w)
or
Wstd(m)

Returns the weighted standard deviation for each columns of a matrix.
WSx WSx(a,w)
or
WSx(m)

Returns the weighted sum of the columns of a matrix.
WSxx WSxx(a,w)
or
WSxx(m)

Returns the weighted sum of the squares of each value in the columns of a matrix.
WSxy WSxy(a,w)
or
WSxy(m)

Returns the sum found by multiplying together the elements in a row and their weights and then summing the result for each row.
Wnum Wnum(a,w)
or
Wnum(m)

Sum of the weights for each column.

The a matrix isn't really necessary but is maintained for syntax congruence
Wmm Wmm(a,w)
or
Wmm(m)

Finds the Minimum, Maximum values for each column in a matrix.
Wlsq Wlsq(a,w)
or
Wlsq(m)

Returns the weighted least squares linear fit of a set of points.
a is a 2 columns matrix of x,y values
w is a 1 column matrix of weights
m is a 3 columns matrix with both values and weights.

Wlsq returns a the 1x3 matrix {a,b,r} where
y = ax + b
is the regression line and r the correlation coefficient.
Wexpand Wexpand(a,w)
or
Wexpand(m)

Returns the expanded version of a weighted matrix.

The expanded matrix is a matrix in which each row of the original matrix is repeated as many times as the corresponding weight. This has a sense only if the weights are the same for all the columns and are integers.
Usage Note for all Wstat functions:

All these functions can be called in two different ways:
Wstat(a, w) or Wstat(m)
where:
a is the matrix of values
w is the matrix of weights
m is a matrix containing both values and weights

All the operations are carried on column wise.

For the Wstat(a, w) syntax the following applies:
a and w must have the same numbers of rows.
If w has the same number of columns of a then each column of w is applied as weights to the corresponding column of a so that the weighted data are a[i,j]*w[i,j].
If w doesn't have the same number of columns of a then the first column of w is applied as weights to all the columns of a so that the weighted data are a[i,j]*w[1,j]. The other columns of w are ignored.

For the Wstat(m) syntax the following applies:
If m has two or more columns than its last column is used as weights for all the previous columns of m so that the weighted data are m[i,j]*m[i,n] for j = 1 to n-1.
If m has only one column then all the weights are set to 1.
CorrCoeff CorrCoeff(y1,y2,w)
or
CorrCoeff({y1 | y2 | w})

Returns the correlation coefficient for two optionally weighted datasets.
A second coefficient is always computed ignoring the weights.


y1 = 1st set of y values
y2 = 2nd set of y values
w = optional weights
NormProbPlot NormProbPlot(y1,y2,w)

Computes the Least Squares Linear Fit for the Normal Probability Plot of the given points.
If plotted plots the plot itself and the regression line.


A high correlation coefficient gives a reasonable confidence on the normality of the points distribution.

If only one set of y is given the plot is computed on them. If y1 and y2 are given, the plot is computed on y2-y1 (residuals). If also w is given the plot is computed on (y2-y1)*w
UnifProbPlot UnifProbPlot(y1,y2,w)

Computes the Least Squares Linear Fit for the Uniform Probability Plot of the given points.
If plotted plots the plot itself and the regression line.


A high correlation coefficient gives a reasonable confidence on the uniformity of the points distribution.

If only one set of y is given the plot is computed on them. If y1 and y2 are given, the plot is computed on y2-y1 (residuals). If also w is given the plot is computed on (y2-y1)*w
RND RND(n,seed)

Returns a n rows vector of pseudo-random numbers uniformly distributed in the interval [0-1].

Seed can be any positive integer. With the same seed the same sequence is obtained. If seed is omitted a default sequence is produced.

Reference:
UNIRAN.f, part of the DATAPAC collection, which is © of NIST and available at http://www.itl.nist.gov/ div898/ software/datapac/homepage.htm
RNDNORM RNDNORM(n,seed)

Returns a n rows vector of pseudo-random numbers normally distributed with standard deviation = 1 and mean = 0.

Seed can be any positive integer. With the same seed the same sequence is obtained. If seed is omitted a default sequence is produced.

Reference:
NORRAN.f, part of the DATAPAC collection, which is © of NIST and available at http://www.itl.nist.gov/ div898/ software/datapac/homepage.htm
QuickSort QuickSort(dataInp, sortKey, sortMode)

Performs a quicksort on the input data.

dataInp = input data (vector or matrix)
sortKey = row or column to sort (optional, default 1)
sortMod = sort mode (optional, default 1):
1 : columnwise, ascending
2 : columnwise , descending
3 : rowwise, left to right
4 : rowwise, right to left

© 2007 Stefano Bertolucci