what is the best approach to generate random samples from bivariate normal and student T distributions? In both cases sigma is one, mean 0 - so the only parameter I am really interested in is correlation (and degrees of freedom for student t). I need to have the solution in C++, so I can't unfortunately use already implemented functions from MatLab or Mathematica.
You can use the GNU GSL libraries. See here for Bivariate normal:
http://www.gnu.org/software/gsl/manual/html_node/The-Bivariate-Gaussian-Distribution.html
and Student's t-distribution here:
http://www.gnu.org/software/gsl/manual/html_node/The-t_002ddistribution.html
They are straight forward to use.
For a bivariate normal with covariance unity and zero mean, just draw two univariate normals.
If you want to draw a bivariate normal with means (m1, m2), standard deviations (s1, s2) and correlation rho, then draw two unit univariate normals X and Y and set
u = m1 + s1 * X
v = m2 + s2 * (rho X + sqrt(1 - rho^2) Y)
Then u and v are distributed as you wish.
For the Student T, you have to draw a normal variate N and a chi^2 variate V. Then, N / sqrt(V) has T distribution.
To draw the chi^2, you should use a package. Or have a look at Numerical Recipes chapter 7 for how to draw from a Gamma distribution (xhi^2 is a special case of Gamma).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With