Salta al contenuto
Note per Studenti Functions of a Random Variable Report

Functions of a Random Variable

In questa pagina 9

The problem

Let XX be a random variable and g:R→Rg:\mathbb{R}\to\mathbb{R} a function; the goal is to find the probabilistic description of the random variable Y=g(X)Y=g(X).

For discrete XX the problem is already solved:

pY(yℓ)=∑xk: g(xk)=yℓpX(xk).p_Y(y_\ell)=\sum_{x_k:\ g(x_k)=y_\ell} p_X(x_k).

For general random variables the problem is slightly more complicated.

Problem. For Y=g(X)Y=g(X), given FX(x)F_X(x) or fX(x)f_X(x) and the function g(x)g(x), find FY(y)F_Y(y) and/or fY(y)f_Y(y).

Since the general problem is considered, XX can be discrete, absolutely continuous or mixed. Depending on the "interaction" between fX(x)f_X(x) and g(x)g(x) anything can happen: discrete X→X \to discrete YY, absolutely continuous X→X \to absolutely continuous YY, absolutely continuous X→X \to discrete YY, absolutely continuous X→X \to mixed YY.

In the formulas below 1(x)\mathbb{1}(x) denotes the unit step function (zero for x<0x<0, one for x≥0x\ge 0, as the use 1(k−1)\mathbb{1}(k-1) for the support k≥1k\ge 1 of a geometric variable shows) and χA\chi_A the indicator function of a set AA.

General strategy: start from the distribution function

Find the DF of YY first:

FY(y)=P(Y≤y)=P(g(X)≤y)=P(X∈g−1((−∞,y])).F_Y(y)=P(Y\le y)=P(g(X)\le y)=P\big(X\in g^{-1}((-\infty,y])\big).

The density, when it exists, is obtained by differentiating: fY(y)=ddyFY(y)f_Y(y)=\dfrac{d}{dy}F_Y(y). The formula looks very abstract; the only way to understand how it works is practice, so several examples follow.

Example 1: affine function Y=aX+bY=aX+b

Let X∼fX(x)X\sim f_X(x). Then

FY(y)=P(aX+b≤y)={P ⁣(X≤y−ba)a>0P ⁣(X≥y−ba)a<0F_Y(y)=P(aX+b\le y)=\begin{cases}P\!\left(X\le \dfrac{y-b}{a}\right) & a>0\\[2mm] P\!\left(X\ge \dfrac{y-b}{a}\right) & a<0\end{cases}

(the figure shows the line g(x)=ax+bg(x)=ax+b for a>0a>0 and a<0a<0: the set {x:g(x)≤y}\{x: g(x)\le y\} is the half line to the left of x=y−bax=\frac{y-b}{a} if a>0a>0, to the right if a<0a<0). Hence

FY(y)={FX ⁣(y−ba)a>01−FX ⁣(y−ba)a<0F_Y(y)=\begin{cases}F_X\!\left(\dfrac{y-b}{a}\right) & a>0\\[2mm] 1-F_X\!\left(\dfrac{y-b}{a}\right) & a<0\end{cases}

and taking the derivative

 fY(y)=1∣a∣ fX ⁣(y−ba) (∗)\boxed{\,f_Y(y)=\frac{1}{|a|}\,f_X\!\left(\frac{y-b}{a}\right)\,}\qquad(*)

The part of the computation that takes the inverse images g−1((−∞,y])g^{-1}((-\infty,y]) and writes FYF_Y in terms of FXF_X does not depend on the actual form of FXF_X or fXf_X.

Special case 1: Gaussian. Y=aX+bY=aX+b, X∼N(μ,σ2)X\sim N(\mu,\sigma^2) ⇒\Rightarrow Y∼N(aμ+b, a2σ2)Y\sim N(a\mu+b,\ a^2\sigma^2). This is derived by substituting the N(μ,σ2)N(\mu,\sigma^2) density in (∗)(*).

Special case 2: uniform. Y=aX+bY=aX+b, X∼U([c,d])X\sim \mathcal{U}([c,d]) gives

Y∼{U([ac+b, ad+b])a>0U([ad+b, ac+b])a<0Y\sim\begin{cases}\mathcal{U}([ac+b,\ ad+b]) & a>0\\ \mathcal{U}([ad+b,\ ac+b]) & a<0\end{cases}

Proof (case a>0a>0): fX(x)=1d−cχ[c,d](x)f_X(x)=\frac{1}{d-c}\chi_{[c,d]}(x), so by (∗)(*)

fY(y)=1a 1d−c χ[c,d] ⁣(y−ba)=1ad−ac χ[ac+b, ad+b](y),f_Y(y)=\frac1a\,\frac1{d-c}\,\chi_{[c,d]}\!\left(\frac{y-b}{a}\right)=\frac{1}{ad-ac}\,\chi_{[ac+b,\ ad+b]}(y),

because y−ba=c⇒y=ac+b\frac{y-b}{a}=c \Rightarrow y=ac+b, and similarly for dd.

Special case 3: exponential. Y=aX+bY=aX+b, X∼Exp(λ)X\sim \mathrm{Exp}(\lambda):

fY(y)=1∣a∣fX ⁣(y−ba)=1∣a∣ λ e−λy−ba 1 ⁣(y−ba).f_Y(y)=\frac1{|a|}f_X\!\left(\frac{y-b}{a}\right)=\frac1{|a|}\,\lambda\, e^{-\lambda\frac{y-b}{a}}\,\mathbb{1}\!\left(\frac{y-b}{a}\right).

Question: is the exponential density preserved by affine transformations like the Gaussian and the uniform?

  • If a<0a<0 the values taken by YY when X∈[0,∞)X\in[0,\infty) range over (−∞,b](-\infty,b], therefore YY cannot be exponential.
  • If a>0a>0 the values of YY range over [b,∞)[b,\infty); if b=0b=0 then YY is exponential.

Conclusion: Y=aXY=aX with a>0a>0 and X∼Exp(λ)X\sim\mathrm{Exp}(\lambda) ⇒\Rightarrow Y∼Exp ⁣(λa)Y\sim \mathrm{Exp}\!\left(\dfrac{\lambda}{a}\right).

Example 2: rectifier

A very common signal transformation in electronics. Analytically

Y=g(X)=X 1(X)Y=g(X)=X\,\mathbb{1}(X)

(graph: zero for x<0x<0, the identity for x≥0x\ge0). First the part of the computation that does not depend on FXF_X or fXf_X:

FY(y)=P(X1(X)≤y)=P(X∈g−1((−∞,y]))={P(X≤y)y≥0P(∅)y<0F_Y(y)=P(X\mathbb{1}(X)\le y)=P\big(X\in g^{-1}((-\infty,y])\big)=\begin{cases}P(X\le y) & y\ge0\\ P(\emptyset) & y<0\end{cases}

since g−1((−∞,y])={x:g(x)≤y}g^{-1}((-\infty,y])=\{x:g(x)\le y\} equals {x:x≤y}\{x:x\le y\} for y≥0y\ge 0 and ∅\emptyset for y<0y<0. Therefore

FY(y)={FX(y)y≥00y<0=FX(y) 1(y).F_Y(y)=\begin{cases}F_X(y) & y\ge0\\ 0 & y<0\end{cases}=F_X(y)\,\mathbb{1}(y).

Special case 1: X∼N(0,1)X\sim N(0,1). FYF_Y is the Gaussian DF Φ\Phi for y≥0y\ge0 and 00 for y<0y<0, so it jumps at y=0y=0 from 00 to 12\tfrac12 (figure). The density is

fY(y)=fX(y)1(y)+12δ(y)=12[22πe−12y21(y)]+12δ(y).f_Y(y)=f_X(y)\mathbb{1}(y)+\frac12\delta(y)=\frac12\left[\frac{2}{\sqrt{2\pi}}e^{-\frac12 y^2}\mathbb{1}(y)\right]+\frac12\delta(y).

The random variable YY is mixed: P(Y=0)=1/2P(Y=0)=1/2.

Special case 2: X∼Exp(λ)X\sim\mathrm{Exp}(\lambda). Then Y∼Exp(λ)Y\sim\mathrm{Exp}(\lambda). No computation is necessary: on the support of the density of XX the function gg is the identity, Y=g(X)=XY=g(X)=X for all x≥0x\ge0.

Special case 3: XX uniform. Without computations one can convince oneself that:

  • X∼U([1,2])⇒Y∼U([1,2])X\sim\mathcal{U}([1,2])\Rightarrow Y\sim\mathcal{U}([1,2]);
  • X∼U([−1,1])⇒fY(y)=12δ(y)+12U([0,1])=12δ(y)+12χ[0,1](y)X\sim\mathcal{U}([-1,1])\Rightarrow f_Y(y)=\frac12\delta(y)+\frac12\mathcal{U}([0,1])=\frac12\delta(y)+\frac12\chi_{[0,1]}(y);
  • X∼U([−2,−1])⇒Y=0X\sim\mathcal{U}([-2,-1])\Rightarrow Y=0 (degenerate random variable);
  • X∼U([−1,3])⇒fY(y)=14δ(y)+34U([0,3])X\sim\mathcal{U}([-1,3])\Rightarrow f_Y(y)=\frac14\delta(y)+\frac34\mathcal{U}([0,3]) (the probability 14\frac14 of [−1,0)[-1,0) is collapsed in y=0y=0, the probability 34\frac34 of [0,3][0,3] stays spread).

Example 3: square Y=X2Y=X^2

Another simple and important function. The preliminary work gives

FY(y)=P(X2≤y)={P(−y≤X≤y)y≥0P(∅)y<0=(FX(y)−FX(−y))1(y).F_Y(y)=P(X^2\le y)=\begin{cases}P(-\sqrt y\le X\le\sqrt y) & y\ge0\\ P(\emptyset) & y<0\end{cases}=\big(F_X(\sqrt y)-F_X(-\sqrt y)\big)\mathbb{1}(y).

The corresponding density is

fY(y)=[12yfX(y)+12yfX(−y)]1(y)+[FX(y)−FX(−y)]δ(y),f_Y(y)=\left[\frac{1}{2\sqrt y}f_X(\sqrt y)+\frac1{2\sqrt y}f_X(-\sqrt y)\right]\mathbb{1}(y)+\big[F_X(\sqrt y)-F_X(-\sqrt y)\big]\delta(y),

where the bracket multiplying δ(y)\delta(y) is 00 (it is evaluated at y=0y=0), so the delta term disappears.

Special case: X∼N(0,1)X\sim N(0,1). Here fXf_X is an even function, so

fY(y)=12y[fX(y)+fX(−y)]1(y)=1yfX(y)1(y)=12πy e−12y 1(y).f_Y(y)=\frac{1}{2\sqrt y}\big[f_X(\sqrt y)+f_X(-\sqrt y)\big]\mathbb{1}(y)=\frac1{\sqrt y}f_X(\sqrt y)\mathbb{1}(y)=\frac1{\sqrt{2\pi y}}\,e^{-\frac12y}\,\mathbb{1}(y).

This is a very important density in probability and statistics, called χ2(1)\chi^2(1) (chi-square with 1 degree of freedom): if X∼N(0,1)X\sim N(0,1) then X2∼χ2(1)X^2\sim\chi^2(1).

Example 4: other common functions

Simple signal transformations very common in electronics (graphs on the page): half wave rectifier x1(x)x\mathbb{1}(x), full wave rectifier ∣x∣|x|, limiter (a linear part saturating at both ends), rectifier and limiter, full wave rectifier and limiter, etc.

Interactions between g(x)g(x) and fX(x)f_X(x)

Typical behaviours of Y=g(X)Y=g(X) depend on the interaction between the properties of gg and of fXf_X.

  1. gg is constant over an interval. If g(x)=y∗g(x)=y^* for x∈[a,b]x\in[a,b] and P(X∈[a,b])>0P(X\in[a,b])>0 then P(Y=y∗)=P(X∈[a,b])>0P(Y=y^*)=P(X\in[a,b])>0, and YY cannot be an absolutely continuous random variable.
  2. gg has a jump at x∗x^*. The figure shows a jump from yℓy_\ell to yhy_h at x∗x^*; then P(Y∈(yℓ,yh))=P(X=x∗)={0X absolutely continuous>0X discrete and x∗∈X.P(Y\in(y_\ell,y_h))=P(X=x^*)=\begin{cases}0 & X\text{ absolutely continuous}\\ >0 & X\text{ discrete and }x^*\in\mathcal{X}.\end{cases}

Exercise (informal solutions)

g(x)={1x≤01−xx>0g(x)=\begin{cases}1 & x\le0\\ 1-x & x>0\end{cases}

  1. X∼N(0,1)X\sim N(0,1). The probability mass in (−∞,0)(-\infty,0), that is 12\frac12, is all mapped in Y=1Y=1. The mass in (0,∞)(0,\infty) is mapped linearly into (−∞,1)(-\infty,1). So fY(y)=12πe−12(y−1)21(1−y)+12δ(y−1),f_Y(y)=\frac{1}{\sqrt{2\pi}}e^{-\frac12(y-1)^2}\mathbb{1}(1-y)+\frac12\delta(y-1), or as a mixture fY(y)=12[22πe−12(y−1)21(1−y)]+12δ(y−1)f_Y(y)=\frac12\left[\frac{2}{\sqrt{2\pi}}e^{-\frac12(y-1)^2}\mathbb{1}(1-y)\right]+\frac12\delta(y-1) (a Gaussian-shaped part on y<1y<1 plus an atom of weight 12\frac12 at y=1y=1).
  2. X∼Exp(λ)X\sim\mathrm{Exp}(\lambda). The probability mass in (−∞,0)(-\infty,0) is 00, therefore P(Y=1)=0P(Y=1)=0; the mass in (0,∞)(0,\infty) is mapped linearly into (−∞,1)(-\infty,1): fY(y)=λe−λ(1−y)1(1−y).f_Y(y)=\lambda e^{-\lambda(1-y)}\mathbb{1}(1-y).

Alternative method: piecewise invertible gg

If Y=g(X)Y=g(X) where gg is piecewise invertible, i.e. a function with a finite number of points xx where g′(x)=0g'(x)=0 (it is monotonic, increasing or decreasing, between consecutive such points, hence invertible on each of those intervals), the density fY(y)f_Y(y) can be found with a different approach.

Lemma. If g∈C1(R)g\in C^1(\mathbb{R}) (differentiable with continuous derivative) and gg has at most a finite number of points xx where g′(x)=0g'(x)=0, then gg is piecewise invertible.

Proof. Let x1<x2<⋯<xNx_1<x_2<\dots<x_N be the points where g′(xi)=0g'(x_i)=0. The sign of g′(x)g'(x) is constant over the intervals (−∞,x1),(x1,x2),…,(xN−1,xN),(xN,+∞)(-\infty,x_1),(x_1,x_2),\dots,(x_{N-1},x_N),(x_N,+\infty), therefore gg is monotonic over each interval, thus invertible. □\square

Theorem. Let g∈C1(R)g\in C^1(\mathbb{R}) with a finite number of zeros of g′(x)g'(x), and let XX be absolutely continuous with density fX(x)f_X(x). Then Y=g(X)Y=g(X) is absolutely continuous with density

 fY(y)=∑a∈g−1(y)fX(a)∣g′(a)∣ \boxed{\,f_Y(y)=\sum_{a\in g^{-1}(y)}\frac{f_X(a)}{|g'(a)|}\,}

Proof (case g′(a)>0g'(a)>0). Take a=g−1(y)a=g^{-1}(y) and a small increment hh of yy. The tangent at aa has slope tan⁡β=hh′=g′(a)\tan\beta=\frac{h}{h'}=g'(a), where h′h' is the corresponding increment of xx, so h′=1g′(a)hh'=\frac{1}{g'(a)}h. Then

fY(y) h=P(Y∈(y,y+h))=P(X∈(a,a+h′))=fX(a)h′=fX(a)g′(a)h,f_Y(y)\,h=P(Y\in(y,y+h))=P(X\in(a,a+h'))=f_X(a)h'=\frac{f_X(a)}{g'(a)}h,

hence fY(y)=fX(a)g′(a)f_Y(y)=\dfrac{f_X(a)}{g'(a)}.

Case g′(a)<0g'(a)<0. Now tan⁡β=g′(a)=hh′<0\tan\beta=g'(a)=\frac{h}{h'}<0 so the interval of xx corresponding to (y,y+h)(y,y+h) lies to the left of aa (figure) and has positive length h′=1∣g′(a)∣hh'=\frac{1}{|g'(a)|}h (a length must be positive). Reasoning as before, whatever the sign of g′(a)≠0g'(a)\neq0,

fY(y)=fX(a)∣g′(a)∣,a=g−1(y).f_Y(y)=\frac{f_X(a)}{|g'(a)|},\qquad a=g^{-1}(y).

In general g−1(y)g^{-1}(y) contains several points a1,a2,a3,…a_1,a_2,a_3,\dots (figure: a horizontal strip (y,y+h)(y,y+h) cuts the graph above several intervals of xx); the contributions of all the small xx-intervals add up:

fY(y)=∑ai∈g−1(y)1∣g′(ai)∣fX(ai).□f_Y(y)=\sum_{a_i\in g^{-1}(y)}\frac{1}{|g'(a_i)|}f_X(a_i).\qquad\square

Example: g(x)=x2g(x)=x^2. g′(x)=2x=0g'(x)=2x=0 only at x=0x=0. For y>0y>0, g−1(y)={−y,y}g^{-1}(y)=\{-\sqrt y,\sqrt y\}, with g′(−y)=−2yg'(-\sqrt y)=-2\sqrt y and g′(y)=2yg'(\sqrt y)=2\sqrt y. Hence

fY(y)=fX(−y)∣−2y∣+fX(y)∣2y∣=12y(fX(−y)+fX(y)),f_Y(y)=\frac{f_X(-\sqrt y)}{|-2\sqrt y|}+\frac{f_X(\sqrt y)}{|2\sqrt y|}=\frac{1}{2\sqrt y}\big(f_X(-\sqrt y)+f_X(\sqrt y)\big),

the same result as with the DF method. Now one can plug in the density fX(x)f_X(x) to find fY(y)f_Y(y) in any special case of interest.

Remark on the two methods. The DF method handles every case (atoms, mixed results, constant stretches of gg); the density formula needs XX absolutely continuous and gg piecewise invertible and then gives an absolutely continuous YY directly. See also Markov and Chebyshev InequalitiesFor a nonnegative random variable P(X >= a) is at most E(X)/a (Markov), and for any random variable with finite mean and variance P(|X - E(X)| >= eps) is at most var(X)/eps^2 (Chebyshev); both bounds are loose but universal, valid whatever the distribution.Markov and Chebyshev Inequalities → for what can be said about YY when only its mean and variance are known.

Versione ripasso

Problem. Y=g(X)Y=g(X); find FYF_Y or fYf_Y. Discrete case: pY(yℓ)=∑g(xk)=yℓpX(xk)p_Y(y_\ell)=\sum_{g(x_k)=y_\ell}p_X(x_k).

DF method (always works). FY(y)=P(g(X)≤y)=P(X∈g−1((−∞,y]))F_Y(y)=P(g(X)\le y)=P(X\in g^{-1}((-\infty,y])), then fY=FY′f_Y=F_Y' (plus atoms where FYF_Y jumps).

Affine: Y=aX+bY=aX+b: fY(y)=1∣a∣fX ⁣(y−ba)f_Y(y)=\frac1{|a|}f_X\!\left(\frac{y-b}{a}\right).

  • X∼N(μ,σ2)⇒Y∼N(aμ+b,a2σ2)X\sim N(\mu,\sigma^2)\Rightarrow Y\sim N(a\mu+b,a^2\sigma^2).
  • X∼U([c,d])⇒Y∼U([ac+b,ad+b])X\sim\mathcal{U}([c,d])\Rightarrow Y\sim\mathcal{U}([ac+b,ad+b]) (a>0a>0), U([ad+b,ac+b])\mathcal{U}([ad+b,ac+b]) (a<0a<0).
  • X∼Exp(λ)X\sim\mathrm{Exp}(\lambda), a>0a>0, b=0b=0: Y∼Exp(λ/a)Y\sim\mathrm{Exp}(\lambda/a); for b≠0b\ne0 or a<0a<0, YY is not exponential (wrong support).

Rectifier Y=X1(X)Y=X\mathbb{1}(X): FY(y)=FX(y)1(y)F_Y(y)=F_X(y)\mathbb{1}(y). For X∼N(0,1)X\sim N(0,1): fY=fX(y)1(y)+12δ(y)f_Y=f_X(y)\mathbb{1}(y)+\frac12\delta(y) (mixed, P(Y=0)=12P(Y=0)=\frac12). Exp\mathrm{Exp} is unchanged. U([−1,3])→14δ(y)+34U([0,3])\mathcal{U}([-1,3])\to\frac14\delta(y)+\frac34\mathcal{U}([0,3]).

Square Y=X2Y=X^2: FY=(FX(y)−FX(−y))1(y)F_Y=(F_X(\sqrt y)-F_X(-\sqrt y))\mathbb{1}(y), fY(y)=12y[fX(y)+fX(−y)]1(y)f_Y(y)=\frac{1}{2\sqrt y}[f_X(\sqrt y)+f_X(-\sqrt y)]\mathbb{1}(y). X∼N(0,1)⇒X2∼χ2(1)X\sim N(0,1)\Rightarrow X^2\sim\chi^2(1) with density 12πye−y/21(y)\frac{1}{\sqrt{2\pi y}}e^{-y/2}\mathbb{1}(y).

Interactions: gg constant on an interval of positive probability ⇒\Rightarrow atom, YY not absolutely continuous. A jump of gg at x∗x^* gives P(Y∈gap)=P(X=x∗)P(Y\in\text{gap})=P(X=x^*): 00 for absolutely continuous XX.

Density formula. g∈C1g\in C^1, finitely many zeros of g′g' (piecewise invertible), XX absolutely continuous: fY(y)=∑a∈g−1(y)fX(a)∣g′(a)∣.f_Y(y)=\sum_{a\in g^{-1}(y)}\frac{f_X(a)}{|g'(a)|}. Idea: fY(y)h=P(X∈(a,a+h′))=fX(a)h′f_Y(y)h=P(X\in(a,a+h'))=f_X(a)h' with h′=h/∣g′(a)∣h'=h/|g'(a)|.

Typical mistakes. Forgetting the absolute value ∣a∣|a| or ∣g′(a)∣|g'(a)|; forgetting an atom when gg is constant on a set of positive probability; using the density formula when g′g' vanishes on an interval; forgetting that 1(y)\mathbb{1}(y) (support) must be kept.

Teoria collegata