Macaulay2 » Documentation
Packages » RandomMonomialIdeals :: sample
next | previous | forward | backward | up | index | toc

# sample -- generates a sample from the given model

- Usage:
    `sample(Model,ZZ)`
- Inputs:
  - M, an instance of the type Model, to be sampled from
  - N, an integer, sample size
- Outputs:
  - an instance of the type Sample, a sample of size $N$ from the given model $M$

## Description

This function generates $N$ realizations of the random variable that has the distribution specified by the given model.

    i1 : s=sample(ER(3,2,0.2),4)

    o1 = Sample{...4...}

    o1 : Sample

One obtains the data from the object of type Sample (that is, the actual sample in the statistical sense) as follows:

    i2 : getData s

                2   2     2           2         2               2
    o2 = {{x , x , x }, {x }, {x x , x , x x , x }, {x , x x , x }}
            3   2   3     2     1 3   2   2 3   3     1   1 2   2

    o2 : List

The actual sample contains more information than just the data itself:

    i3 : peek s

    o3 = Sample{ModelName => Erdos-Renyi                                          }
                Parameters => (3, 2, .2)
                SampleSize => 4
                               2   2     2           2         2               2
                Data => {{x , x , x }, {x }, {x x , x , x x , x }, {x , x x , x }}
                           3   2   3     2     1 3   2   2 3   3     1   1 2   2

and one can easily obtain sample statistics:

    i4 : statistics(s,degree@@ideal)

    o4 = HashTable{Histogram => Tally{2 => 4}}
                   Mean => 2
                   StdDev => 0

    o4 : HashTable

## See also

- statistics -- generate statistics for a sample
- getData -- get the underlying samples

## Ways to use sample:

- `sample(Model,ZZ)`
- sample(String) -- creates an object of type Sample from a sample stored in a directory on disk

## For the programmer

The object sample is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/RandomMonomialIdeals.m2:1687:0.