stat.lsp

Module index

source download

Module: stat.lsp

Basic statistics and plotting library

Version: 3.0 - Eliminated plot functions and f-prob which now is built-in as prob-f
Version: 3.1 - Documentation changes
Version: 3.2 - Documentation, mention built-in 'stats' function since 10.4.2


Author: Lutz Mueller, 2001-2014

Functions for statistics

To use this module it has to be loaded at the beginning of the program file:
 (load (append (env "NEWLISPDIR") "/modules/stat.lsp"))
 ; or shorter
 (module "stat.lsp")
 
All functions work on integers and floats or a mix of both. lists are normal LISP lists. matrices are lists of lists, one list for each row in the two dimensional data matrix. See the function stat:matrix on how to make matrices from lists.

In version 3.0 of stat.lsp the usage for Gnuplot the stat:plot and stat:plotXY functions has been eliminated. Instead use the module plot.lsp shipped with all binary and source distributions. The F-distribution function f-prob has also been eliminated instead use one of new the built-in prob-f or crit-f functions.

The documention contains only the call patterns. See the source for more documentation.

Summary of functions


General uni- and bi- variate statistics

 stat:sum      - sum of a vector of numbers (see also built-in stats since 10.4.2)
 stat:mean     - arithmetik mean of a vector of numbers (see also built-in stats since 10.4.2)
 stat:var      - estimated variance of numbers in a vector sample
 stat:sdev     - estimated standard deviation of numbers in a vector (see also built-in stats since 10.4.2)
 stat:sum-sq   - sum of squares of a data vector
 stat:sum-xy   - sum of products of a two data vectors
 stat:corr     - correlation coefficient between two vectors (built-in since 10.4.2)
 stat:cov      - covariance of two number vectors
 stat:sum-d2   - sum of squared differences of a vector from its mean
 stat:sum-d2xy - sum of squared diffferences of two vectors
 stat:regression - calculates the intecept and slope of a regression estimate
 stat:fit      - return the fitted line using regression coefficients
 stat:moments  - calulates 1st to 3rd moments from a vector of numbers
 

Multi variate statistics

 stat:multiple-reg  - calculates a multiple regression
 stat:cov-matrix    - calculates a covariance matrix
 stat:corr-matrix   - calculates a correlation matrix
 

Time series

 stat:smooth   - smoothes a vector of numbers
 stat:lag      - calcultes a difference list with specified lag
 stat:cumulate - cumulate a data vector
 stat:power    - calculate the power spectrum of a time series
 

Matrix and list utilities

 stat:matrix       - make a matrix from column vectors
 stat:diagonal     - make a diagonal matrix
 stat:get-diagonal - return the diagonal of a matrix in a vector
 stat:mat-map      - map a binary function on to matrices
 


§

stat:corr

syntax: (stat:corr X Y)
parameter: X - A list of numbers.
parameter: Y - A list of numbers.

return: Correlation coefficient of lists X and Y.

A corr native function is built into newLISP since 10.4.2.

§

stat:cov

syntax: (stat:cov X Y)
parameter: X - A list of numbers.
parameter: Y - A list of numbers.

return: Covariance of data in lists X and Y



§

stat:cov-matrix

syntax: (stat:cov-matrix X)
parameter: X - A matrix of numbers.

return: Covariance matrix of X with N rows and k columns.



§

stat:corr-matrix

syntax: (stat:corr-matrix X)
parameter: X - A matrix of numbers.

return: Correlation matrix of X with N rows and k columns.



§

stat:cumulate

syntax: (stat:cumulate X)
parameter: X - A list of numbers.

return: The cumulated list of X.



§

stat:diagonal

syntax: (stat:diagonal item N)
parameter: item - The diagonal element.

return: A diagonal matrix of length N with item in the diagonal.



§

stat:fit

syntax: (stat:fit X Y)
parameter: X - A list of numbers.
parameter: Y - A list of numbers.

return: fitted line based on (stat:regression X Y).



§

stat:f-prob

syntax: (stat:f-prob F df1 df2)
parameter: F - The variance ratio.
parameter: df1 - Degrees of freedom.
parameter: df2 - Degrees of freedom.

return: Probablity of F variance ratio for df1, df2 degress of freedom.



§

stat:get-diagonal

syntax: (stat:get-diagonal X)
parameter: X - An matrix filled with numbers.

return: A list from the diagonal elements of X.



§

stat:lag

syntax: (stat:lag X n)
parameter: X - A list of numbers.
parameter: n - Lag n.

return: A differenced list of X with a lag of n.

If the length of list X is l then the length of the resulting differenced list is l - n.

§

stat:mat-map

syntax: (stat:mat-map op A B)

return: Matrix map, e.g. (stat:mat-map + A B).

Used for adding and subtracting matrices.

§

stat:matrix

syntax: (stat:matrix C1 .... CN)
parameter: C1 - The first column list of values.
parameter: CN - The Nth column list of values.

return: A matrix off 1 to N columns C.



§

stat:mean

syntax: (stat:mean X)
parameter: X - A list of numbers.

return: The mean of data in list X.



§

stat:moments

syntax: (stat:moments X)
parameter: X - A list of numbers.

return: Calculates all moments of list X.



§

stat:multiple-reg

syntax: (stat:multiple-reg X offY)
parameter: X - A matrix of numbers.
parameter: offY - Zero based offset into Y.

return: Multiple regression of vars in X onto Y at offsetY.



§

stat:power

syntax: (stat:power TS)
parameter: TS - A time series of numbers.

return: The power spectrum of a time series



§

stat:regression

syntax: (stat:regression X Y)
parameter: X - A list of numbers.
parameter: Y - A list of numbers.
returns (b0 b1) coefficients of regression Y = b0 + b1*X.

§

stat:sdev

syntax: (stat:sdev X)
parameter: X - A list of numbers.

return: Standard deviation of data in list X.



§

stat:smooth

syntax: (stat:smooth X alpha)
parameter: X - A list of numbers.
parameter: alpha - Smoothing coefficient 0 < alpha < 1.

return: Exponentially smoothed sequence in X.



§

stat:sum

syntax: (stat:sum X)
parameter: X - A list of numbers,

return: Sum of data in list X.



§

stat:sum-d2

syntax: (stat:sum-d2 X)
parameter: X - A list of numbers.

return: Sum of squared diffs (x - mean(X))^2 in list X.



§

stat:sum-d2xy

syntax: (stat:sum-d2xy X Y)

return: Sum of squared differences (x - y)^2 of elements in lists X and Y.



§

stat:sum-sq

syntax: (stat:sum-sq X)
parameter: X - A list of numbers.

return: Sum of x*x data elements in list X.



§

stat:sum-xy

syntax: (stat:sum-xy X Y)
parameter: X - A list of numbers.
parameter: Y - A list of numbers.

return: Sum of products x*y data elements in lists X and Y.



§

stat:var

syntax: (stat:var X)
parameter: X - A list of numbers.

return: The variance of the data in list X.



- ∂ -

generated with newLISP  and newLISPdoc