Close
Close window
Distributions and Random Variables - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.
Maplesoft logo
Maplesoft logo

Online Help

All Products Maple MapleSim


[フレーム] [フレーム]

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:=RandomVariableChiSquare5

C:=_R

(1.1)

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.

>

PDFC,x

&lcub;0x<0162x3&sol;2&ExponentialE;12x&pi;otherwise

(1.2)
>

PDFChiSquare5&comma;x

&lcub;0x<0162x3&sol;2&ExponentialE;12x&pi;otherwise

(1.3)
>

PDFC&comma;x&comma;mainbranch

162x3&sol;2&ExponentialE;12x&pi;

(1.4)

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:=RandomVariableUniform0&comma;1RandomVariableNormal0&comma;1

R:=_R1_R2

(1.5)
>

PDFR&comma;x

14Ei1&comma;12x22&pi;

(1.6)
>

CDFR&comma;x

142&pi;&plus;2xEi1&comma;12x2&plus;2erf12x2&pi;&pi;

(1.7)
>

VarianceR

13

(1.8)
>

ExpectedValuecosR

122&pi;erf122

(1.9)

2 Discrete Probability Distributions

The Statistics package includes 9 discrete probability distributions and commands for manipulating and creating discrete random variables.

>

restart&colon;withStatistics&colon;

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:=RandomVariableBinomial4&comma;0.5

R:=_R

(2.1)
>

ProbabilityFunctionR&comma;x

&lcub;0x<0binomial4&comma;x0.5x0.54xotherwise

(2.2)
>

ProbabilityFunctionBinomial4&comma;0.5&comma;x

&lcub;0x<0binomial4&comma;x0.5x0.54xotherwise

(2.3)
>

VarianceR

1.00

(2.4)
>

MomentR&comma;2

5.0000

(2.5)
>

MomentGeneratingFunctionR&comma;x

0.5&ExponentialE;x&plus;0.54

(2.6)

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:=RandomVariableNegativeBinomial2&comma;34

T:=_R1

(2.7)
>

CDFT&comma;x assuming x posint

7164x3164xx&plus;1

(2.8)
>

CDFT&comma;4

40774096

(2.9)
>

MeanT

23

(2.10)
>

CentralMomentT&comma;3

4027

(2.11)
>

CumulantGeneratingFunctionT&comma;x

2ln342ln114&ExponentialE;Ix

(2.12)

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&comma;14&comma;18&comma;116&comma;116&colon;PRandomVariableProbabilityTablePTable&colon;

>

ProbabilityFunctionP&comma;2

14

(2.13)
>

CDFP&comma;2

34

(2.14)

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:=Array1&comma;1&comma;1&comma;2&comma;4&comma;4&comma;5.5&colon;XRandomVariableEmpiricalDistributionEmpiricalData&colon;

>

ProbabilityFunctionX&comma;1

37

(2.15)
>

CDFX&comma;5

67

(2.16)
>

MeanX

2.64285714285714279

(2.17)
>

CentralMomentX&comma;3

2.10787172011661861

(2.18)

3 Random Sample Generation

All probability distributions provide optimized hardware-level random number generators capable of generating very large pseudo-random samples quickly.

>

restart&colon;withStatistics&colon;

Generate a sample from a Binomial distribution.

>

R:=RandomVariableBinomial10&comma;0.5&colon;SampleR&comma;10

Generate a sample from a probability table distribution.

>

PTable:=12&comma;14&comma;18&comma;116&comma;116&colon;P:=RandomVariableProbabilityTablePTable&colon;SampleP&comma;10

Sample a non-central chi square distribution and plot the histogram of the output against the probability density function.

>

S:=SampleNonCentralChiSquare5&comma;5&comma;100000&colon;P1HistogramS&comma;range&equals;0..30&comma;maxbins&equals;100&colon;P2:=DensityPlotNonCentralChiSquare5&comma;5&comma;range&equals;0..30&comma;thickness&equals;3&comma;color&equals;red&colon;plotsdisplayP1&comma;P2

4 Custom Random Variables

The Statistics package includes the Distribution constructor, which can be used to create custom random variables.

>

restart&colon;withStatistics&colon;

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:=PDFNormal0&comma;1&comma;x

NormalPDF:=122&ExponentialE;12x2&pi;

(4.1)
>

HalfNormalPDF:=piecewisex<0&comma;0&comma;2NormalPDF

HalfNormalPDF:=&lcub;0x<02&ExponentialE;12x2&pi;otherwise

(4.2)

Create a distribution module using the half normal PDF.

>

HalfNormalDist:=DistributionPDF&equals;unapplyHalfNormalPDF&comma;x

HalfNormalDist:=moduleoptionDistribution&comma;Continuous&semi;exportPDF&comma;Type&semi;end module

(4.3)
>

R:=RandomVariableHalfNormalDist

R:=_R0

(4.4)
>

DensityPlotR&comma;thickness&equals;3

Compute the characteristics of this distribution.

>

MeanR

2&pi;

(4.5)
>

VarianceR

2&plus;&pi;&pi;

(4.6)
>

MomentGeneratingFunctionR&comma;x

erf12x2&ExponentialE;12x2&plus;&ExponentialE;12x2

(4.7)

Return to Index for Example Worksheets


Download Help Document

AltStyle によって変換されたページ (->オリジナル) /