Sample - Maple Help

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}\left[\mathrm{Statistics}\right]\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)$
 $\left[\begin{array}{cccccccccc}-1.072424127998269& -0.329077870547065& -0.6170919369097896& 0.21446674524529077& -0.025428128042384635& 1.728821284177832& -1.6348567543439045& 1.5711721717543001& 0.1703584214104083& 1.0064784087518084\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(\mathrm{exp}\left(X\right)Y,10\right)$
 $\left[\begin{array}{cccccccccc}3.2657397453750607& -1.132013723965773& 0.3771027876738075& -0.46688107987387883& -0.9199685499404602& 0.6187666279536128& 1.2125167453732142& 0.20969254261276463& -0.353909479087286& -0.19090845989048247\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{2}{\mathrm{π}}& \frac{4}{\mathrm{π}}& \frac{3}{\mathrm{π}}& 0& \frac{3}{\mathrm{π}}& \frac{1}{\mathrm{π}}& \frac{2}{\mathrm{π}}& 0& \frac{5}{\mathrm{π}}& \frac{3}{\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}1.5915494309189535& 0.954929658551372& 0.954929658551372& 2.228169203286535& 0.3183098861837907& 1.2732395447351628& 0.954929658551372& 0.954929658551372& 0.954929658551372& 0.6366197723675814\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}{3}& {6}& {2}& {5}& {2}& {3}& {0}& {7}& {2}& {1}& {3}& {1}& {2}& {5}& {4}& {3}& {2}& {5}& {3}& {5}& {1}& {2}& {2}& {4}& {3}& {4}& {4}& {4}& {2}& {7}& {2}& {1}& {1}& {4}& {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}\end{array}\right]{,}{\mathrm{PLOT}}{}\left({\mathrm{...}}\right)$ (8)
 > $\mathrm{dataset}$
 $\left[\begin{array}{rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr}3& 6& 2& 5& 2& 3& 0& 7& 2& 1& 3& 1& 2& 5& 4& 3& 2& 5& 3& 5& 1& 2& 2& 4& 3& 4& 4& 4& 2& 7& 2& 1& 1& 4& 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\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)$
 ${{\mathrm{_rtable}}}_{{36893628006826898124}}$ (10)
 > $\mathrm{Mean}\left(C\right)$
 ${0.994862958212511}$ (11)
 > $\mathrm{Median}\left(C\right)$
 ${0.455147477689335}$ (12)
 > $\mathrm{Skewness}\left(C\right)$
 ${2.81421618454522}$ (13)
 > $\mathrm{Kurtosis}\left(C\right)$
 ${14.8537269935385}$ (14)
 > $\mathrm{Variance}\left(C\right)$
 ${1.96550597257815}$ (15)
 > $\mathrm{StandardDeviation}\left(C\right)$
 ${1.40196503971324}$ (16)
 > $\mathrm{Quantile}\left(C,0.6\right)$
 ${0.713125222514264}$ (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.