Transformations and joint distributions — theory with a food delivery order, marginals, covariance and the Jacobian (and the 60 % that was 80 %)
One Friday night, waiting for some pizzas at the flat, I assured my flatmate that only six out of ten orders arrive on time. The app promised 30 minutes; I had assumed that the kitchen and the delivery take 10 minutes each on average, independently, and I had computed the probability that the kitchen took under 15 minutes and the delivery under 15: (1 - exp(-1.5))^2 gave 0.60. She had passed ME1 in June, and she took my phone: “Arriving on time means the sum does not go over 30. If the kitchen takes 5, the delivery can take 25.” With the right region, pgamma(30, 2, 0.1), you get 0.80. My mistake was not in any formula: it was in the drawing of the region.
This topic is about two things that are used together throughout the EC2. The first, transforming a variable: if you know the distribution of , what is the distribution of ? The second, working with two variables at once: the joint distribution, the marginals, the conditionals, independence, covariance and correlation, and how to change variables with a Jacobian. We pick up where we left off in the normal distribution and in continuous random variables: the densities, the exponential, the gamma and the mgf are the same, but now they come in pairs. The proofs, step by step, are in the transformations and joint distributions proofs.
Table of Contents
Before you start. For this topic you need what you saw in continuous random variables: that probability is an area under the density, that the distribution function is the area up to and that differentiating gives the density. And, from calculus, integrating exponentials, the chain rule and a 2 × 2 determinant. The topic has two halves. In the first, a single variable: if you know , what looks like, by two routes (the distribution function and the change of variable theorem). In the second, two variables at once: the joint distribution and, from it, marginals (sum or integrate out the other one), conditionals (slice and rescale), independence (does it factorise?), covariance and correlation (do they move together?) and the Jacobian, which is the change of variable with two variables. We use the same order from start to finish: kitchen , delivery and arrival . If you get lost, draw the support: almost every mistake in this topic shows up in that drawing.
The order that comes with us
You order dinner through an app from a restaurant near campus. From the moment you tap “Order”, two things happen, one after the other:
- the kitchen prepares the order: it takes minutes;
- the rider brings it to your door: it takes minutes.
The model for the whole topic: and are independent and both follow an , that is, they take 10 minutes on average each (it is a simple model with made-up data, but it has the shape of waiting times: many short ones and the odd long one). With them we will build the variables you really care about:
- , the minute the order arrives at your door;
- , what part of the wait is kitchen.
depends on : if the kitchen is slow, the order arrives late. Measuring that dependence is half of the topic. The other half is knowing what distribution or have without having to simulate.
Transforming one variable: Y = g(X)
The rider and their speed
We start with a single variable. The restaurant is 3 km away and the rider cycles at a speed that depends on the traffic: km/h. The delivery time, in minutes, is
You know the distribution of . What is the distribution of ? There are two routes and it pays to master both.
Route 1: through the distribution function
The distribution function method has three steps:
- Where the new variable lives. goes from 12 to 20, so goes from to minutes.
- Its distribution function, writing the event in terms of the variable you know. For :
- Differentiate to get the density:
Look at the third step of the chain: when you solve for in , the inequality flips, because is decreasing. It is where people slip most.
The distribution function method, step by step
The chain above does four things in one line. Here they are separated, because it is the same scheme you will repeat with any , also when it is not monotonic:
| Step | What you do | With the rider | Why |
|---|---|---|---|
| 1 | Find the support of the new variable | Take the endpoints of through the function: and . Outside that range, is 0 (below) or 1 (above) | |
| 2 | Write | It is the definition: you are only naming what you are looking for | |
| 3 | Translate the event into the variable you know | You multiply by and divide by , both positive. The appears because was in the denominator: is decreasing, and “short time” means “high speed” | |
| 4 | Use the you know | , and the uniform has | |
| 5 | Differentiate with respect to | The density is the derivative of . The derivative of is : the minus sign goes away on its own |
Quick check: at the endpoints of the support, and . If you don’t get 0 at one end and 1 at the other, the mistake is in step 3.
Check you’ve got it: what is and what does it mean for the order?
: 25 % of deliveries take 10 minutes or less. You can check it by going back to the speed, as in step 3: , and in a that is . If you got 0.75, you didn’t flip the inequality.
Route 2: the change of variable theorem
If is differentiable and strictly monotonic (always increasing or always decreasing) on the support of , the density of comes out directly:
With the rider: , and . Since on the whole support:
The same as by route 1. The absolute value does the job of “the inequality flips”: a density can never be negative.
In the drawing, the speed is flat (all equally likely) and the time is not: there are more orders near 9 minutes than near 15. The reason is in the curve in the middle: when the bike is fast, changing the speed by 1 km/h hardly changes the time, so a lot of probability piles up in a few minutes.
fR <- function(r) 22.5 / r^2 # the density we have found integrate(fR, 9, 15) # it must give 1 ER <- integrate(function(r) r * fR(r), 9, 15)$value c(ER, 180 / 16) # E(R) versus 180 / E(V) 1 - integrate(fR, 9, 12)$value # P(R > 12): delivery over 12 min
Output:
1 with absolute error < 1.1e-14 [1] 11.49358 11.25000 [1] 0.375
How to read it
1 with absolute error < 1.1e-14: the density is right, it integrates to 1 over its support. If you got something else, check the limits (from 9 to 15, not from 12 to 20).11.49358 11.25000: the mean delivery time is 11.49 minutes, not the 11.25 you get by dividing 180 by the mean speed of 16 km/h. In general unless is linear; with a convex , like , the mean of the result is larger.0.375: 37.5 % of the orders spend more than 12 minutes on the bike. You can check it without integrating, going back to the speed: , and . When you doubt a calculation with the new variable, translate it to the old one.
Where the absolute value comes from: the bands in the drawing
The theorem’s formula looks like magic, but you can read it with the drawing of the bands above. A density is probability divided by width. If you cut the speed into four bands of 2 km/h, each one has the same probability, . When you move to time, each band still has its 0.25, but it takes up a different width:
| Speed (km/h) | Time (min) | Width in minutes | Average density, 0.25 / width | Why |
|---|---|---|---|---|
| 18 to 20 | 9 to 10 | 1 | 0.25 | With a fast bike, 2 km/h change the time by only 1 minute: the probability piles up |
| 16 to 18 | 10 to 11.25 | 1.25 | 0.20 | The same probability, in a bit more room |
| 14 to 16 | 11.25 to 12.86 | 1.61 | 0.16 | The curve keeps getting steeper |
| 12 to 14 | 12.86 to 15 | 2.14 | 0.12 | With a slow bike, 2 km/h are more than 2 minutes: the density drops |
Those average densities fall between the values of at the edges of each band (in the first one, and ). The factor is exactly that: how many km/h fit into one minute of delivery. And it carries an absolute value because a width is never negative, even when the function goes down.
When g is not monotonic: back to F
The change of variable theorem cannot be used if goes up and down on the support, like or on the whole line: two values of reach the same . Then you go back to route 1.
The app estimates the arrival time and is off by minutes, with (sometimes over, sometimes under). Standardising, . How is , the squared standardised error, distributed? For :
Differentiating (chain rule on each term):
It is the chi-squared with 1 degree of freedom, , which is also a . You will see it again in topic 8. The two branches, and , contribute the same because the normal is symmetric.
1 - pchisq(4, df = 1) # P(W > 4): the squared error goes over 4 2 * (1 - pnorm(2)) # P(|Z| > 2): the same, said with the normal
Output:
[1] 0.04550026 [1] 0.04550026
Both give 0.0455: is the same as , that is, the app being off by more than 8 minutes (two standard deviations). 4.55 % of the time.
Applying to with a single root, . You get half the density (it integrates to 0.5) and you don’t notice until you check. Before using the theorem, ask yourself: is monotonic on the whole support of ?
Simulating any distribution with runif
There is one transformation that deserves its own section. If is continuous with distribution function :
- : passing a variable through its own gives a uniform.
- The other way round: if , then has distribution function .
The second one is what R uses under the hood to simulate. For the kitchen, ; solving, . So 10,000 kitchen times can be made from uniform numbers:
set.seed(2026) u <- runif(10000) x <- -10 * log(1 - u) # the inverse of F: simulated kitchen c(mean(x), var(x)) # an exp(0.1) has mean 10 and variance 100 mean(x <= 10); pexp(10, 0.1) # simulated proportion versus theoretical
Output:
[1] 9.964396 99.177245 [1] 0.6397 [1] 0.6321206
The mean comes out 9.96 and the variance 99.18, close to 10 and 100, and 64 % of the simulated kitchens take 10 minutes or less, against the 63.2 % that pexp says: the difference is simulation noise. It is exactly what qexp(u, 0.1) does: R’s q is the inverse of its p.
When you can’t remember whether a calculation with is right, simulate: x <- qexp(runif(1e5), 0.1) and compare its histogram with dexp. If they match, the calculation is right.
Two variables at once: the joint distribution
Dishes and drinks: the discrete case
We start with something you count. In each order from the restaurant, is the number of dishes (1, 2 or 3) and the number of drinks (0, 1 or 2). Looking at many orders, the restaurant has this joint probability function, :
| \\ | 0 | 1 | 2 | Marginal of |
|---|---|---|---|---|
| 1 dish | 0.20 | 0.15 | 0.05 | 0.40 |
| 2 dishes | 0.10 | 0.20 | 0.10 | 0.40 |
| 3 dishes | 0.02 | 0.08 | 0.10 | 0.20 |
| Marginal of | 0.32 | 0.43 | 0.25 | 1 |
Each cell is a probability (non-negative) and together they add up to 1. The marginals are read on the edges: adding each row gives that of and adding each column, that of . For example, : 32 % of the orders come without a drink.
Summing the joint table, row by row and column by column
The marginals of the table come from a very concrete question. To find , you don’t care how many drinks there are: an order with 1 dish can have 0, 1 or 2 drinks, and those three cases don’t overlap. So you add them up:
| Marginal | Calculation | Why |
|---|---|---|
| Row for 1 dish: every possible number of drinks | ||
| Row for 2 dishes | ||
| Row for 3 dishes. And : check done | ||
| Column for 1 drink: now you don’t care about the dishes | ||
| Column for 2 drinks. With the 0.32 from before, |
Keep this sentence: the marginal of one variable is the joint summed over everything the other one can do. In the continuous case it is the same sentence, with “sum” replaced by “integrate”.
p <- matrix(c(0.20, 0.15, 0.05,
0.10, 0.20, 0.10,
0.02, 0.08, 0.10), nrow = 3, byrow = TRUE,
dimnames = list(dishes = 1:3, drinks = 0:2))
addmargins(p) # the table with its marginals
pX <- rowSums(p); pY <- colSums(p)
p["3", ] / pX["3"] # drinks when there are 3 dishes
Output:
drinks dishes 0 1 2 Sum 1 0.20 0.15 0.05 0.4 2 0.10 0.20 0.10 0.4 3 0.02 0.08 0.10 0.2 Sum 0.32 0.43 0.25 1.0 0 1 2 0.1 0.4 0.5
How to read it
- The table with
Sum:addmarginsadds the row and column of totals, which are the marginals (0.40, 0.40, 0.20 for the dishes; 0.32, 0.43, 0.25 for the drinks) and the 1 in the corner. 0.1 0.4 0.5: it is the conditional distribution of the drinks when the order has 3 dishes: the 3-dish row divided by its marginal, . With 3 dishes, half the orders carry 2 drinks; in general (marginal), only 25 %. Knowing how many dishes there are changes what you expect of the drinks: you can already sense they are not independent.
The whole order: the continuous case
Back to the times. Now we look at the order with two numbers: , the minute it leaves the kitchen, and , the minute it arrives at your door. Always . Their joint density is
(where this formula comes from we will see with the Jacobian, at the end). A joint density does two things: and its integral over the whole plane is 1. And probabilities are volumes: the probability that falls in a region is the double integral of over .
In the drawing, the density only lives in the triangle above the diagonal , and it is stronger at the bottom (fast orders). That diagonal is what decides all the integration limits in the topic. For example, the probability that the kitchen finishes within 10 minutes and the order arrives within 30:
Look at the inner limit: starts at , not at 0, because there is nothing below the diagonal.
Before writing a double integral, draw the support and the region you are asked for, and sweep it with a vertical line ( fixed): where that line enters and where it leaves are the limits for . This is what I was missing with the 30 minutes: the region is a triangle, not the square .
The marginals
To keep a single variable, you integrate out the other one (in the discrete case, you add):
In the order, the infinities become the edges of the triangle:
The kitchen is an , as it should be, and the arrival minute is a : the sum of two independent exponentials with the same . In the second integral, does not depend on and comes out; what is left is the length of the interval, .
Integrating the joint density, with the drawing in front of you
It is the dishes and drinks table in continuous form: you fix one variable and “sum” everything the other one can do. The hard part is the limits, and the triangle gives them:
| Marginal | What you fix | The other one runs… | Why those limits | Result |
|---|---|---|---|---|
| The kitchen, | from to | Vertical line at : it enters the triangle through the diagonal (you can’t arrive before leaving the kitchen) and never leaves through the top | ||
| The arrival, | from to | Horizontal line at : the kitchen could have finished at any minute between 0 and the arrival |
In the first one, the calculation is : the antiderivative of is , which is 0 at infinity. With the marginal you can now work out anything about one variable: , without going back to the joint.
Integrating from 0 to infinity “because the arrival is positive”. You get for every : a “density” that is constant for , which would integrate to infinity. When a marginal comes out without the fixed variable in it, check the limits with the drawing.
f <- function(x, y) ifelse(x < y, 0.01 * exp(-0.1 * y), 0) fX <- function(x) integrate(function(y) f(x, y), x, Inf)$value fY <- function(y) integrate(function(x) f(x, y), 0, y)$value c(fX(10), dexp(10, 0.1)) # the marginal of X at x = 10 c(fY(30), dgamma(30, 2, 0.1)) # the marginal of Y at y = 30 pgamma(30, 2, 0.1) # P(Y <= 30): arrives on time
Output:
[1] 0.03678794 0.03678794 [1] 0.01493612 0.01493612 [1] 0.8008517
How to read it
0.03678794 0.03678794: integrating the joint density in from to infinity gives the same as the exponential density. The marginal is right.0.01493612 0.01493612: the same with the gamma. It is a density height (per minute), not a probability.0.8008517: the probability that the order arrives in 30 minutes or less is 0.80. It is the one from the beginning: the right one.
If you know the joint, you know the marginals. Not the other way round: two different joints can have the same marginals. That is why the marginals say nothing about how the variables are related.
The conditionals
The distribution of given that is the joint density cut along the line and rescaled so that it integrates to 1 again:
In the order:
Both have a very concrete reading, and in the drawing they look like two slices of the triangle:
- . If the order arrived at minute 30, the kitchen may have finished at any moment between 0 and 30, all equally likely. Its mean is .
- is plus an . If the kitchen finished at minute 10, the order arrives 10 minutes later on average: .
Two results you will use a lot (theorem 4 in the notes):
With the order: and , the same as the gives: mean and variance .
Conditioning is slicing and rescaling, first with the table
The formula is easier to understand with the table. Knowing that the order has 1 dish means keeping the row for 1 dish and forgetting the other two. That row adds up to 0.40, not 1, so each cell is divided by 0.40 to make it a distribution again:
| Drinks, | Cell | Why | |
|---|---|---|---|
| 0 | 0.20 | Half the 1-dish orders have no drink | |
| 1 | 0.15 | Slice: only the 1-dish row counts | |
| 2 | 0.05 | Rescale: |
In the continuous case it is the same. If the order arrived at minute 30, you slice the triangle along the line : what is left is , the same height for every between 0 and 30. That “row” doesn’t integrate to 1, but to (the 0.01493612 in the R output). After dividing, you get over the whole interval: a . The slice is flat because the joint density doesn’t depend on .
Check you’ve got it: with the dishes and drinks table, do you get by averaging the conditional means, as the theorem says?
Yes. First, the mean number of drinks in each row, with its conditional distribution. With 1 dish: . With 2 dishes, the row divided by 0.40 is 0.25, 0.50 and 0.25, and the mean is . With 3 dishes, 0.10, 0.40 and 0.50, and the mean is . Then you average those means with the weight of each row, which is the marginal of : . It is the same mean the marginal of gives. The conditional means go up with the dishes (0.625, 1 and 1.40): another hint that dishes and drinks are not independent.
Independence
and are independent if and only if the joint density is the product of the marginals at every point:
- Kitchen and delivery, : yes. Their joint density is on the quadrant : a product of a function of and another of , on a rectangular support.
- Kitchen and arrival, : no. At the joint density is 0 (you cannot arrive before leaving the kitchen), but .
If the support is not a rectangle (a triangle, a circle, …), the variables are not independent: the value of one limits what the other can be. You don’t need to compute anything else.
In the discrete table, and : a single cell that doesn’t match is enough for them not to be independent.
Checking independence cell by cell
In a table, “the joint is the product of the marginals” means: in each cell, multiply the marginal of its row by the marginal of its column and compare. If all nine match, they are independent; if one fails, they are not:
| Dishes / drinks | 0 | 1 | 2 |
|---|---|---|---|
| 1 dish (0.40) | versus 0.20 | versus 0.15 | versus 0.05 |
| 2 dishes (0.40) | 0.128 versus 0.10 | 0.172 versus 0.20 | 0.10 versus 0.10 |
| 3 dishes (0.20) | 0.064 versus 0.02 | 0.086 versus 0.08 | 0.05 versus 0.10 |
With 1 dish there are more orders without a drink than there would be if they were independent (0.20 versus 0.128), and with 3 dishes, more with 2 drinks (0.10 versus 0.05). In the continuous case, the check has two questions, in this order: is the support a rectangle? (if not, you are done: they are not independent) and, if it is, can the joint be written as something in times something in ?
Check you’ve got it: in the cell for 2 dishes and 2 drinks the product matches (0.40 · 0.25 = 0.10). Does that say anything about independence?
Nothing. Independence is “for every “: all nine cells have to match. One matching can be a coincidence, as here; one failing, like the one for 1 dish and 0 drinks, is enough to say they are not independent. In the exam, to deny it you only need to show one cell that fails; to claim it, you have to check them all.
Expectation of a function of two variables
For any function :
Two consequences used all the time:
- Linearity, always: , whether they are independent or not.
- The product, only with independence: if and are independent, (and, in general, ). The converse is not true.
In the order, is not , because and are not independent. You have to integrate:
Covariance and correlation
The covariance measures whether two variables move together, and the correlation does the same without units:
In the order: and
Positive: when the kitchen takes longer, the order tends to arrive later. It is not 1 because the delivery adds noise that has nothing to do with the kitchen.
set.seed(2026) x <- rexp(10000, 0.1) # kitchen r <- rexp(10000, 0.1) # delivery, independent y <- x + r # arrival minute round(c(cov(x, y), cor(x, y)), 2) round(c(cov(x, r), cor(x, r)), 2) round(c(var(y - x), var(x) + var(y) - 2 * cov(x, y)), 2)
Output:
[1] 103.58 0.72 [1] 0.57 0.01 [1] 98.86 98.86
How to read it
103.58 0.72: with 10,000 simulated orders, the covariance comes out close to 100 and the correlation, 0.72, one hundredth away from the theoretical 0.71.0.57 0.01: kitchen and delivery are independent and their simulated correlation is practically 0 (not exactly 0 because of the randomness of the simulation).98.86 98.86, two equal numbers: it is the formula for the variance of a linear combination, the one you need to know:
With : , which is the variance of the delivery, as it should be, because . If you forget the covariance term, you get 300: three times as much.
Properties that come up (all proved in the proofs article):
| Property | What it says |
|---|---|
| The variance is the covariance of a variable with itself | |
| It comes from the Cauchy–Schwarz inequality | |
| Sign of | |
| Added constants don’t count | |
| Changing units doesn’t change the correlation (only its sign, if ) | |
| Independent | The converse is not true |
Covariance cell by cell: dishes and drinks
With the discrete table you can see what covariance does inside, without integrals. For you need three means. Two come from the marginals: and . For , each cell contributes its product times its probability:
| Cell | Why | |||
|---|---|---|---|---|
| 0 | 0.32 in total | 0 | With no drinks, the product is 0: the whole column contributes nothing | |
| 1 | 0.15 | 0.15 | ||
| 2 | 0.05 | 0.10 | ||
| 2 | 0.20 | 0.40 | ||
| 4 | 0.10 | 0.40 | ||
| 3 | 0.08 | 0.24 | ||
| 6 | 0.10 | 0.60 | The one that contributes most: a big order with lots of drinks | |
| Total | 1 |
So . Positive: more dishes, more drinks. With the variances, and , the correlation is : a weakish linear relationship, much weaker than the one between kitchen and arrival.
The other formula, , explains the sign. Where both variables are above their mean (3 dishes, 2 drinks) or both below (1 dish, 0 drinks), the product of the distances is positive, and those two cells contribute a lot: 0.13 and 0.15. The “crossed” ones (1 dish with 2 drinks, 3 dishes with no drink) subtract, but only a little. The balance is 0.22.
Zero covariance is not independence
This is the mistake of the topic. Covariance only measures the linear relationship. Take the app’s error, , and its square, . They are tightly linked (if you know , you know exactly), but
because the normal is symmetric and .
In the drawing there are three clouds of 400 simulated points. The one on the left, kitchen and delivery, has no shape: independent. The middle one, kitchen and arrival, goes up: correlation 0.71. The one on the right is a perfect parabola and its correlation is 0. A correlation close to 0 doesn’t let you say there is no relationship: only that there is no straight line.
“Since , they are independent.” It only works the other way round (independent ⇒ covariance 0). To prove independence you have to see that the joint density factorises, or that the joint mgf factorises. There is one important exception: with a bivariate normal, does imply independence.
The bivariate normal
It is the most used joint distribution: two normal variables with a correlation . In the delivery, is the distance of the order (km) and the delivery time (min), with and (further away, more time). Its density is
What you need to know about it:
- Its marginals are normal: and .
- So are its conditionals, with the mean moved by the regression line and the standard deviation shrunk:
- independent (here, yes).
An order 5 km away: .
1 - pnorm(25, 15, 4) # P(R > 25) without knowing the distance 1 - pnorm(25, 21.4, 2.4) # P(R > 25 | D = 5)
Output:
[1] 0.006209665 [1] 0.0668072
Without knowing the distance, only 0.62 % of deliveries go over 25 minutes. Knowing that the order goes 5 km away, the probability rises to 6.68 %, more than ten times as much: the information about one variable changes what you expect of the other when they are correlated.
In the drawing, the “mountain” of the bivariate normal seen from above: tilted ellipses because . The dashed line is the slice at : the coral bell on the right is the conditional, centred at 21.4 and narrower than the marginal of .
The lab sessions use the mnormt package, whose function dmnorm(cbind(d, r), mean, cov) computes exactly this density from the mean vector and the covariance matrix , with off the diagonal. In this topic’s practice we write the formula by hand to see where each number comes from.
The joint mgf
As with one variable, the joint moment generating function keeps the whole distribution:
Its properties:
- and : the marginals come out by setting a zero.
- The derivatives at give the moments: , , .
- and are independent .
In the order, since with and independent:
It doesn’t factorise into a part in times a part in : they are not independent. Differentiating twice, , the same number as before.
The mgf is also the quick way to add independent variables: , which is the mgf of a . That is why the arrival minute is gamma.
Changing two variables at once: the Jacobian
With two variables, the change of variable theorem carries a Jacobian. If and is a bijective transformation, with inverse :
What part of the wait is kitchen? We go from , independent, to (the total) and (the kitchen fraction). The four steps:
- The new support: and .
- The inverse: and .
- The Jacobian:
- Substitute:
The joint density is (something in ) × 1 on a rectangle: , and they are independent. Translated to the order: the fraction of the wait spent in the kitchen is equally likely to be any value between 0 and 1, and it doesn’t depend on whether the order took long or not. Something you can’t see by eye and that the Jacobian gives in four lines.
And the triangle density from the beginning comes out the same way: from to , with inverse and , you get with .
The Jacobian, step by step and with the why
The list above does in three lines what the exam marks separately. The usual order, with the change from to :
| Step | What you do | In the order | Why |
|---|---|---|---|
| 1 | Write the starting joint density and its support | , with | They are independent: the joint is the product of the two exponentials |
| 2 | Solve for the inverse | , | The old density is evaluated at and , so you need them in terms of and |
| 3 | The new support | and say that the kitchen is a part (neither nothing nor everything) of a positive total | |
| 4 | The Jacobian and its absolute value | , | You differentiate the inverse, not the direct transformation. The absolute value, because it is a change of area |
| 5 | Substitute and simplify | In the exponential, : the disappears | |
| 6 | Check that it integrates to 1 | It is the whole gamma. If you get something else, the is missing or the support is wrong |
Step 5 is the one with the surprise: since disappears from the formula and its support, , doesn’t depend on , the joint factorises on a rectangle. That is exactly the independence from before.
Check you’ve got it: in the change from to , why is the Jacobian 1 and where does the triangle come from?
The inverse is and . Its derivatives: , , and . The determinant is : this change neither stretches nor shrinks areas, it only tilts them. The new support comes from the old conditions: stays the same and becomes , that is, . Hence the triangle , and hence and can’t be independent.
Forgetting the absolute value of the Jacobian (you get a negative “density”) or not recomputing the support. In the exam, the support of is worth marks: always write it, and check that the joint density integrates to 1.
In R: what you need
| I want… | In R |
|---|---|
| A double integral | integrate(Vectorize(function(x) integrate(function(y) f(x, y), a(x), b(x))$value), x0, x1) |
| A marginal at a point | integrate(function(y) f(x0, y), lower, upper)$value |
| Marginals of a table | rowSums(p), colSums(p), addmargins(p) |
| Check independence in a table | all.equal(p, outer(rowSums(p), colSums(p)), check.attributes = FALSE) |
| Covariance and correlation of data | cov(x, y), cor(x, y) |
| Simulate with the inverse | qexp(runif(n), rate) (or the inverse you have worked out) |
| Bivariate normal density | the formula, or mnormt::dmnorm(cbind(x, y), mu, Sigma) |
| Draw a surface | z <- outer(x, y, f) and persp(x, y, z) or contour(x, y, z) |
The Vectorize is not decoration: integrate passes the outer function a vector of points at once, and the inner one only knows how to compute one. You will see it fail in the practice.
What is proved in this topic
They are all, step by step, in the transformations and joint distributions proofs:
- The change of variable theorem, in both versions ( increasing and decreasing).
- If , then .
- and has distribution function .
- and, with independence, .
- , and the correlation of and .
- , with only if one variable is a straight line of the other.
- The sum of two independent exponentials is a gamma (with the mgf).
- The Jacobian of the order: gamma total, uniform fraction and independent.
Typical mistakes
Integration limits of a rectangle on a triangular support. If the joint density lives on , the marginal of is integrated in from , and that of in up to . A marginal that depends on the variable you have just integrated out is wrong.
Using or without independence. In the order, , not 300.
Concluding independence because a conditional “looks like” the marginal at one point. Independence is at every point: a single cell (or a point of the plane) that fails breaks it.
Always check that what you got is a density: non-negative and integrating to 1 over its support. With integrate in R it takes ten seconds and saves you half an exercise.
Try it in the R playground
Open the site’s R playground (or RStudio) and paste this script. It brings together the rider’s speed, the joint density of the order and the Jacobian:
# 1. The rider: V ~ U(12, 20) km/h and R = 180 / V minutes set.seed(1); v <- runif(1e5, 12, 20); r <- 180 / v hist(r, freq = FALSE, breaks = 40) curve(22.5 / x^2, from = 9, to = 15, add = TRUE, lwd = 2, col = "red") c(mean(r), 180 / 16) # E(R) versus 180 / E(V) # 2. The order: kitchen X and delivery independent, arrival Y = X + delivery x <- rexp(1e5, 0.1); y <- x + rexp(1e5, 0.1) plot(x[1:500], y[1:500], pch = 20); abline(0, 1, col = "red") # the triangle c(cov(x, y), cor(x, y)) # close to 100 and 0.71 # 3. The Jacobian: the kitchen fraction is uniform and independent of the total u <- x / y hist(u, freq = FALSE); cor(u, y)
What to look at:
- In the first histogram, the bars go down from left to right following , even though the speed was flat.
- In the scatter plot, none of the points is below the red line : it is the support .
- Change the second exponential to
rexp(1e5, 0.05)(deliveries of 20 minutes on average): does the correlation go up or down? Think about why before running it. - The histogram of
ucomes out flat andcor(u, y)almost 0. If you change the two rates to different values, does it still come out flat?
Summary
| Concept | Formula | In the order |
|---|---|---|
| Change of variable ( monotonic) | : on | |
| not monotonic | via and differentiate | |
| Inverse of | kitchen | |
| Marginal | , | |
| Conditional | ||
| Independence | at every point | yes; no |
| Covariance | ||
| Correlation | ||
| Variance of | ||
| Jacobian | , , independent |
Three ideas to take away:
- Draw the support before integrating. The diagonal decides the limits, the independence and half the mistakes in the topic.
- Zero covariance is not independence. Independence means the joint density (or the joint mgf) factorises at every point.
- Transforming is changing ruler, and the Jacobian is the scale factor. With one variable, ; with two, . Without it, the density doesn’t integrate to 1.
Now, to prove it: the topic proofs have the eight results step by step, and in the R practice you simulate and integrate them. The next ME1 topic is inequalities and limit theorems: why the mean of many orders looks more and more like a normal.
Next step: proofsTransformations 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)Did this article help you? Here is how you can support SergioLearns →



