 Student[Statistics] - Maple Programming Help

Home : Support : Online Help : Education : Student Packages : Statistics : Student/Statistics/Sample

Student[Statistics]

 Sample
 generate random sample

 Calling Sequence Sample(X, n, numeric_option, output_option)

Parameters

 X - algebraic; random variable n - positive integer; sample size numeric_option - (optional) equation of the form numeric=value where value is true or false output_option - (optional) equation of the form output=x where x is value, plot, or both

Description

 • The Sample command generates a random sample drawn from the distribution given by X.
 • The first parameter, X, can be a random variable, or an algebraic expression involving random variables (see Student[Statistics][RandomVariable]).
 • The second parameter, n, is the sample size. The function will return a newly created Vector of length n, filled with the sample values.
 • If the option output is not included or is specified to be output=value, then the function will return the generated sample as a Vector. If output=plot is specified, then the function will return a density plot of the input random variable together with a histogram of the sample. If output=both is specified, then both the value and the plot will be returned.

Computation

 • If X is a continuous random variable, or an expression that contains a floating point value, or an expression that contains a continuous random variable, then the sample is returned as floating point values. Otherwise, the sample is returned as exact values.
 • By default, the data are generated according to the rule above. To always generate data numerically, specify the numeric or numeric=true option.

Examples

 > $\mathrm{with}\left({\mathrm{Student}}_{\mathrm{Statistics}}\right):$

Straightforward sampling of a random variable.

 > $X≔\mathrm{NormalRandomVariable}\left(0,1\right)$
 ${X}{≔}{\mathrm{_R}}$ (1)
 > $A≔\mathrm{Sample}\left(X,10\right)$
 ${A}{≔}\left[\begin{array}{cccccccccc}{-}{1.07242412799827}& {-}{0.329077870547065}& {-}{0.617091936909790}& {0.214466745245291}& {-}{0.0254281280423846}& {1.72882128417783}& {-}{1.63485675434390}& {1.57117217175430}& {0.170358421410408}& {1.00647840875181}\end{array}\right]$ (2)

You can check how well the generated data fit the input model by specifying the output=plot option and comparing the their graphs.

 > $\mathrm{Sample}\left(X,{10}^{5},\mathrm{output}=\mathrm{plot}\right)$ You can also sample an expression involving two random variables.

 > $Y≔\mathrm{NormalRandomVariable}\left(0,1\right)$
 ${Y}{≔}{\mathrm{_R0}}$ (3)
 > $\mathrm{Sample}\left({ⅇ}^{X}Y,10\right)$
 $\left[\begin{array}{cccccccccc}{-}{0.253735520046683}& {-}{3.23229306202039}& {-}{0.112979754336150}& {0.157482784785936}& {0.122492593669143}& {19.6071936753415}& {1.35229332525304}& {0.0732276755693901}& {2.20915384220871}& {-}{0.189083076767802}\end{array}\right]$ (4)

Consider a discrete random variable.

 > $B≔\mathrm{PoissonRandomVariable}\left(3\right)$
 ${B}{≔}{\mathrm{_R1}}$ (5)
 > $\mathrm{Sample}\left(\frac{B}{\mathrm{Pi}},10\right)$
 $\left[\begin{array}{cccccccccc}\frac{{4}}{{\mathrm{π}}}& \frac{{3}}{{\mathrm{π}}}& \frac{{2}}{{\mathrm{π}}}& \frac{{5}}{{\mathrm{π}}}& \frac{{3}}{{\mathrm{π}}}& \frac{{5}}{{\mathrm{π}}}& \frac{{1}}{{\mathrm{π}}}& \frac{{2}}{{\mathrm{π}}}& \frac{{2}}{{\mathrm{π}}}& \frac{{4}}{{\mathrm{π}}}\end{array}\right]$ (6)

To always generate floating point value data, specify the numeric or numeric=true option.

 > $\mathrm{Sample}\left(\frac{B}{\mathrm{Pi}},10,\mathrm{numeric}\right)$
 $\left[\begin{array}{cccccccccc}{0.954929658551372}& {1.27323954473516}& {1.27323954473516}& {1.27323954473516}& {0.636619772367581}& {2.22816920328654}& {0.636619772367581}& {0.318309886183791}& {0.318309886183791}& {1.27323954473516}\end{array}\right]$ (7)

Use the output=both option to obtain both the value and plot of the generated data.

 > $\mathrm{dataset},\mathrm{graph}≔\mathrm{Sample}\left(B,100,\mathrm{output}=\mathrm{both}\right)$
 ${\mathrm{dataset}}{,}{\mathrm{graph}}{≔}\left[\begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{1}& {2}& {0}& {3}& {1}& {1}& {3}& {0}& {5}& {5}& {2}& {4}& {6}& {4}& {4}& {4}& {3}& {2}& {1}& {1}& {2}& {3}& {1}& {1}& {3}& {3}& {2}& {4}& {2}& {2}& {2}& {2}& {5}& {3}& {2}& {1}& {3}& {3}& {0}& {3}& {2}& {0}& {3}& {2}& {5}& {3}& {0}& {4}& {5}& {1}& {2}& {3}& {2}& {5}& {3}& {3}& {5}& {2}& {2}& {5}& {5}& {1}& {8}& {4}& {4}& {3}& {5}& {5}& {4}& {8}& {4}& {1}& {2}& {4}& {7}& {1}& {5}& {4}& {3}& {2}& {3}& {3}& {4}& {1}& {1}& {5}& {4}& {3}& {1}& {2}& {2}& {1}& {5}& {2}& {3}& {8}& {2}& {4}& {2}& {0}\end{array}\right]{,}{\mathrm{PLOT}}{}\left({\mathrm{...}}\right)$ (8)
 > $\mathrm{dataset}$
 $\left[\begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{1}& {2}& {0}& {3}& {1}& {1}& {3}& {0}& {5}& {5}& {2}& {4}& {6}& {4}& {4}& {4}& {3}& {2}& {1}& {1}& {2}& {3}& {1}& {1}& {3}& {3}& {2}& {4}& {2}& {2}& {2}& {2}& {5}& {3}& {2}& {1}& {3}& {3}& {0}& {3}& {2}& {0}& {3}& {2}& {5}& {3}& {0}& {4}& {5}& {1}& {2}& {3}& {2}& {5}& {3}& {3}& {5}& {2}& {2}& {5}& {5}& {1}& {8}& {4}& {4}& {3}& {5}& {5}& {4}& {8}& {4}& {1}& {2}& {4}& {7}& {1}& {5}& {4}& {3}& {2}& {3}& {3}& {4}& {1}& {1}& {5}& {4}& {3}& {1}& {2}& {2}& {1}& {5}& {2}& {3}& {8}& {2}& {4}& {2}& {0}\end{array}\right]$ (9)
 > $\mathrm{graph}$ You can also compute the statistics of the generated data.

 > $C≔\mathrm{Sample}\left({X}^{2},{10}^{4}\right)$
 ${C}{≔}\left[\begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{0.258005868285310}& {0.647832085370262}& {0.552625307079720}& {0.644317098320509}& {0.00366167458000057}& {0.0403829699057481}& {0.681389692738934}& {0.143078226441773}& {0.134241896950606}& {2.47625349047887}& {0.000609879121306750}& {2.38438147890592}& {2.22797185617195}& {1.32526331246164}& {0.270369850841511}& {0.138375509296907}& {0.0265002475331880}& {0.979677373551427}& {0.388427692431028}& {0.182264034278867}& {0.812366933639697}& {0.539108541717883}& {0.473091370455867}& {0.237684359606523}& {0.000861634389063400}& {0.166773154590571}& {7.13844482244958}& {1.14534554710405}& {0.913006438034576}& {1.66751156050423}& {0.323445730676006}& {3.52129010668172}& {0.600620076918909}& {0.411967081429006}& {1.52122249494429}& {1.45524050120427}& {0.377389541501214}& {0.864734078563337}& {0.0742810492979717}& {0.0246050443811001}& {5.86372130395730}& {0.0499245795380815}& {0.0923353973474443}& {0.510164356816196}& {0.0909007583728517}& {0.256606700588797}& {0.00210972803584742}& {1.81900097514430}& {0.451785248150641}& {0.292282793863928}& {0.0383136090795131}& {0.109528385416795}& {0.409157516946452}& {0.000227840819025803}& {0.268936763599973}& {2.04375558610188}& {2.79788342009087}& {0.906395938505289}& {0.0143753414827398}& {0.00150305933767118}& {2.53784040226779}& {0.00584258490070722}& {0.740145799907055}& {1.81937481223161}& {2.50549920639906}& {0.386081866589341}& {0.00149144240526257}& {0.100400039791628}& {1.53504988673351}& {0.913635637831187}& {0.631699620782699}& {0.0603685709738763}& {0.652120845954173}& {0.121746724542649}& {0.625975373844940}& {0.649397727345142}& {0.873417200057731}& {3.51036567337435}& {0.146486323489547}& {0.00244347525707687}& {3.30900437015094}& {0.799940431179467}& {0.0981602243084241}& {0.993008832251858}& {1.69889178463384}& {13.0850904021864}& {0.0919408015605868}& {1.22919302365509}& {1.30766766198218}& {0.497555830859906}& {0.00158669709244757}& {0.0994329473621025}& {0.338645905186422}& {0.296734008074236}& {0.00807852392146294}& {0.00366109419866321}& {0.625914550526785}& {1.62080220014563}& {0.0729675445926770}& {0.129421293949300}& {\mathrm{...}}& {"... 9900 row vector entries not shown"}\end{array}\right]$ (10)
 > $\mathrm{Mean}\left(C\right)$
 ${0.990673425318131}$ (11)
 > $\mathrm{Median}\left(C\right)$
 ${0.453986354979151}$ (12)
 > $\mathrm{Skewness}\left(C\right)$
 ${2.77883456642836}$ (13)
 > $\mathrm{Kurtosis}\left(C\right)$
 ${14.4546978275010}$ (14)
 > $\mathrm{Variance}\left(C\right)$
 ${1.93714365220748}$ (15)
 > $\mathrm{StandardDeviation}\left(C\right)$
 ${1.39181308091549}$ (16)
 > $\mathrm{Quantile}\left(C,0.6\right)$
 ${0.710679651989900}$ (17)
 > 

References

 Stuart, Alan, and Ord, Keith. Kendall's Advanced Theory of Statistics. 6th ed. London: Edward Arnold, 1998. Vol. 1: Distribution Theory.
 Walker, Alastair J. New Fast Method for Generating Discrete Random Numbers with Arbitrary Frequency Distributions, Electronic Letters, 10, 127-128.
 Walker, Alastair J. An Efficient Method for Generating Discrete Random Variables with General Distributions, ACM Trans. Math. Software, 3, 253-256.

Compatibility

 • The Student[Statistics][Sample] command was introduced in Maple 18.