<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2000 - INRIA - Carlos Klimann
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="sample">
    <refnamediv>
        <refname>sample</refname>
        <refpurpose>Sampling with replacement</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>s = sample(n,X,orient)</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>n</term>
                <listitem>
                    <para>positive integer (size of sample)</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>X</term>
                <listitem>
                    <para>matrix. Samples will be extracted from this matrix.</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>orient</term>
                <listitem>
                    <para>
                        Optional parameter. Admissible values are <literal>{'*'}, 1, 2, 'r'</literal> or <literal>'c'</literal>. The orientation to sample rows or columns. See Description below.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>s</term>
                <listitem>
                    <para>vector or matrix containing sample</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            This function returns a  vector or matrix. It contains
            a random  sample of <literal>n</literal> extractions,  with replacement, from
            the matrix <literal>X</literal>.
        </para>
        <para>
            <literal>s = sample(n, X)</literal>  (or <literal>s = sample(n, X, '*')</literal>)  returns a  vector <literal>s</literal>
            whose  values are  a random  sample  of <literal>n</literal>  values,
            extracted with replacement, from <literal>X</literal>.
        </para>
        <para>

            <literal>s = sample(n, X, 'r')</literal>   (or,   equivalently,  <literal>s = sample(n, X, 1)</literal>)
            returns  a matrix  of size  <literal>size(X,'r') * n</literal>.  It  contains a
            random sample of <literal>n</literal>  rows, extracted with replacement, from
            the rows of <literal>X</literal>.
        </para>
        <para>

            <literal>s = sample(n, X, 'c')</literal>   (or,   equivalently,  <literal>s = sample(n, X, 2)</literal>)
            returns  a matrix  of size  <literal>n * size(X, 'c')</literal>.  It  contains a
            random  sample of <literal>n</literal> columns,  extracted  with replacement
            from the columns of <literal>X</literal>.
        </para>
    </refsection>
    <refsection>
        <title> Random number generator </title>
        <para>
            <literal>sample</literal> is based on <link linkend="grand">grand</link> for generating the random samples. Use <literal>grand("setsd", seed)</literal> to change the seed for <literal>samplef</literal>.
        </para>
        <programlisting role="example"><![CDATA[
            seed = getdate("s");
            grand("setsd", seed); //sets the seed to current date

            seed = 0;
            grand("setsd", seed); //sets the seed to default value
            ]]>
        </programlisting>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
X = ['a' 'dd' 'arreu'; 'ber' 'car' 'zon']
s = sample(25, X)
s = sample(25, X, 'r')
s = sample(25, X, 'c')
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="samplef">samplef</link>
            </member>
            <member>
                <link linkend="samwr">samwr</link>
            </member>
            <member>
                <link linkend="grand">grand</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
