This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Stat 6304 Computational Statistics Generating Discrete Random Variables The Inverse Transform Method • Purpose: To generate the value of a discrete random variable X having probability: Pr( X = x j ) = p j , j = 0 , 1 ,..., summationdisplay j p j = 1 . • Approach: Generate a uniform random number U and set X = x , if U < p x j , if j 1 ∑ i =1 p i ≤ U < j ∑ i =1 p i ,j = 1 , 2 ,... • The inverse transform method sets X = j 1 if U falls in the jth interval. It involves search of the interval where U lies. 1 Pr( X = 0) U ? Pr( X = 1) U ? Pr( X = 2) U ? ······ Pr( X = n ) U ? 1 The Inverse Transform Method • Justification: Pr( X = x j ) = Pr j 1 summationdisplay i =1 p i < U < j summationdisplay i =1 p i = p j Thus, X has the desired distribution. • Let F ( x ) = summationdisplay x j <x Pr( X = x j ) = summationdisplay x j <x p i = Pr( X < x ) , then F ( x j ) = j 1 summationdisplay i =1 p i and X = F 1 ( U ) 2 Example 1: Bernoulli Distribution • Let X ∼ Bernoulli( p ), namely Pr( X = 1) = p and Pr( X = 0) = 1 p. • Then we set X = braceleftbigg 1 , if U < p , otherwise • In SPLUS/R, the code for generating 50 Bernoulli( p ) variable is x < rep(0,50) u < runif(50) x[u < p] < 1 3 Example 2: Fourpoint distribution • If we want to generate 100 random numbers from a random variable X with Pr( X = 1) = 0 . 2 Pr( X = 2 . 5) = 0 . 15 Pr( X = 4) = 0 . 25 Pr( X = 10) = 0 . 4 • The SPLUS/R code is x < rep(10,100); U < runif(100) x[u < 0.6] < 4 x[u < 0.35] < 2.5 x[u < 0.2] < 1 • In the computer program, we can do the following: If U < . 20 set X = 1 and stop If U < . 35 set X = 2 . 5 and stop If U < . 60 set X = 4 and stop Otherwise X = 10 • A more efficient algorithm: If U < . 40 set X = 10 and stop If U < . 65 set X = 3 and stop If U < . 85 set X = 1 and stop Otherwise X = 2 4 Example 3: Discrete Uniform • Wish to simulate X with Pr( X = x j ) = 1 N , j = 1 ,.. .,N. • By the inverse transform method, X = x j , if j 1 N ≤ U < j N or j 1 ≤ NU < j • The above condition is equivalent to X = x j , if int ( NU ) = j 1 • In particular, if x j = j , then X = j, if int ( NU ) = j 1 ⇔ X = int ( NU )+1 5 Example 3: Discrete Uniform • This is equivalent to sample with replacement a45 draw with replacement x 1 x 2 x 3 ······ x n • In SPLUS/R, the code is U < runif(100) X < floor(N*U) + 1 6 Example 4: Sampling without replacement...
View
Full Document
 Spring '10
 Tom
 Probability distribution, Probability theory, Cumulative distribution function, Discrete probability distribution, pj

Click to edit the document details