Commands for Computing Properties of Random Variables
The Statistics package provides a wide range of tools for working with random variables. This includes tools for creating random variables from specific distributions, commands for computing basic quantities, and related functions, simulation and visualization routines.
Creating New Random Variables
Computing with Random Variables
Examples
Random variables are created using the RandomVariable command.
with(Statistics):
X := RandomVariable(Normal(5, 1));
X≔_R
Y := RandomVariable(Normal(7, 1));
Y≔_R0
Random variables can be distinguished from ordinary variables (names) by their attributes. Type RandomVariable can be used to query whether a given Maple object is a random variable or not.
type(X, RandomVariable);
true
type(Z, RandomVariable);
false
indets(X+Y+Z, RandomVariable);
_R,_R0
The Statistics package provides a number of tools for computing basic quantities and functions. Single random variables as well as algebraic expressions (e.g. linear combinations, products, etc.) involving random variables are supported. Different random variables involved in an expression are considered to be independent. By default, all computations involving random variables are performed symbolically.
AbsoluteDeviation
compute the average absolute deviation
CDF
cumulative distribution function
CentralMoment
central moments
CGF
cumulant generating function
CharacteristicFunction
characteristic function
Cumulant
cumulants
CumulantGeneratingFunction
CumulativeDistributionFunction
Decile
deciles
ExpectedValue
compute expected values
FailureRate
hazard (failure) rate
GeometricMean
geometric mean
HarmonicMean
harmonic mean
HazardRate
HodgesLehmann
Hodges-Lehmann statistic
InterquartileRange
interquartile range
InverseSurvivalFunction
inverse survival function
Kurtosis
kurtosis
MakeProcedure
generate a procedure for calculating statistical quantities
Mean
arithmetic mean
MeanDeviation
average absolute deviation from the mean
Median
median
MedianDeviation
compute the median absolute deviation
MGF
moment generating function
MillsRatio
Mills ratio
Mode
mode
Moment
moments
MomentGeneratingFunction
OrderStatistic
order statistics
PDF
probability density function
Percentile
percentiles
Probability
compute the probability of an event
ProbabilityDensityFunction
ProbabilityFunction
probability function
QuadraticMean
quadratic mean
Quantile
quantiles
Quartile
quartiles
RandomVariable
create new random variables
RousseeuwCrouxQn
Rousseeuw and Croux' Qn
RousseeuwCrouxSn
Rousseeuw and Croux' Sn
Skewness
skewness
StandardDeviation
standard deviation
StandardError
standard error of the sampling distribution
StandardizedMoment
standardized moments
Support
support set of a random variable
SurvivalFunction
survival function
Variance
variance
Variation
coefficient of variation
with⁡Statistics:
Compute the PDF and the CDF of the non-central beta distribution.
PDF⁡NonCentralBeta⁡5,3,m,t
0t<0ⅇ−m2⁢t4⁢1−t2⁢116⁢m3⁢t3+218⁢m2⁢t2+632⁢m⁢t+105⁢ⅇm⁢t2t≤10otherwise
CDF⁡NonCentralBeta⁡5,3,m,t
0t≤0t5⁢ⅇ−12⁢m+12⁢m⁢t⁢m2⁢t4−2⁢m2⁢t3+m2⁢t2+24⁢m⁢t3−52⁢m⁢t2+28⁢m⁢t+120⁢t2−280⁢t+1688t≤111<t
Compute the PDF, mean, standard deviation and moments of a Beta random variable.
X≔RandomVariable⁡Β⁡p,q
X≔_R3
PDF⁡X,t
0t<0tp−1⁢1−tq−1Β⁡p,qt<10otherwise
Mean⁡X
pp+q
StandardDeviation⁡X
p⁢qp+q+1p+q
Moment⁡X,n
Β⁡q,n+pΒ⁡p,q
Create two normal random variables.
X≔RandomVariable⁡Normal⁡0,1
X≔_R4
Y≔RandomVariable⁡Normal⁡0,1
Y≔_R5
Compute the density of X/Y. Compare the result with the Cauchy density.
PDF⁡XY,t
1t2+1⁢π
PDF⁡Cauchy⁡0,1,t
Compute some probabilities.
X≔RandomVariable⁡Normal⁡0,1:
Probability⁡X2<X
erf⁡222
The speed distribution for the molecules of an ideal gas.
assume⁡0<m,0<k,0<T
σ≔sqrt⁡k⁢Tm
σ≔k~⁢T~m~
f≔simplify⁡piecewise⁡x<0,0,sqrt⁡2πσ3⁢x2⁢exp⁡−x22⁢σ2
f≔0x<02⁢m~32⁢x2⁢ⅇ−x2⁢m~2⁢k~⁢T~π⁢k~32⁢T~320≤x
MD≔Distribution⁡PDF=unapply⁡f,x
MD ≔ moduleoptionDistribution,Continuous;exportPDF,Conditions;end module
Create random variable having this distribution.
X≔RandomVariable⁡MD
X≔_R8
Compute average molecular speed.
2⁢T~⁢k~⁢2m~⁢π
Compute average kinetic energy.
simplify⁡ExpectedValue⁡12⁢m⁢X2
3⁢k~⁢T~2
Helium at 25C.
g≔eval⁡f,T=298.15,k=evalf⁡ScientificConstants:-Constant⁡k,m=4.×10−27
g≔0x<05.404283672×10−10⁢2⁢x2⁢ⅇ−4.858610154×10−7⁢x20≤x
He≔Distribution⁡PDF=unapply⁡g,x:
XHe≔RandomVariable⁡He:
Most probable speed.
Mode⁡XHe
1434.643427
Use simulation to verify the results.
A≔Sample⁡XHe,105
Mode⁡A
1444.17684604007
P≔DensityPlot⁡XHe,range=0..3500,thickness=3,color=red:
Q≔Histogram⁡A,range=0..3500:
plotsdisplay⁡P,Q
See Also
Statistics
Statistics[Computation]
Statistics[DescriptiveStatistics]
Statistics[Distributions]
Statistics[Simulation]
Download Help Document