Random numbers generation

## Random numbers with SN or ST distribution

A recurrent question is: how can I generate pseudo-random numbers with skew-normal (SN), or skew-t (ST), distribution?

Solution A
Download the R 'library sn' and use the functions rsn or rmsn for the SN univariate and multivariate case, respectively. For the ST distribution, use rst and rmst. The master version of the library is the one for the computing environment R; this is available as public domain software, from CRAN.

The Matlab version provides facilities for the SN distribution only (univariate and multivariate), not for the ST distribution.

Solution B
If you want to write a program yourself, there are various algorithms; the following solution is based on one of these alternatives.

Consider first the scalar SN case.

1. Sample $3u_0,~u_1$ having marginal distribution N(0,1) and correlation $3\delta$. A simple way to achieve this is to generate $3u_0,~v$ as independent N(0,1) variates and define $3u_1=\delta~u_0+\sqrt{1-\delta^2}~v$.
2. Then

$3 z=\{\atop{u_1~~~{\rm~if}u_0\geq0}{-u_1~~{\rm~otherwise}}\.$

is a random number sampled from the SN distribution with shape parameter $3\alpha=\delta/\sqrt{1-\delta^2}$.
3. To change the location and scale from (0,1) to (a,b) with b>0, say, set y=a+b z.

Consider now the bivariate SN case; the general multivariate case is similar.
1. Sample $3u_0,~u_1,~u_2$ all having marginal N(0,1) distribution and correlation matrix

$4\Omega^*=$$\array{3,c.cccBCCC&u_0&u_1&u_2\\\hdash~u_0&1&\delta_{1}&\delta_{2}\\u_1&\delta_{1}&1&\omega\\u_2&\delta_{2}&\omega&1}$$$ .

2. Then

$3 z=~(z_1,~z_2)^\top=\{\atop{(u_1,~u_2)^\top,~~{\rm~if}u_0\geq0}{(-u_1,-u_2)^\top,~~~{\rm~otherwise}}\.$

is a random vector sampled from the bivariate SN distribution with (vector) shape parameter
$3\alpha=\frac{\Omega^{-1}\delta}{\sqrt{1-\delta^\top\Omega^{-1}\delta}}$,    where $3\delta=$$\array{\delta_1\\\delta_2$$,~~~\Omega=$$\array{1&\omega\\\omega&1$$.$
For mathematical details and the general multivariate case, see Proposition 1 of Azzalini & Capitanio (1999).
3. If required, change the location and scale of z, similarly to the scalar case; this must be done component by component.

To obtain a ST variate, generate $3V\sim\chi^2_\nu$ and put $3w=z/\sqrt{V/\nu}$; then w has ST distribution with $3\nu$ degrees of freedom and shape parameter equal to the one of z. This works both for z scalar or multivariate. Again, this can be followed by scale and location change of w. For mathematical details, see Section 4 of Azzalini & Capitanio (2003).

Solution C
Click here

Go back to the Skew-Normal distribution