Sample - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


Student[Statistics]

  

Sample

  

generate random sample

 

Calling Sequence

Parameters

Description

Computation

Examples

References

Compatibility

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

> 

with⁡StudentStatistics:

Straightforward sampling of a random variable.

> 

X≔NormalRandomVariable⁡0,1

X≔_R

(1)
> 

A≔Sample⁡X,10

A≔−1.07242412799827−0.329077870547065−0.6170919369097900.214466745245291−0.02542812804238461.72882128417783−1.634856754343901.571172171754300.1703584214104081.00647840875181

(2)

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

> 

Sample⁡X,105,output=plot

You can also sample an expression involving two random variables.

> 

Y≔NormalRandomVariable⁡0,1

Y≔_R0

(3)
> 

Sample⁡exp⁡X⁢Y,10

3.26573974537506−1.132013723965770.377102787673808−0.466881079873879−0.9199685499404600.6187666279536131.212516745373210.209692542612765−0.353909479087286−0.190908459890482

(4)

Consider a discrete random variable.

> 

B≔PoissonRandomVariable⁡3

B≔_R1

(5)
> 

Sample⁡Bπ,10

2π4π3π03π1π2π05π3π

(6)

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

> 

Sample⁡Bπ,10,numeric

1.591549430918950.9549296585513720.9549296585513722.228169203286540.3183098861837911.273239544735160.9549296585513720.9549296585513720.9549296585513720.636619772367581

(7)

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

> 

dataset,graph≔Sample⁡B,100,output=both

dataset,graph≔3625230721312543253512243444272114120311305524644432112311332422225321330320325304512325335225518443,PLOT⁡...

(8)
> 

dataset

3625230721312543253512243444272114120311305524644432112311332422225321330320325304512325335225518443

(9)
> 

graph

You can also compute the statistics of the generated data.

> 

C≔Sample⁡X2,104

> 

Mean⁡C

0.994862958212511

(10)
> 

Median⁡C

0.455147477689335

(11)
> 

Skewness⁡C

2.81421618454522

(12)
> 

Kurtosis⁡C

14.8537269935385

(13)
> 

Variance⁡C

1.96550597257815

(14)
> 

StandardDeviation⁡C

1.40196503971324

(15)
> 

Quantile⁡C,0.6

0.713125222514264

(16)
> 

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.

• 

For more information on Maple 18 changes, see Updates in Maple 18.

See Also

Statistics[Sample]

Student

Student[Statistics]

Student[Statistics][RandomVariable]