1
$\begingroup$

I would like to create a random number generator for the normal distribution via using a uniform linear congruential generator (on uniform distribution) and the inversion method.

However, I'm getting stuck at the final state. Please correct my understanding at any point!

Say i have an LCG, which generates numbers from 0 - 1. It follows a uniform distribution of (0,1).

Now, I want my subsequent normal distribution (X) to follow the same range, so it's standard normal, hence i normalize the area

enter image description here

Now

enter image description here

Using taylor series as this cannot be integrated, I get

enter image description here

However, now I'm stuck. even if i integrate this, I cannot invert this to y = f(x) due to the powers of y. Am I even going about this right?

Any help will be much appreciated! thank you!

$\endgroup$
9
  • 2
    $\begingroup$ Why not simply use inverse transform stats.stackexchange.com/questions/184325/… ? $\endgroup$
    – Tim
    Sep 21, 2016 at 14:36
  • 1
    $\begingroup$ ...I was not aware such a magical function existed, thought I had to figure it out by hand. For curiositys sake, how would i compute this manually? $\endgroup$
    – Wboy
    Sep 21, 2016 at 14:43
  • 2
    $\begingroup$ What you're trying to do is not a correct implementation of 'the inversion method'. Done correctly, you'd be trying to invert the normal cdf. $\endgroup$
    – Glen_b
    Sep 21, 2016 at 16:05
  • 1
    $\begingroup$ No, you're not. There's several errors all at once which makes it hard to untangle. $\endgroup$
    – Glen_b
    Sep 21, 2016 at 16:12
  • 2
    $\begingroup$ There's a graphical illustration of the inversion method for the normal case on the Wikipedia page Inverse transform sampling. Reading the article may help clarify ideas for you. $\endgroup$
    – Glen_b
    Sep 21, 2016 at 16:17

1 Answer 1

5
$\begingroup$

To sample from any distribution using uniform distribution you can use inverse transform method, so there is no need in re-inventing the wheel. For this you simply need to use inverse cumulative distribution function (also known as quantile function) of normal distribution

$$ F^{-1}(p) = \mu+\sigma\sqrt{2}\,\operatorname{erf}^{-1}(2p-1) $$

where $\operatorname{erf}$ is error function, and then take uniformly distributed random variable $U \sim \mathrm{Unif}(0, 1)$ and pass it through the quantile function

$$ X = F^{-1}(U) $$

resulting variable $X$ will follow normal distribution.

Most statistical software would provide you with quantile function for normal distribution already implemented (e.g. qnorm in R), but if you need to implement it by hand, you can check the following paper that describes algorithm that is used in R:

Wichura, M. J. (1988) Algorithm AS 241: The percentage points of the normal distribution. Applied Statistics, 37, 477–484.

or simply take a look at source code of R's qnorm.

$\endgroup$
1
  • $\begingroup$ Thank you so much for your help! :) while that presents an alternative way, is there a way to do this via the method i mentioned? Namely, taking the range of the Uniform distribution, setting the distribution i want (standard norm) and normalizing it, attempting to integrate to get the cdf then invert etc? $\endgroup$
    – Wboy
    Sep 21, 2016 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.