Transformations and joint distributions proofs — step by step with the food delivery order, the inverse of F, Cauchy–Schwarz and the Jacobian (and the density that came out negative)
In a practice exam in class I did a change of variables with two variables right until the last line, and on that line I wrote a negative density. The Jacobian came out as , I multiplied it in as it was and wrote down, very pleased with myself, that the joint density was , negative for every . The lecturer didn’t write any comment in the margin: he just circled the minus sign and drew a question mark the size of the page. Two little bars were missing, those of the absolute value, and so was a glance at whether the result made sense.
This article is the extension of the transformations and joint distributions theory: there you have the results and how to use them; here, where they come from. These are the eight proofs that come up in the EC2 with this topic, each one with what we want to prove, where we start, each step with the property that justifies it, where people usually get stuck and how to check it with R. We keep the food delivery order: the kitchen and the delivery , independent and , and the arrival minute .
Table of Contents
Before we start: the rules we will use
| Rule | What it says | Where it is used |
|---|---|---|
| Chain rule | Differentiating a composite distribution function | |
| Derivative of the inverse | with | The sign of is that of |
| Continuous: points weigh nothing | , so | Going from to |
| Marginal | Going from a double integral to a single one | |
| Fubini | A double integral of a product over a rectangle is the product of integrals | Independence and expectations |
| mgf | It determines the distribution; that of a sum of independent variables is the product | Identifying the sum |
| Linearity | In almost all of them |
Proof 1: the change of variable theorem
What we want to prove
If is continuous with density and , with differentiable and strictly monotonic on the support of , then
Why it matters. It is the tool of the whole topic: every time you are asked for the density of a function of a variable (the rider’s time from their speed, the kitchen in seconds), this is the formula. And its idea, translating into an event about , comes back in proof 2.
Where we start
From the definition of distribution function, , and from the density being its derivative. The idea is to write the event as an event about , whose distribution we know. There are two cases, depending on whether goes up or down.
Case 1: g increasing
If is increasing, applying (also increasing) to both sides keeps the inequality:
Differentiating with the chain rule:
And since is increasing, its derivative is positive: it equals its absolute value.
Where that derivative comes from: the outer function is , whose derivative is , and the inner one is . It is the chain rule from the table with and . In case 2 you differentiate the same way, with the minus sign of in front.
Case 2: g decreasing
If is decreasing, applying flips the inequality (that is what you see in the drawing, on the right):
The last step uses that is continuous: , because the point weighs nothing. Differentiating:
Now is decreasing and its derivative is negative, so .
Putting the two cases together
In both you get times a positive factor which is the absolute value of the derivative of the inverse. That is the theorem. The support of is the image under of the support of .
Where people get stuck is case 2: either they don’t flip the inequality, or they flip it and then put the absolute value on again, counting the sign twice. If you do the case with step by step, the sign comes out on its own.
Check it with R
The rider from the theory: and , decreasing. The theorem gives on . We compare a probability computed both ways: integrating the new density and translating the event to the speed.
fR <- function(r) 22.5 / r^2 integrate(fR, 9, 11)$value # P(R <= 11) with the theorem's density 1 - punif(180 / 11, 12, 20) # P(V >= 180/11): the same event
Output:
[1] 0.4545455 [1] 0.4545455
Both give the same, 0.45 (exactly ). In the second line you see case 2 at work: , with the inequality flipped.
Check you’ve got it: where does for the rider come from, and why on ?
The inverse of is , with derivative : negative, because is decreasing (case 2), and the absolute value turns it into . Since on , . The support is the image of ‘s: and , with the endpoints swapped because goes down.
Proof 2: the square of a standard normal is a chi-squared
What we want to prove
If , then has density
which is the , that is, a .
Why it matters. It shows what to do when is not monotonic and proof 1 does not apply: go back to and look at how many values of lead to each . And the comes back in the sampling distributions topic, with the sample variance.
Where we start
is not monotonic on the line (it goes down to 0 and then up), so the theorem in proof 1 doesn’t apply. We go back to the distribution function.
Step 1: the support
always, so for , . We work with .
Step 2: the event, in terms of Z
is the same as , that is, . It is the central interval in the drawing:
Step 3: differentiate
With the chain rule on each term, and knowing that and :
Why the minus turns into a plus: the derivative of is , and in the second term, , the inner derivative is . Minus times minus is plus: the two branches add up.
Step 4: use the symmetry and substitute
The normal density is even, , so the bracket is :
Step 5: recognise it
A has density . With and :
The same. The is called .
Using only the positive root, , and writing . It is half the density: it integrates to 0.5. Each value of comes from two values of .
Check it with R
fW <- function(w) exp(-w / 2) / sqrt(2 * pi * w) integrate(fW, 0, Inf) # a density: integrates to 1 c(fW(1.5), dchisq(1.5, df = 1), dgamma(1.5, 0.5, 0.5))
Output:
1 with absolute error < 6.4e-05 [1] 0.1538663 0.1538663 0.1538663
It integrates to 1 and, at , the three versions (ours, dchisq and dgamma) give the same height, 0.1539.
Check you’ve got it: without integrating anything, what is ?
0.68. By step 2, is the same as , so : landing less than one standard deviation from the mean. In R, pchisq(1, 1) gives the same.
Proof 3: the inverse of F (simulating any distribution)
What we want to prove
Let be continuous with distribution function , strictly increasing on its support (so exists). Then:
- .
- If , the variable has distribution function .
Why it matters. Part 2 is the recipe for simulating any continuous distribution with nothing but uniform numbers: if you can solve for , you can simulate . It is what you will use when a distribution does not come ready-made in R.
Where we start
From two things: takes values between 0 and 1, and since it is increasing, (and the same with ). For the uniform, if .
Part 1: F(X) is uniform
lives between 0 and 1. For , we apply to both sides (increasing: the inequality is kept):
on is the distribution function of the .
The step that gets skipped: because is exactly the at which equals . And is required because that is the only place where is defined.
Part 2: F⁻¹(U) has distribution F
Now we apply to both sides:
The last equality is the uniform’s, because is a number between 0 and 1.
For the kitchen
With , solving : , . So . And since is also , works just as well.
In the drawing, simulating with the inverse is “shooting a horizontal arrow” from a random height to the curve of and dropping down to the axis: the areas where rises fast (where the density is high) receive more arrows.
Check it with R
set.seed(2026) x <- -10 * log(runif(1e5)) # the inverse with U instead of 1 - U round(quantile(x, c(0.25, 0.5, 0.75)), 2) # simulated quartiles round(qexp(c(0.25, 0.5, 0.75), 0.1), 2) # quartiles of the exp(0.1) round(mean(pexp(x, 0.1) <= 0.3), 3) # part 1: F(X) is uniform
Output:
25% 50% 75% 2.86 6.89 13.86 [1] 2.88 6.93 13.86 [1] 0.302
The simulated quartiles are a few hundredths from the theoretical ones, and the proportion of comes out 0.302: practically the 0.3 a uniform gives.
Check you’ve got it: if runif gives , what kitchen time does simulate? And ?
Both, 6.93 minutes: with , also , and . It is the median of the kitchen, the 50% in the R output.
Proof 4: the expectation of a sum and of a product
What we want to prove
For and with joint density :
- , always.
- If they are independent, . In particular, .
Why it matters. With part 1, the mean of the arrival, , comes out without touching the joint density. Part 2 is the piece used in proofs 5 and 7: the covariance of two independent variables is 0, and the mgf of a sum splits into a product.
Where we start
From the definition and from the marginal. We do the continuous case; the discrete one is the same with sums.
Part 1: the sum
In the first term, doesn’t depend on and comes out of the inner integral, which is the marginal:
The same in the second with . We are left with . We haven’t used independence at any point.
What the first line does without saying so: the integral of a sum is the sum of the integrals, and constants come out. Then you integrate first in the variable that does not appear, and that leaves the marginal on its own.
Part 2: the product, with independence
If they are independent, , and the double integral of a product of a function of and another of splits:
The independence hypothesis is used in the first step, when writing . Without it, the integral doesn’t split.
The converse is not true
With , , and and are not independent. The product coming out “as if they were” proves nothing.
Check it with R
In the order, and are not independent: need not be . We integrate it over the triangle:
g <- function(x) integrate(function(y) x * y * 0.01 * exp(-0.1 * y), x, Inf)$value integrate(Vectorize(g), 0, Inf)$value # E(XY) on 0 < x < y 10 * 20 # E(X) E(Y)
Output:
[1] 300 [1] 200
300 against 200: the difference, 100, is exactly the covariance from the theory.
Check you’ve got it: in the order, why is correct even though and are not independent, while is not?
Part 1 does not use independence: always. Part 2 does, when writing . Since the arrival includes the kitchen, the joint density does not split and comes out as 300. A sum always splits; a product, only with independence.
Proof 5: the variance of a linear combination and the covariance with constants
What we want to prove
- .
- .
- if and if .
Why it matters. The first formula gives the variance of any sum, also of dependent variables like the kitchen and the arrival: the is what gets forgotten. The other two explain why the covariance changes with the units and the correlation does not.
Where we start
From the definitions and , and from the linearity in proof 4.
Part 1: the variance
By linearity, . We subtract and group:
We square it () and take expectations, again by linearity:
and each expectation is, by definition, , and . With independence, the covariance is 0 (proof 4) and you get the topic 5 formula.
Where the squares come from: , and the cross term is . When taking expectations, , and come out because they are constants.
Part 2: the covariance with constants
, so : the constant disappears. The same with . Then
Part 3: the correlation
With , the standard deviations are and :
is 1 if and if . That is why the correlation between the kitchen and the arrival is the same in minutes as in seconds: it has no units.
Check it with R
set.seed(2026)
x <- rexp(1e5, 0.1); y <- x + rexp(1e5, 0.1)
round(c(cor(x, y), cor(60 * x + 5, y), cor(x, -2 * y + 7)), 4)
round(c(var(2 * x - 3 * y),
4 * var(x) + 9 * var(y) - 12 * cov(x, y)), 2)
Output:
[1] 0.7055 0.7055 -0.7055 [1] 1007.29 1007.29
The correlation doesn’t change when the kitchen goes to seconds and gets 5 added, and only changes sign when the arrival is multiplied by . In the second line, the formula gives exactly the simulated variance (it is an algebraic identity, also with data). In theory, .
Check you’ve got it: what is in the order, and why is it not ?
With : . Adding only the variances would treat them as independent, and they are not: the arrival includes the kitchen, so when one gets longer the other does too.
Proof 6: the correlation lies between −1 and 1
What we want to prove
, and if and only if with probability 1 (the sign of is that of ).
Why it matters. Since the correlation is always between −1 and 1, a 0.71 means the same in minutes as in seconds. And the second part says what it measures: how close the points are to a straight line. A 0 does not say there is no relationship, only that it is not linear.
Where we start
From the Cauchy–Schwarz inequality: . We prove it with a trick: an expectation of a square is never negative.
Step 1: a parabola that is never negative
Let and . For any real number , , so its expectation isn’t negative either:
Why each term is what it is: expand and, when taking expectations, comes out because it is a number. , and are, by definition, the two variances and the covariance.
Step 2: the discriminant
is a parabola in (with ) that never goes below 0, so it touches the axis at one point at most: its discriminant cannot be positive.
Step 3: the correlation
Dividing by : , that is, .
Step 4: when it is ±1
is discriminant 0: the parabola touches the axis at a . Then , and a non-negative variable with expectation 0 is 0 with probability 1: , that is, , a straight line. Conversely, if : and , so .
If in an exam you get a correlation of 1.3, don’t look for an interpretation: there is a mistake in or in a variance. It is the same warning as a probability greater than 1.
Check it with R
set.seed(2026) x <- rexp(1e5, 0.1) round(c(cor(x, 3 * x + 2), cor(x, -x + 20), cor(x, x + rexp(1e5, 0.1))), 4)
Output:
[1] 1.0000 -1.0000 0.7055
1 and −1 for the two straight lines; and for the arrival, which is “the kitchen plus something that doesn’t depend on it”, an intermediate value, 0.71 (it comes out 0.7055; the theory gives ).
Check you’ve got it: where does the correlation of 0.71 between the kitchen and the arrival come from?
With proof 5: , because the kitchen and the delivery are independent. The standard deviations are 10 and , so . It does not reach 1 because the delivery adds something that does not depend on the kitchen.
Proof 7: the sum of independent exponentials is a gamma
What we want to prove
If and are independent and , then . More generally, if and are independent, .
Why it matters. It is the shortest way to find the distribution of a sum: instead of integrating the joint density over the triangle, you multiply two mgfs. That is why comes out with a single pgamma.
Where we start
From the mgf of the exponential (topic 4), for ; from that of the gamma, ; from the mgf determining the distribution, and from proof 4 with , .
Step by step
The third equality is independence (proof 4). The result is the mgf of a and, since the mgf determines the distribution, . For two gammas with the same , the same: .
The first two equals signs: the mgf of is by definition , and because an exponent that is a sum splits into a product. That product is a : that is why proof 4 comes in.
Adding two gammas with different and saying it is a gamma. The product is not the mgf of any gamma. The kitchen and the delivery add up to a gamma because they have the same .
Check it with R
set.seed(2026) y <- rexp(1e5, 0.1) + rexp(1e5, 0.1) round(c(mean(y <= 30), pgamma(30, 2, 0.1)), 4) round(c(mean(y), var(y)), 2) # gamma(2, 0.1): mean 20, variance 200
Output:
[1] 0.8012 0.8009 [1] 20.00 200.64
The simulated proportion of orders arriving within 30 minutes and the gamma’s agree up to the third figure (0.801), and the mean and variance are close to 20 and 200.
Check you’ve got it: if you add a third independent stage, the wait at the door , what distribution does have?
A . The mgf of the sum is the product of the three, , the one of a gamma with and . It works because all three have the same . The mean is minutes.
Proof 8: the Jacobian of the order
What we want to prove
If and are independent and , then and are independent, with and . And, on the way, the joint density of is on .
Why it matters. It is the two-dimensional theorem in full, in the order the exam asks for it: support, inverse, Jacobian, substitute and marginals. And it reads in the order: knowing how long it took in total says nothing about what share was kitchen.
Where we start
From the change of variable theorem in two dimensions (theorem 6 in the notes): if is bijective and differentiable, , with the determinant of the derivatives of the inverse. And from the joint density of : by independence, on .
Step 1: the new support
takes any positive value. is between 0 and 1, because . And each in corresponds to a single : the transformation is bijective.
Step 2: the inverse
From we get , and from we get .
Step 3: the Jacobian
. The minus sign is not carried along: it is the one in my anecdote. In the drawing, is the factor by which the area of a small patch is multiplied when going from to : a patch becomes a parallelogram of area , larger the bigger is.
Step 4: substitute
What substituting does: in , becomes and becomes . The exponent simplifies by itself, , and the in front is .
Step 5: the marginals and independence
The joint density is the product of (only ) times 1 (only ) on a rectangle. Integrating:
The second integral is 1 because it is the integral of a gamma density. And at every point: independent.
On the way: the triangle from the theory
With the transformation , the inverse is , , and
The condition has become : that is how the triangle is born.
Check it with R
set.seed(2026) x <- rexp(1e5, 0.1); r <- rexp(1e5, 0.1) t <- x + r; u <- x / t round(table(cut(u, c(0, 0.25, 0.5, 0.75, 1))) / 1e5, 3) # quarters of U round(cor(t, u), 3) round(c(mean(t <= 30 & u <= 0.5), pgamma(30, 2, 0.1) * 0.5), 4)
Output:
(0,0.25] (0.25,0.5] (0.5,0.75] (0.75,1]
0.251 0.249 0.250 0.250
[1] -0.001
[1] 0.4003 0.4004
How to read it
- The four quarters of each have about 25 % of the orders: it is a uniform.
cor(t, u)comes out practically 0. On its own it wouldn’t prove independence (zero correlation isn’t enough), but the third line does put it to the test:- simulated equals the product : the joint distribution also factorises on this event.
Check you’ve got it: what is by hand, and what does mean in the order?
By independence, , the 0.4004 from R: the 0.80 is the gamma from proof 7 and the 0.5, the uniform. means the kitchen took at most half of the total time.
Prove it yourself
Three proofs in the same style. Try each one on paper before opening the solution.
1. Prove that when is continuous with density . Use it to compute in the order knowing that .
See the solution
is a function of . Its expectation, with the density of :
The cancels, and what is left is the definition of with the joint density (proof 4). In the order: , without touching the gamma.
2. If and are independent, prove that . (It is the time until whatever finishes first, the kitchen or a message from the rider.)
See the solution
We work with the tail, , because the minimum is greater than if and only if both are. For :
The second equality is independence. Then , which is the distribution function of an . With the kitchen and the delivery, : a mean of 5 minutes.
3. If and , prove with the change of variable theorem that . What distribution does the kitchen time have measured in seconds?
See the solution
is increasing; the inverse is , with , and the support is still :
because . It is a . The kitchen, , in seconds () is : a mean of 600 seconds, the usual 10 minutes.
When to use each result
| You are asked for… | Use… |
|---|---|
| The density of with monotonic | Proof 1 () |
| The density of , or another that goes up and down | Back to and differentiate (proof 2) |
Simulating a distribution with runif | The inverse of (proof 3) |
| or | If independent, the product; if not, the double integral |
| The variance of a sum or a difference | (proof 5) |
| That a correlation doesn’t depend on the units | Proof 5, part 3 |
| That | Cauchy–Schwarz with the parabola (proof 6) |
| The distribution of a sum of independent variables | The product of mgfs (proof 7) |
| The distribution of | Support, inverse, Jacobian, substitute (proof 8) |
Typical mistakes when proving
In the one-dimensional change of variable, writing instead of . What is evaluated in the old density is the inverse: the value of that produces .
Computing the Jacobian with the derivatives of the direct transformation (…) instead of those of the inverse. If you do, you get . If the direct one is easier for you, fine, but then you have to divide.
Forgetting the support. “” without “” is not a complete answer, and it is exactly what lets you see that is uniform.
At the end of any proof that gives a density, integrate the result in your head (or with integrate): if it doesn’t give 1, there is a mistake earlier, almost always in a limit or in a Jacobian.
Try it in the R playground
Open the site’s R playground (or RStudio) and paste this script. It checks five of the eight proofs with simulations:
set.seed(1) n <- 1e5 # 2. Z^2 is a chi-squared with 1 degree of freedom z2 <- rnorm(n)^2 c(mean(z2 <= 1), pchisq(1, 1)) # 3. The inverse of F: -10 log(U) is an exp(0.1) x <- -10 * log(runif(n)); c(mean(x), sd(x)) # 5 and 6. The correlation doesn't change with units and lives between -1 and 1 y <- x + rexp(n, 0.1) c(cor(x, y), cor(60 * x, y / 60), cor(x, 5 - 3 * x)) # 7. The sum of two exponentials is a gamma(2, 0.1) hist(y, freq = FALSE, breaks = 60); curve(dgamma(x, 2, 0.1), add = TRUE, col = "red", lwd = 2) # 8. The kitchen fraction is uniform and independent of the total u <- x / y; hist(u, freq = FALSE); c(cor(u, y), mean(u <= 0.5 & y <= 30), 0.5 * pgamma(30, 2, 0.1))
What to look at:
- In the first line of results, the two numbers should be close: , the rule from topic 5.
cor(60 * x, y / 60)is the same ascor(x, y): going from minutes to seconds or hours doesn’t touch the correlation.cor(x, 5 - 3 * x)gives exactly −1: a decreasing straight line.- Change the delivery rate to 0.05: the histogram of
ystops following the gamma(2, 0.1) (and stops being gamma), and that ofustops being flat.
Summary
| Proof | Result | The key |
|---|---|---|
| 1. Change of variable | With decreasing, the inequality flips | |
| 2. | Two branches, | |
| 3. Inverse of | , | An increasing keeps inequalities |
| 4. Expectations | linear; product with independence | The marginal and |
| 5. Variance and covariance | ; | Added constants go away |
| 6. | Cauchy–Schwarz | A parabola that doesn’t go below 0 |
| 7. Sum of exponentials | Product of mgfs | |
| 8. Jacobian | gamma, uniform, independent | and the rectangular support |
Three ideas to take away:
- Every transformation starts with the support: where the new variable lives. Without it, neither the density nor independence can be read.
- The absolute value of the Jacobian is not decoration. It is what turns a change of ruler into a density that integrates to 1.
- Independence works in the first step of each proof: . Without it, doesn’t split and the covariance doesn’t vanish.
To put it into practice, the R practice computes all this with integrate, Vectorize and simulations, and the exam-style exercises mix proofs and R as in the EC2.
Did this article help you? Here is how you can support SergioLearns →



