probdist is a library which adds to LME classes related to probability distributions. They provide an alternative interface to the algorithms in functions pdf, cdf, icdf and random. In addition, they provide methods to compute their mean, their median, their variance and their standard deviation when an explicit formula is known.
Probability distribution objects, which bundle both the distribution type and parameters, should be created with function makedist.
The following statement makes available classes defined in probdist:
use probdist
Cumulative distribution function for a distribution.
s = cdf(pd, x)
cdf(pd,x) calculates the integral of a probability density function from -infinity to x. The distribution is specified by the distribution object pd, typically created by makedist.
use probdist pd = makedist('normal', mu=1, sigma=0.5); x = linspace(-1, 3); p = pdf(pd, x); c = cdf(pd, x); plot(x, p, '-'); plot(x, c);
distribution::pdf, distribution::icdf, distribution::random, makedist, cdf
Inverse cumulative distribution function for a distribution.
x = icdf(pd, p)
icdf(pd,p) calculates the value of x such that cdf(pd,x) is p. The distribution is specified by the distribution object pd, typically created by makedist.
icdf is defined for distributions beta, chi2, gamma, lognormal, normal, student, and uniform.
use probdist pd = makedist('student', nu=3); p = cdf(pd, 4) p = 0.9860 x = icdf(pd, p) x = 4.0000
distribution::cdf, distribution::pdf, distribution::random, makedist, icdf
Make a distribution object.
use probdist pd = makedist(name, param1=value1, ...)
makedist(name) creates a distribution object with the default parameters. Parameters can be specified with named arguments. The result is an object whose class is a subclass of distribution.
Here is a list of distributions with the default parameter values.
Name | Default parameters | Class |
---|---|---|
'beta' | a=1,b=1 | betaDistribution |
'chi' | nu=1 | chiDistribution |
'chi2' 'chisquare' |
nu=1 | chi2Distribution |
'exp' 'exponential' |
mu=1 | exponentialDistribution |
'logn' 'lognormal' |
mu=1,sigma=1 | lognormalDistribution |
'nakagami' | mu=1,omega=1 | nakagamiDistribution |
'norm' 'normal' |
mu=0,sigma=1 | normalDistribution |
'rayl' 'rayleigh' |
b=1 | rayleighDistribution |
't' 'student' |
nu=1 | studentDistribution |
'unif' 'uniform' |
Lower=0,Upper=1 | uniformDistribution |
'weib' 'weibull' |
a=1,b=1 | weibullDistribution |
use probstat pd = makedist('chi2', nu=3) pd = Chi2 distribution m_th = mean(pd) m_th = 3 m_data = mean(random(pd, [1, 10000])) m_data = 3.0027
Mean of a distribution.
m = mean(pd)
mean(pd) gives the arithmetic mean of a distribution.
use probdist pd = makedist('normal', mu=3, sigma=2); mean(pd) 3
distribution::var, distribution::sdev, distribution::median, makedist, mean
Median of a distribution.
m = median(pd)
median(pd) gives the arithmetic median of a distribution, or NaN if it cannot be computed.
use probdist pd = makedist('exp', mu=2); median(pd) 3
distribution::var, distribution::sdev, distribution::median, makedist, median
Probability density function of a distribution.
s = pdf(pd, x)
pdf(pd,x) gives the probability of a distribution. The distribution is specified by the distribution object pd, typically created by makedist.
use probdist pd = makedist('lognormal', mu=2, sigma=1.5); x = logspace(-2,1); p = pdf(pd, x); plot(x, p);
distribution::cdf, distribution::icdf, distribution::random, makedist, pdf
Random generator for a distribution.
x = random(pd) x = random(pd, size)
random(pd) calculates a pseudo-random number whose distribution function is specified by the distribution object pd, typically created by makedist.
Additional input arguments specify the size of the result, either as a vector (or a single scalar for a square matrix) or as scalar values. The result is an array of the specified size where each value is an independent pseudo-random variable. The default size is 1 (scalar).
use probdist pd = makedist('exp'); dataSize = [10, 100]; data = random(pd, dataSize);
distribution::pdf, makedist, random
Standard deviation of a distribution.
s = std(pd)
std(pd) gives the standard deviation of a distribution.
use probdist pd = makedist('lognormal', mu=2, sigma=1.5); std(pd) 66.3080 std(random(pd,[1,100000])) 68.0868
distribution::var, distribution::mean, distribution::median, makedist, std
Variance of a distribution.
s2 = var(pd)
var(pd) gives the variance of a distribution.
use probdist pd = makedist('uniform', Lower=2, Upper=10); var(pd) 5.3333 var(random(pd,[1,100000])) 5.3148
distribution::mean, distribution::sdev, distribution::median, makedist, var