Generation of random numbers (exponential distribution) by inverse distribution function method R language implementation

Source: Internet
Author: User

First of all, the symbol: U (0,1)-Uniform distribution, "~" is to obey the XXX distribution, F (x), for the need to generate a random number distribution function, INVF (x) to represent the inverse distribution function, then the algorithm steps are as follows:

Step 1: Generate U~u (0,1)

Step 2: Calculate X=INVF (U)

So x is the random number that obeys the distribution function f (x), a simple proof:

Proof: P (x<y) =p (INVF (U) <y) =p (u<f (y)) =f (y); The certificate is completed.

You're going to feel so easy, yes, it's very simple, here's the usual exponential distribution.
First, the distribution function of the exponential distribution:

F (x) =1-exp (-lamda*x); x>0 (Lamda as parameter)

So the inverse distribution function:

INVF (x) =-(1/LAMDA) *ln (1-x); 0<x<1

So the random number generation process:

Step 1: Generate U~u (0,1)

Step 2: Calculate X=-ln (1-u)

Get random numbers

X <-runif (+) Lamda <-0.1U <-runif (+) Lamda <-0.1X <- -1/lamda * log (U) hist (X,prob=t,col=gray (0.9), Mai N= "exp from uniform") curve (Dexp (X,LAMDA), add=t,col= "Red")

  

Generation of random numbers (exponential distribution) by inverse distribution function method R language implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.