<?xml version="1.0" encoding="UTF-8"?>

<!--
 *
 * This help file was generated from distfun_vectorrnd.sci using help_from_sci().
 *
 -->

<refentry version="5.0-subset Scilab" xml:id="distfun_vectorrnd" xml:lang="en"
          xmlns="http://docbook.org/ns/docbook"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg"
          xmlns:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:scilab="http://www.scilab.org"
          xmlns:db="http://docbook.org/ns/docbook">

  <refnamediv>
    <refname>distfun_vectorrnd</refname>
    <refpurpose>Random vectors.</refpurpose>
  </refnamediv>


<refsynopsisdiv>
   <title>Calling Sequence</title>
   <synopsis>
   x=distfun_vectorrnd(r)
   x=distfun_vectorrnd(r,n)
   x=distfun_vectorrnd(r,n,sigma)
   
   </synopsis>
</refsynopsisdiv>

<refsection>
   <title>Parameters</title>
   <variablelist>
   <varlistentry><term>r :</term>
      <listitem><para> a list with d items describing the multivariate random variable (see below)</para></listitem></varlistentry>
   <varlistentry><term>n :</term>
      <listitem><para> a 1-by-1 matrix of floating point integers, the number of rows in x (default n = 1)</para></listitem></varlistentry>
   <varlistentry><term>sigma :</term>
      <listitem><para> a d-by-d matrix of doubles, the covariance matrix, symmetric, positive definite (default = identity)</para></listitem></varlistentry>
   <varlistentry><term>x:</term>
      <listitem><para> a m-by-n matrix of doubles, the random numbers.</para></listitem></varlistentry>
   </variablelist>
</refsection>

<refsection>
   <title>Description</title>
   <para>
Generate a multivariate random vector given
marginal and covariance matrix.
   </para>
   <para>
The covariance matrix sigma must have unit diagonal.
Its non-diagonal terms must be in the range [0,1).
   </para>
   <para>
If sigma is not provided (default), then
the multivariate sample is generated by direct
simulation, considering that the dimensions
are independent.
   </para>
   <para>
If sigma is provided, the algorithm produces a sample with
Gaussian copula.
   </para>
   <para>
The variable r is a list of n items, where r(i) is a list
which describes the i-th random variable.
The first item in r(i) is a string, which is the short name of the
distribution.
The used map is defined by distfun_list.
   </para>
   <para>
Implementation notes
   </para>
   <para>
If sigma is provided, the algorithm is the following.
<itemizedlist>
<listitem>
<para>
Generate Z=[Z1,...,Zd] with zero mean, and given covariance.
</para>
</listitem>
<listitem>
<para>
Compute U = [Phi(Z1),...,Phi(Zd)],
where Phi is the standard normal cumulative distribution function.
</para>
</listitem>
<listitem>
<para>
Compute X = [Q1(U1),...,Qd(Ud)],
where Qi is the quantile function of the i-th marginal.
</para>
</listitem>
</itemizedlist>
   </para>
   <para>
</para>
</refsection>

<refsection>
   <title>Examples</title>
   <programlisting role="example"><![CDATA[
sigma = [
1.0  0.5
0.5  1.0
]
v1=list("unif",5,12) // Uniform(min=5,max=12)
v2=list("norm",-5,7) // Normal(mean=-5,sigma=7)
r=list(v1,v2)
n=10 // Number of outcomes
x=distfun_vectorrnd(r,n,sigma)

// Graphical "test" (requires Stixbox)
x=distfun_vectorrnd(r,1000,sigma);
scf();
for i=1:4
subplot(2,2,i)
rho=(i-1)/4;
sigma = [1.0  rho;rho  1.0];
x=distfun_vectorrnd(r,1000,sigma);
plot(x(:,1),x(:,2),"bo");
title("rho="+string(rho));
end
scf();
subplot(1,2,1)
histo(x(:,1));
title("Uniform(5,12)");
subplot(1,2,2)
histo(x(:,2));
title("Normal(-5,7)");

   ]]></programlisting>
</refsection>

<refsection>
   <title>Bibliography</title>
   <para>http://web.ics.purdue.edu/~hwan/IE680/Lectures/Chap08Slides.pdf</para>
   <para>http://fr.mathworks.com/help/stats/examples/simulating-dependent-random-variables-using-copulas.html</para>
</refsection>

<refsection>
   <title>Authors</title>
   <simplelist type="vert">
   <member>Copyright (C) 2014 - Michael Baudin</member>
   </simplelist>
</refsection>
</refentry>
