Jump to content

Probability/Transformation of Probability Densities

From Wikibooks, open books for an open world
A Wikibook showing how to transform the probability density of a continuous random variable in both the one-dimensional and multidimensional case. In other words, it shows how to calculate the distribution of a function of continuous random variables.

This Wikibook shows how to transform the probability density of a continuous random variable in both the one-dimensional and multidimensional case. In other words, it shows how to calculate the distribution of a function of continuous random variables. The first section formulates the general problem and provides its solution. However, this general solution is often quite hard to evaluate and simplifications are possible in special cases, e.g., if the random vector is one-dimensional or if the components of the random vector are independent. Formulas for these special cases are derived in the subsequent sections. This Wikibook also aims to provide an overview of different equations used in this field and show their connection.

General Problem and Solution (n-to-m mapping)

[edit | edit source]

Let X→=(X1,…,Xn) be a random vector with the probability density function, pdf, ϱX→(x1,…,xn) and let f:ℝn→ℝm be a (Borel-measurable) function. We are looking for the probability density function ϱY→ of Y→:=f→(X→).

First, we need to remember the definition of the cumulative distribution function, cdf, FY→(y→) of a random vector: It measures the probability that each component of Y takes a value smaller than the corresponding component of y. We will use a short-hand notation and say that two vectors are "less or equal" (≤) if all of their components are.

FY→(y→)=P(Y→≤y→)=P(f→(X→)≤y→)

 

 

 

 

(1)

The wanted density ϱY→(y→) is then obtained by differentiating FY→(y→):

ϱY→(y→)=∂∂y1⋯∂∂ymFY→(y→)

 

 

 

 

(2)

Thus, the general solution can be expressed as the m‘th derivative of an n-dimensional integral:

ℝn → ℝm mapping

ϱY→(y→)=∂∂y1⋯∂∂ym∫{x→∈ℝn∣f→(x→)≤y→}ϱX→(x→)dnx

 

 

 

 

(3)

The following sections will provide simplifications in special cases.

Function of a Random Variable (n=1, m=1)

[edit | edit source]

If n=1 and m=1, X is a continuously distributed random variable with the density ϱX and f:ℝ→ℝ is a Borel-measurable function. Then also Y := f(X) is continuously distributed and we are looking for the density ϱY(y).

In the following, f should always be at least differentiable.

Let us first note that there may be values that are never reached by f, e.g. y<0 if f(x) = x2. For all those y, necessarily ϱY(y)=0.

ϱY(y)={0,if y∉f(ℝ)?,if y∈f(ℝ)

Following equations 1 and 2, we obtain

ϱY(y)=ddyFY(y)=ddyP(Y≤y)=ddyP(f(X)≤y)

 

 

 

 

(4)

We will now rearrange this expression in various ways.

Derivation using cumulated distribution function Fx

[edit | edit source]

At first, we limit ourselves to f whose derivative is never 0 (thus, f is a diffeomorphism). Then, the inverse map f−1 exists and f is either monotonically increasing or monotonically decreasing.

If f is monotonically increasing, then x≤f−1(y)⇔f(x)≤f(f−1(y))=y and f′>0. Therefore:

ϱY(y)=ddyP(f(X)≤y)=ddyP(X≤f−1(y))=ddyFX(f−1(y))=ϱX(f−1(y))df−1(y)dy

If f is monotonically decreasing, then x≤f−1(y)⇔f(x)≥f(f−1(y))=y and f′<0. Therefore:

ϱY(y)=ddyP(f(X)≤y)=ddyP(X≥f−1(y))=ddy(1−FX(f−1(y)))=−ϱX(f−1(y))df−1(y)dy

This can be summarized as:

ϱY(y)={0,if y∉f(ℝ)ϱX(f−1(y))⋅|df−1(y)dy|,if y∈f(ℝ)

 

 

 

 

(5)

If now the derivative f′(xi)=0 does vanish at some positions xi, i=1,…,N, then we split the definition space of f using those position into N+1 disjoint intervals Ij. Equation 5 holds for the functions fIj limited in their definition space to those intervals Ij. We have

P(f(X)≤y)=∑j=1N+1P(fIj(X)≤y)ϱY(y)=ddyP(f(X)≤y)=∑j=1N+1ϱX(fIj−1(y))⋅|dfIj−1(y)dy|

 

 

 

 

(5a)

With the convention that the sum over 0 addends is 0 and using the inverse function theorem, it is possible to write this in a more compact form (read as: sum over all x, where f(x)=y):

ℝ → ℝ mapping

ϱY(y)=∑x,f(x)=yϱX(x)|f′(x)|

 

 

 

 

(6)

Derivation using Integral Substitution

[edit | edit source]

In this section we consider a different derivation.

The probability in 4 is the integral over the probability density. Again in the case of monotonically increasing f, we have:

∫−∞yϱY(u)du=P(Y≤y)=P(f(X)≤y)=P(X≤f−1(y))=∫−∞f−1(y)ϱX(x)dx

Now we substitute u = f(x) in the integral on the right hand site, i.e. x=f−1(u) and dudx=f′(x). The integral limits are then from -∞ to y and in the rule “dx=dxdudu” we have dxdu=df−1(u)du due to the inverse function theorem. Consequentially:

∫−∞yϱY(u)du=∫−∞yϱX(f−1(u))df−1(u)dudu

Taking the derivative of both sides with respect to y, we get:

ϱY(y)=ϱX(f−1(y))df−1(y)dy

Following the same argument as in the last section, we can again derive equation 6.

This rule often misleads physics books to present the following viewpoint, which might be easier to remember, but is not mathematically sound: If you multiply the probability density ϱX(x) with the “infinitesimal length” dx, then you will get the probability ϱX(x)dx for X to lie in the interval [x, x+dx]. Changing to new coordinates y, you will get by substitution:

ϱX(x)dx=ϱX(x(y))dxdy⏟ϱY(y)dy

Derivation using the Delta Distribution

[edit | edit source]

In this section we consider another different derivation, often used in physics.

We start again with equation 4 and write this as an integral:

ϱY(y)=ddyP(f(X)≤y)=ddy∫{x∈ℝ∣f(x)≤y}ϱX(x)dx=ddy∫ℝΘ(y−f(x))ϱX(x)dx=∫ℝddyΘ(y−f(x))ϱX(x)dx=∫ℝδ(y−f(x))ϱX(x)dx

The intuitive interpretation of the last expression is: one integrates over all possible x-values and uses the delta “function” to pick all positions where y = f(x). This formula is often found in physics books, possibly written as expectation value, ⟨…⟩:

ℝ → ℝ mapping (using Dirac Delta Distribution)

ϱY(y)=∫ℝδ(y−f(x))ϱX(x)dx=⟨δ(y−f(x))⟩.

 

 

 

 

(7)

We can see this formula is equivalent to equation 6 using the following identity

∫ℝδ(h(x))g(x)dx=∑x0,h(x0)=0g(x0)|h′(x0)|

Examples

[edit | edit source]
  • Let us consider the following specific example: let ϱX(x)=exp⁡[−0.5x2]2π and f(x)=x2. We choose to use equation 6 (equations 5 and 7 lead to the same result). We calculate the derivative f′(x)=2x and find all x for which f(x)=y, which are −y and +y if y>0 and none otherwise. For y>0 we have:
ϱY(y)=∑x,f(x)=yϱX(x)|f′(x)|=ϱX(−y)|f′(−y)|+ϱX(+y)|f′(+y)|=exp⁡[−0.5y]2π2y+exp⁡[−0.5y]2π2y=exp⁡[−0.5y]2πy
Since f never reaches negative values, the sum remains 0 for y<0 and we finally obtain:
ϱY(y)={0,if y≤0exp⁡[−0.5y]2πy,if y>0
This example is illustrated in the following graphics:
Random numbers are generated according to the standard normal distribution X∼𝒩(0,1). They are shown on the x-axis of figure (a). Many of them are around 0. Each of those numbers is mapped according to y=x2, which is shown with grey arrows for two example points. For many generated realisations of X, a histogram on the y-axis will converge towards the wanted probability density function ϱY shown in (c). In order to analytically derive this function, we start by observing that in order for Y to be between any v and v+Δv, X must have been between either −v+Δv and −v, or, between v and v+Δv. Those intervals are marked in figures (b) and (c). Because the probability is equal to the area under the probability density function, we can determine ϱY from the condition that the grey shaded area in (c) must be equal to the sum of the areas in (b). The areas are calculated using integrals and it is useful to take the limit Δv→0 in order to get the formula noted in (c).
ϱX(x)≡{1,if 0≤x≤10,else.
If we want to obtain random numbers according to a distribution with the pdf ϱZ, we choose f as the inverse function of the cdf of Z, i.e. Y=f(X)=FZ−1(X). We can now show that Y will have the same distribution as the wanted Z, ϱY=ϱZ by using equation 5 and the fact that f−1=FZ:
ϱY(y)={0,if y∉FZ−1(ℝ)ϱX(FZ(y))⋅|dFZ(y)dy|,if y∈FZ−1(ℝ)=1⋅|dFZ(y)dy|=ϱZ(y).
An example is illustrated in the following plot:
Random numbers yi are generated from a uniform distribution between 0 and 1, i.e. Y∼U(0,1). They are sketched as colored points on the y-axis. Each of the points is mapped according to x=F−1(y), which is shown with gray arrows for two example points. In this example, we have used an exponential distribution. Hence, for x≥0, the probability density is ϱX(x)=λe−λx and the cumulated distribution function is F(x)=1−e−λx. Therefore, x=F−1(y)=−ln⁡(1−y)λ. We can see that using this method, many points end up close to 0 and only few points end up having high x-values - just as it is expected for an exponential distribution.

Mapping of a Random Vector to a Random Variable (n>1, m=1)

[edit | edit source]

We will now investigate the case when a random vector X with known density ϱX→ is mapped to (scalar) random variable Y and calculate the new density ϱY(y).

According to 3, we find:

ϱY(y)=ddy∫{x→∈ℝn∣f(x→)≤y}ϱX→(x→)dnx

 

 

 

 

(8)

The direct evaluation of this equation is sometimes the easiest way, e.g., if there is a known formula for the area or volume presented by the integral. Otherwise one needs to solve a parameter-depended multiple integral.

If the components of the random vector X→ are independent, then the probability density factorizes:

ϱX→(x1,…,xn)=ϱX1(x1)⋅…⋅ϱXn(xn)

In this case the delta function may provide a fast tool for the evaluation. Replacing the integration bound with a step function inside the integral, H(y−f(x→)) and using the fact that the derivative of a step function is the delta:

ϱY(y)=∫ℝnϱX→(x1,…,xn)δ(y−f(x→))dx1…dxn=∫ℝϱXn(xn)⋯∫ℝϱX1(x1)δ(y−f(x→))dx1…dxn

 

 

 

 

(9)

If one wants to avoid calculations with the delta function, it is of course possible to evaluate the innermost integral ∫dx1, provided that the components are independent:

ϱY(y)=∫ℝn−1∑x1,f(x→)=yϱX→(x→)|∂f(x→)∂x1|dx2…dxn

Examples

[edit | edit source]
  • Let Y=f(X→)=X1+X2 with the independent, continuous random variable X1 and X2. According to equation 9, we have:
ϱY(y)=∫ℝϱX2(x2)∫ℝϱX1(x1)δ(y−x2−x1)dx1dx2=∫ℝϱX2(x2)ϱX1(y−x2)dx2
If one uses the sum formula instead, the sum runs over all x1, for which f(x→)=x1+x2=y, i.e. where x1 = y - x2.
The derivative is ∂(x1+x2)∂x1=1, so that one also obtains the equation ϱY(y)=∫ℝϱX2(x2)ϱX1(y−x2)dx2.
Integrating over x2 first leads to the following, equivalent expression:
ϱY(y)=∫ℝϱX1(x1)ϱX2(y−x1)dx1
  • If Y=X1−X2 with independent X1 and X2, then ϱY(y)=∫ℝϱX1(x1)ϱX2(x1−y)dx1.
  • If Y=X1⋅X2 with independent X1 and X2, then ϱY(y)=∫ℝϱX1(x1)ϱX2(yx1)1|x1|dx1.
  • If Y=X1X2 with independent X1 and X2, then ϱY(y)=∫ℝϱX1(x2⋅y)ϱX2(x2)|x2|dx2.
  • Given the independent random variables X1 and X2 with the density
ϱX→(x1,x2)={1/π,if x12+x22≤10,otherwise
Let Y:=X12+X22. According to equation 8, we need to solve:
ϱY(y)=ddy∫{x→∈ℝn∣x12+x22≤y}1πdx1dx2
The last integral is over a circle with radius y ≤ 1, hence with the area πy2. This simplifies the calculation:
0≤y≤1⇒ϱY(y)=1πddy(πy2)=2πyπ=2y.
If y<0, we integrate over an empty set, which gives 0. If y>1, ϱX→=0. Therefore, the final result is:
ϱY(y)={2y,if 0≤y≤10,otherwise
This example is illustrated in the following graphics:
Figure (a) shows a sketch of random sample points from a uniform distribution in a circle of radius 1, subdivided into rings. In figure (b), we count how many of those points fell into each of the rings with the same width Δv. Since the area of the rings increases linearly with the radius, one can expect more points for larger radii. For Δv → 0, the normalized histogram in (b) will converge to the wanted probability density function ρY. In order to calculate ρY analytically, we first derive the cumulated distribution function FY, plotted in figure (d). FY(y) is the probability to find a point inside the circle of radius v (shown in grey in figure (c)). For v between 0 and 1, we find FY(v)=AvAtot=πv2π12=v2. The slope of FY is the wanted probability density function ρY(y)=dFY(y)dy=2y, in agreement with figure (b).

Invertible Transformation of a Random Vector (n=m)

[edit | edit source]

Let X→=(X1,…,Xn) be a a random vector with the density ϱX→(x1,…,xn) and let f:ℝn→ℝn be a diffeomorphism. For the density ϱY→ of Y→:=f→(X→) we have:

∫GϱX→(x→)dnx=∫f(G)ϱX→(f−1(y→))|∂(x1,…,xn)∂(y1,…,yn)|dny

and therefore

ℝn → ℝn mapping

ϱY→(y→)=ϱX→(f−1(y→))|∂(x1,…,xn)∂(y1,…,yn)|,

 

 

 

 

(10)

where Φf−1=|∂(x1,…,xn)∂(y1,…,yn)| is the Jacobian determinant of f−1. Note that Φf−1=(Φf)−1. In the one-dimensional case (n=1), equation 10 coincides with equation 5.

Examples

[edit | edit source]
  • Given the random vector X→ and the invertible matrix A and a vector b→, let Y→=AX→T+b→. Then ϱY→(y→)=ϱX→(A−1(y→−b→))|det⁡A−1|. Also, det⁡A−1=1/det⁡A.
  • Given the independent random variables X1 and X2, we introduce polar coordinates Y1=X12+X22 and Y2=atan2⁡(X2,X1). The inverse map is X1=Y1cos⁡Y2 and X2=Y1sin⁡Y2. Due to Jacobian determinant y1, the wanted density is ϱY→(y1,y2)=y1ϱX→(y1cos⁡y2,y1sin⁡y2).

Possible simplifications for multidimensional mappings (n>1, m>1)

[edit | edit source]

Even if none of the above special cases apply, simplifications can still be possible. Some of them are listed below:

Independent Target-Components

[edit | edit source]

If one knows beforehand that the components of Yi will be independent, i.e.

ϱY→(y1,…,yn)=ϱY1(y1)⋅…⋅ϱYn(yn),

then the density ϱYi of each component Yi=fi(X→) can be calculated like in the above section Mapping of a Random Vector to a Random Variable.

Example

[edit | edit source]
Given the random vector X→=(X1,X2,X3,X4) with independent components.
Let f:ℝ4→ℝ2, Y→=f→(X→):=(X1+X2,X3+X4).
Obviously, the components Y1 = X1 + X2 and Y2 = X3 + X4 are independent and therefore:
ϱY1(y1)=∫ℝϱX1(y1−x2)ϱX2(x2)dx2 and
ϱY2(y2)=∫ℝϱX3(y2−x4)ϱX4(x4)dx4.
Note that the components of Y→ can be independent even if the components of X→ are not.

Split Integral Region

[edit | edit source]

Sometimes it is useful to split the integral region in equation 3 into parts that can be evaluate separately. This can be made explicit by rewriting 3 with delta functions:

ϱY→(y→)=∫ℝnϱX→(x→)δ(y1−f(x→)1)⋅…⋅δ(ym−f(x→)m)dnx

and then use the identity δ(x−x0)=∫ℝδ(x−ξ)δ(ξ−x0)dξ.

Example

[edit | edit source]
To illustrate the idea, we use a simple ℝn → ℝ example: Let Y = X12 + X22 + X3 with
ϱX→(x1,x2,x3)={e−x3π,if x12+x22≤1∧x3≥00,else
The parametrisation of the region where at the same time x12 + x22 + x3 ≤ y and x12 + x22 ≤ 1 and x3 ≥ 0 may not be obvious, so we use the two above formulas:
ϱY(y)=∫ℝ3ϱX→(x→)δ(y−f(x→))dx1dx2dx3=∫0∞∬x12+x22≤1e−x3πδ(y−x12−x22−x3)dx1dx2dx3=∫0∞∬x12+x22≤1e−x3π∫ℝδ(ξ−x12−x22)δ(y−x3−ξ)dξdx1dx2dx3=∫0∞∫ℝ[∬x12+x22≤1e−x3πδ(ξ−x12−x22)dx1dx2]δ(y−x3−ξ)dξdx3
Now, we have split the integral such that the expression in brackets can be evaluated separately, because the region depends on x1 and x2 only and may contain x3 only as parameter.
∬x12+x22≤1e−x3πδ(ξ−x12−x22)dx1dx2={e−x3,if 0≤ξ≤10,else
Therefore:
ϱY(y)=∫0∞∫01e−x3δ(y−x3−ξ)dξdx3=∫max⁡(0,y−1)ye−x3dx3={e1−y−e−y,if y>11−e−y,if 0≤y≤10,if y≤0

Helper Coordinates

[edit | edit source]

If f is injective, then it can be easier to introduce additional helper coordinates Ym+1 to Yn, then do the ℝn→ℝn transformation from section Invertible Transformation of a Random Vector and finally integrate out all helper coordinates of the so-obtained density.

Example

[edit | edit source]
Given the random vector X→=(X1,X2,X3) with the density ϱX→(x→) and the following mapping:
(Y1Y2)=(123456)(X1X2X3)
Now we introduce the helper coordinate Y3 = X3, which results in the transformation matrix
A=(123456001)
with the corresponding pdf ϱX→(A−1y→)|det⁡A−1|. Thus, we finally obtain
ϱY→(y1,y2)=∫ℝϱX→(A−1(y1y2y3))|det⁡A−1|dy3.
Remark: If the joint pdf ϱY→(y1,y2), i.e. the conditional distribution, is not of interest and one is only interested in the marginal distribution with ϱY1(y1)=∫ℝϱY→(y1,y2)dy2, then it is possible to calculate the density as described in section Mapping of a Random Vector to a Random Variable for the mapping Y1 = 1 X1 + 2 X2 + 3 X3 (and likewise for Y2 = 4 X1 + 5 X2 + 6 X3).

Real-World Applications

[edit | edit source]

In order to show some possible applications, we present the following questions, which can be answered using the techniques outlines in this Wikibook. In principle, the answers could also be approximated using a numerical random number simulation: generate several realizations of X→, calculate Y→=f(X→) and make a histogram of the results. However, many such random numbers are needed for reasonable results, especially for higher-dimensional random vectors. Gladly, we can always calculate the resulting distribution analytically using the above formulas.

Statistical Physics

[edit | edit source]
  • Suppose atoms in a laser are moving with normally distributed velocities Vx, ϱVx(vx)=exp⁡[−vx2/2σ2]2πσ2, σ2 = kBT/m. Due to the Doppler effect, light emitted with frequency f0 by an atom moving with vx will be detected as f ≈ f0 ( 1 + vx / c ). Hence, f is a function of Vx. What does the detected spectrum, ϱf, look like? (Answer: Gaussian around f0.)
  • Suppose the velocity components of an ideal gas (Vx, Vy, Vz) are identically, independently normally distributed as in the last example. What is the probability density ϱV of V=Vx2+Vy2+Vz2? (The answer is known as Maxwell-Boltzmann distribution.)

Quantifying Uncertainty of Derived Properties

[edit | edit source]
  • Suppose we do not know the exact value of X and Y, but we can assign a probability distribution to each of them. What is the distrubution of the derived property Z = X2 / Y and what is the mean value and standard deviation of Z? (To tackle such problems, linearisation around the mean values are sometimes used and both X and Y are assumed to be normally distributed. However, we are not limited to such restrictions.)
  • Suppose we consider the value of one gram gold, silver and platinum in one year from now as independent random variables G, S and P, respectively. Box A contains 1 gram gold, 2 gram silver and 3 gram platinum. Box B contains 4, 5 and 6 gram, respectively. Thus, (AB)=(123456)(GSP). What is the value of the contents in box A (or box B) in one year from now? (The answer is given in an example above.) Note that A and B are correlated.

Note that the above examples assume the distribution of X→ to be known. If it is unknown, or if the calculation is based on only a few data points, methods from mathematical statistics are a better choice to quantify uncertainty.

Generation of Correlated Random Numbers

[edit | edit source]

Correlated random numbers can be obtained by first generating a vector of uncorrelated random numbers and then applying a function on them.

  • In order to obtain random numbers with covariance matrix CY, we can use the following know procedure: Calculate the Cholesky decomposition CY = A AT. Generate a vector x→ of uncorrelated random numbers with all var(Xi) = 1. Apply the matrix A: Y→=AX→. This will result in correlated random variables with covariance matrix CY = A AT.
  • With the formulas outlined in this Wikibook, we can additionally study the shape of the resulting distribution and the effect of non-linear transformations. Consider, e.g., that X is uniform distributed in [0, 2π], Y1 = sin(X) and Y2 = cos(X). In this case, a 2D plot of random numbers from (Y1, Y2) will show a uniform distribution on a circle. Although Y1 and Y2 are stochastically dependent, they are uncorrelated. It is therefore important to know the resulting distribution, because ϱY→(y1,y1) has more information than the covariance matrix CY.