Probability Distributions
The Statistics package contains 37 probability distributions as well as providing functionality for creating new distributions and manipulating random variables.
1 Continuous Probability Distributions
The Statistics package includes 28 continuous probability distributions along with commands for manipulating and creating continuous random variables. Continuous probability distributions are defined by a continuous probability density function along a section of the real line.
restart:withStatistics:
Consider a chi square random variable. The chi square random variable takes a single parameter which represents the number of degrees of freedom. When the random variable is created using the RandomVariable constructor, it generates a new name for the random variable data structure and returns it.
C:=RandomVariable⁡ChiSquare⁡5
C:=_R
The probability density function, as well as all other distribution commands, accepts either a random variable or probability distribution as its first parameter. The 'mainbranch' option can be used to return only the main branch of the distribution.
PDF⁡C,x
{0x<016⁢2⁢x3/2⁢ⅇ−12⁢xπotherwise
PDF⁡ChiSquare⁡5,x
PDF⁡C,x,mainbranch
16⁢2⁢x3/2⁢ⅇ−12⁢xπ
Combinations of probability distributions can be generated by performing operations on a set of random variables. For example, consider the product of a uniform random variable and a normal (gaussian) random variable.
R:=RandomVariable⁡Uniform⁡0,1⁢RandomVariable⁡Normal⁡0,1
R:=_R1⁢_R2
PDF⁡R,x
14⁢Ei⁡1,12⁢x2⁢2π
CDF⁡R,x
14⁢2⁢π+2⁢x⁢Ei⁡1,12⁢x2+2⁢erf⁡12⁢x⁢2⁢ππ
Variance⁡R
13
ExpectedValue⁡cos⁡R
12⁢2⁢π⁢erf⁡12⁢2
2 Discrete Probability Distributions
The Statistics package includes 9 discrete probability distributions and commands for manipulating and creating discrete random variables.
Consider a binomial random variable. Unlike continuous random variables, discrete random variables are defined by their probability function rather than their probability density function.
R:=RandomVariable⁡Binomial⁡4,0.5
R:=_R
ProbabilityFunction⁡R,x
{0x<0binomial⁡4,x⁢0.5x⁢0.54−xotherwise
ProbabilityFunction⁡Binomial⁡4,0.5,x
1.00
Moment⁡R,2
5.0000
MomentGeneratingFunction⁡R,x
0.5⁢ⅇx+0.54
The Statistics package also allows for both numeric and symbolic manipulation of random variables and distributions. Consider the negative binomial distribution with symbolic parameters.
T:=RandomVariable⁡NegativeBinomial⁡2,34
T:=_R1
CDFT,x assuming x ∷ posint
−716⁢4−x−316⁢4−x⁢x+1
CDF⁡T,4
40774096
Mean⁡T
23
CentralMoment⁡T,3
4027
CumulantGeneratingFunction⁡T,x
2⁢ln⁡34−2⁢ln⁡1−14⁢ⅇI⁢x
Further, the Statistics package supports the probability table. This distribution is used to associate probabilities with the integers 1..n, for any n. Consider a case of n = 5.
PTable:=12,14,18,116,116:P≔RandomVariableProbabilityTable⁡PTable:
ProbabilityFunction⁡P,2
14
CDF⁡P,2
34
The Statistics package also supports the empirical distribution, which is effectively a probability distribution built around a data sample. The probability of each element is equal to its frequency in the data sample.
EmpiricalData:=Array⁡1,1,1,2,4,4,5.5:X≔RandomVariableEmpiricalDistribution⁡EmpiricalData:
ProbabilityFunction⁡X,1
37
CDF⁡X,5
67
Mean⁡X
2.64285714285714279
CentralMoment⁡X,3
2.10787172011661861
3 Random Sample Generation
All probability distributions provide optimized hardware-level random number generators capable of generating very large pseudo-random samples quickly.
Generate a sample from a Binomial distribution.
R:=RandomVariable⁡Binomial⁡10,0.5:SampleR,10
Generate a sample from a probability table distribution.
PTable:=12,14,18,116,116:P:=RandomVariableProbabilityTable⁡PTable:Sample⁡P,10
Sample a non-central chi square distribution and plot the histogram of the output against the probability density function.
S:=Sample⁡NonCentralChiSquare⁡5,5,100000:P1≔HistogramS,range=0..30,maxbins=100:P2:=DensityPlotNonCentralChiSquare⁡5,5,range=0..30,thickness=3,color=red:plotsdisplayP1,P2
4 Custom Random Variables
The Statistics package includes the Distribution constructor, which can be used to create custom random variables.
A distribution that is occasionally used in statistics is the half-normal distribution, named so because it is a normal distribution that has been cropped at all negative values.
NormalPDF:=PDF⁡Normal⁡0,1,x
NormalPDF:=12⁢2⁢ⅇ−12⁢x2π
HalfNormalPDF:=piecewise⁡x<0,0,2⋅NormalPDF
HalfNormalPDF:={0x<02⁢ⅇ−12⁢x2πotherwise
Create a distribution module using the half normal PDF.
HalfNormalDist:=Distribution⁡PDF=unapply⁡HalfNormalPDF,x
HalfNormalDist:=moduleoptionDistribution,Continuous;exportPDF,Type;end module
R:=RandomVariable⁡HalfNormalDist
R:=_R0
DensityPlot⁡R,thickness=3
Compute the characteristics of this distribution.
Mean⁡R
2π
−2+ππ
erf⁡12⁢x⁢2⁢ⅇ12⁢x2+ⅇ12⁢x2
Return to Index for Example Worksheets
Download Help Document