5. Functions of a Random Variable Let X be a r.v defined on the model (Ω, F , P ), and suppose g(x) is a function of the variable x. Define Y = g ( X ). (5-1) Is Y necessarily a r.v? If so what is its PDF FY ( y ), pdf fY ( y ) ? Clearly if Y is a r.v, then for every Borel set B, the set of ξfor which Y (ξ ) ∈ B must belong to F. Given that X is a r.v, this is assured if g −1 ( B ) is also a Borel set, i.e., if g(x) is a Borel function. In that case if X is a r.v, so is Y, and for every Borel set B P (Y ∈ B ) = P ( X ∈ g −1 ( B )). (5-2) 1 PILLAI In particular FY ( y ) = P (Y (ξ ) ≤ y ) = P (g ( X (ξ )) ≤ y ) = P (X (ξ ) ≤ g −1 ( −∞, y ]). (5-3) Thus the distribution function as well of the density function of Y can be determined in terms of that of X. To obtain the distribution function of Y, we must determine the Borel set on the x-axis such that X (ξ ) ≤ g −1 ( y ) for every given y, and the probability of that set. At this point, we shall consider some of the following functions to illustrate the technical details. aX + b X2 Y = g( X ) log X |X | X eX | X | U ( x) 2 PILLAI Example 5.1: Y = aX + b Solution: Suppose a > 0 . FY ( y) = P(Y (ξ ) ≤ y ) = P(aX (ξ ) + b ≤ y ) = P X (ξ ) ≤ and (5-4) y −b y −b = FX . (5-5) a a y −b 1 fY ( y) = f X . a a On the other hand if a < 0 , then FY ( y ) = P(Y (ξ ) ≤ y ) = P(aX (ξ ) + b ≤ y ) = P = 1 − FX and hence y −b , a fY ( y) = − (5-6) y −b X (ξ ) > a (5-7) y −b 1 fX . a a (5-8) 3 PILLAI From (5-6) and (5-8), we obtain (for all a) fY ( y) = y −b 1 fX . a |a | (5-9) (5-10) Example 5.2: Y = X 2 . FY ( y ) = P (Y (ξ ) ≤ y ) = P (X 2 (ξ ) ≤ y ). (5-11) If y < 0 , then the event { X 2 (ξ ) ≤ y}= φ , and hence (5-12) FY ( y ) = 0, y < 0. For y > 0 , from Fig. 5.1, the event is equivalent to { x1 < X (ξ ) ≤ x 2 }. {Y (ξ ) ≤ y } = { X 2 (ξ ) ≤ y } Y = X2 y x1 Fig. 5.1 x2 X 4 PILLAI Hence FY ( y ) = P ( x1 < X (ξ ) ≤ x 2 ) = F X ( x 2 ) − F X ( x1 ) = FX ( y ) − FX ( − y ), (5-13) y > 0. By direct differentiation, we get 1 fY ( y ) = 2 ( f y X ( y ) + f X (− ) y) , 0, If f X (x) y > 0, otherwise . (5-14) represents an even function, then (5-14) reduces to fY ( y ) = 1 fX y ( y ) U ( y ). (5-15) In particular if X ∼ N ( 0 ,1), so that fX (x) = 1 − x2 /2 e , 2π (5-16) 5 PILLAI and substituting this into (5-14) or (5-15), we obtain the p.d.f of Y = X 2 to be fY ( y ) = 1 e − y / 2U ( y ). 2π y (5-17) On comparing this with (3-36), we notice that (5-17) represents a Chi-square r.v with n = 1, since Γ (1 / 2 ) = π . Thus, if X is a Gaussian r.v with µ = 0, then Y = X 2 represents a Chi-square r.v with one degree of freedom (n = 1). Example 5.3: Let X − c, Y = g( X ) = 0, X + c, X > c, − c < X ≤ c, X ≤ − c. 6 PILLAI In this case P (Y = 0) = P ( − c < X (ξ ) ≤ c ) = FX ( c ) − FX ( − c ). For y > 0 , we have x > c , and Y (ξ ) = X (ξ ) − c FY ( y ) = P (Y (ξ ) ≤ y ) = P ( X (ξ ) − c ≤ y ) Similarly = P ( X (ξ ) ≤ y + c ) = FX ( y + c ), y > 0 . y < 0 , if x < − c , and Y ( ξ ) = X ( ξ ) + c FY ( y ) = P (Y (ξ ) ≤ y ) = P ( X (ξ ) + c ≤ y ) = P ( X (ξ ) ≤ y − c ) = FX ( y − c ), Thus f X ( y + c ), y < 0. g( X ) c (a) (5-19) so that (5-20) (5-21) y < 0. FX (x ) −c so that y > 0, f Y ( y ) = [ FX ( c ) − FX ( − c )]δ ( y ), f X ( y − c ), (5-18) FY ( y ) X (b) Fig. 5.2 x (c) y 7 PILLAI Example 5.4: Half-wave rectifier Y = g ( X ); g ( x) = x, x > 0, 0, x ≤ 0. (5-22) Y In this case P (Y = 0) = P ( X (ξ ) ≤ 0) = FX ( 0). (5-23) X Fig. 5.3 and for y > 0 , since Y = X , FY ( y ) = P(Y (ξ ) ≤ y ) = P( X (ξ ) ≤ y ) = FX ( y ). (5-24) Thus f X ( y ), y > 0, f Y ( y ) = FX (0)δ ( y ) y = 0, 0, = f X ( y )U ( y ) + FX (0)δ ( y ). (5-25) y < 0, 8 PILLAI Note: As a general approach, given Y = g ( X ), first sketch the graph y = g ( x ), and determine the range space of y. Suppose a < y < b is the range space of y = g ( x ). Then clearly for y < a, FY ( y) = 0, and for y > b, FY ( y) = 1, so that FY ( y) can be nonzero only in a < y < b. Next, determine whether there are discontinuities in the range space of y. If so evaluate P(Y (ξ ) = yi ) at these discontinuities. In the continuous region of y, use the basic approach FY ( y ) = P (g ( X (ξ )) ≤ y ) and determine appropriate events in terms of the r.v X for every y. Finally, we must have FY ( y ) for −∞ < y < +∞, and obtain fY ( y ) = dFY ( y ) dy in a < y < b. 9 PILLAI However, if Y = g(X ) is a continuous function, it is easy to establish a direct procedure to obtain fY (y). A continuos function g(x) with g′(x) nonzero at all but a finite number of points, has only a finite number of maxima and minima, and it eventually becomes monotonic as | x |→ ∞. Consider a specific y on the y-axis, and a positive increment ∆ y as shown in Fig. 5.4 g (x ) y + ∆y y x 1 x1 + ∆x1 x 2 + ∆x 2 x 2 x 3 x3 + ∆x3 x Fig. 5.4 fY (y) for Y = g(X ), where g (⋅) is of continuous type. 10 PILLAI Using (3-28) we can write P {y < Y (ξ ) ≤ y + ∆ y } = y + ∆y y f Y ( u ) du ≈ f Y ( y ) ⋅ ∆ y . (5-26) But the event {y < Y (ξ ) ≤ y + ∆ y } can be expressed in terms of X (ξ ) as well. To see this, referring back to Fig. 5.4, we notice that the equation y = g(x) has three solutions x1 , x2 , x3 (for the specific y chosen there). As a result when {y < Y (ξ ) ≤ y + ∆ y }, the r.v X could be in any one of the three mutually exclusive intervals {x1 < X (ξ ) ≤ x1 + ∆x1}, {x2 + ∆x2 < X (ξ ) ≤ x2} or {x3 < X (ξ ) ≤ x3 + ∆x3}. Hence the probability of the event in (5-26) is the sum of the probability of the above three events, i.e., P {y < Y (ξ ) ≤ y + ∆ y } = P { x1 < X (ξ ) ≤ x1 + ∆ x1 } + P { x 2 + ∆ x 2 < X (ξ ) ≤ x 2 } + P { x 3 < X (ξ ) ≤ x 3 + ∆ x 3 } .(5-27) 11 PILLAI For small ∆y, ∆xi , making use of the approximation in (5-26), we get fY ( y )∆y = f X ( x1 )∆x1 + f X ( x2 )( − ∆x2 ) + f X ( x3 )∆x3. (5-28) In this case, ∆x1 > 0, ∆x2 < 0 and ∆x3 > 0, so that (5-28) can be rewritten as fY ( y ) = f X ( xi ) i | ∆xi | = ∆y i 1 f X ( xi ) ∆y / ∆xi (5-29) and as ∆y → 0, (5-29) can be expressed as fY ( y ) = i 1 f X ( xi ) = dy / dx x i i 1 f X ( xi ). g ′( xi ) (5-30) The summation index i in (5-30) depends on y, and for every y the equation y = g ( xi ) must be solved to obtain the total number of solutions at every y, and the actual solutions x1 , x2 , 12 all in terms of y. PILLAI For example, if Y = X 2 , then for all y > 0, x1 = − y and x2 = + y represent the two solutions for each y. Notice that the solutions xi are all in terms of y so that the right side of (5-30) 2 Y = X is only a function of y. Referring back to the example (Example 5.2) here for each y > 0, there are two solutions given by x1 = − y and x2 = + y . ( fY ( y ) = 0 for y < 0 ). Y=X Moreover 2 dy dy = 2 x so that =2 y dx dx x = xi y and using (5-30) we get 1 fY ( y ) = 2 ( f y x1 X ) ( y ) + f X (− y ) , 0, which agrees with (5-14). Fig. 5.5 y > 0, otherwise , X x2 (5-31) 13 PILLAI Example 5.5: 1 Y = . X (5-32) Find fY ( y). Solution: Here for every y, dy 1 = − 2 so that dx x x1 = 1 / y dy dx is the only solution, and = x = x1 1 2 = y , 2 1/ y and substituting this into (5-30), we obtain 1 1 fY ( y ) = 2 f X . y y (5-33) In particular, suppose X is a Cauchy r.v as in (3-39) with parameter α so that α /π f X ( x) = 2 , − ∞ < x < +∞. 2 α +x (5-34) In that case from (5-33), Y = 1 / X has the p.d.f fY ( y ) = 1 (1 / α ) / π α /π = , 2 2 2 2 2 y α + (1 / y ) (1 / α ) + y − ∞ < y < +∞ . (5-35) 14 PILLAI But (5-35) represents the p.d.f of a Cauchy r.v with parameter 1 / α . Thus if X ∼ C (α ), then 1 / X ∼ C (1 / α ). Example 5.6: Suppose f X ( x ) = 2 x / π 2 , 0 < x < π , and Y = sin X . Determine fY ( y ). Solution: Since X has zero probability of falling outside the interval (0,π ), y = sin x has zero probability of falling outside the interval ( 0 ,1). Clearly fY ( y ) = 0 outside this interval. For any 0 < y < 1, from Fig.5.6(b), the equation y = sin x has an infinite number of solutions , x1 , x2 , x3 , , where x1 = sin −1 y is the principal solution. Moreover, using the symmetry we also get x2 = π − x1 etc. Further, dy = cos x = 1 − sin 2 x = 1 − y 2 dx so that dy = 1 − y2 . dx x = xi 15 PILLAI fX (x) x3 π (a) x y = sin x y x −1 x1 x2 π x3 x (b) Fig. 5.6 Using this in (5-30), we obtain for 0 < y < 1, fY ( y ) = +∞ i = −∞ i ≠0 1 1− y 2 f X ( x i ). (5-36) But from Fig. 5.6(a), in this case f X ( x−1 ) = f X ( x3 ) = f X ( x4 ) = (Except for f X ( x1 ) and f X ( x 2 ) the rest are all zeros). 16 =0 PILLAI Thus (Fig. 5.7) fY ( y ) = = 1 1 − y2 ( f X ( x1 ) + 2 ( x 1 + π − x1 ) π 2 1− y 2 f X ( x2 ) ) = 2 = π 1 − y2 0, , 1 1 − y2 2 x1 π2 0 < y < 1, otherwise. + fY ( y ) 2 x2 π2 2 (5-37) π Fig. 5.7 y 1 Example 5.7: Let Y = tan X where X ∼ U (− π / 2, π / 2 ) . Determine fY ( y ). Solution: As x moves from (−π / 2, π / 2) , y moves from (− ∞ , + ∞ ) . From Fig.5.8(b), the function Y = tan X is one-to-one for −π / 2< x <π / 2. For any y, x1 = tan−1 y is the principal solution. Further dy d tan x = = sec 2 x = 1 + tan 2 x = 1 + y 2 dx dx 17 PILLAI so that using (5-30) fY ( y ) = 1 1/π f X ( x1 ) = , 2 | dy / dx |x = x1 1+ y (5-38) − ∞ < y < +∞ , which represents a Cauchy density function with parameter equal to unity (Fig. 5.9). f X (x ) −π /2 π /2 x fY ( y ) = (a) y = tan x −π /2 y y x1 π / 2 (b) Fig. 5.8 1 1 + y2 x Fig. 5.9 18 PILLAI Functions of a discrete-type r.v Suppose X is a discrete-type r.v with P ( X = xi ) = pi , x = x1 , x2 , (5-39) , xi , and Y = g ( X ). Clearly Y is also of discrete-type, and when x = xi , yi = g ( xi ), and for those yi P (Y = yi ) = P( X = xi ) = pi , y = y1 , y2 , , yi , (5-40) Example 5.8: Suppose X ∼ P (λ ), so that P ( X = k ) = e −λ λk k! , k = 0,1,2, Define Y = X 2 + 1. Find the p.m.f of Y. Solution: X takes the values 0 ,1, 2 , , k , takes the value 1, 2, 5, , k 2 + 1, and (5-41) so that Y only 19 PILLAI P(Y = k 2 + 1) = P( X = k ) so that for j = k 2 + 1 ( P(Y = j ) = P X = ) j − 1 = e− λ λ j −1 ( j − 1)! , j = 1, 2,5, , k 2 + 1, . (5-42) 20 PILLAI