A lesson from Essential Probability & Statistics for ML
£29/month
£29/month£29/month or £249/year · 30-day money-back guarantee
Get full accessOur content is best on a larger screen
What covariance measures
The variance of is its expected squared deviation from its mean. With two random variables, we often want to know how they vary together: when is above its mean, is usually above its mean too, or below it?
To measure this, we multiply the two deviations:
Definition
For random variables and with means and , the covariance of and is the expected value of the product of their deviations,
This definition applies to any random variables. When and are discrete, with joint PMF , the law of the unconscious statistician for two random variables makes it a sum: each pair of values adds its product of deviations, weighted by its probability:
A term is positive when and lie on the same side of their means, and negative when they lie on opposite sides. The board below works through an example.
Over a three-day weekend,
Each dot is a pair of values
Practice questions
4 questions
A student revises for hours before a test, and is the number of errors they make in it. What sign would we expect to have?
Select the correct answer:
+ 3 more questions · unlocked with a subscription
Computing covariance from a joint table
The variance can be written using expected values alone, as , with no deviations from the mean. The covariance has a formula of the same form:
Theorem
For any random variables and ,
When and are discrete, with their joint PMF set out as a table, we find by weighting each cell's product by its probability,
and and from the marginal PMFs, the row and column sums of the table.
Details
A household is chosen at random. is the number of cars it owns, and if someone in it cycles to work, and otherwise. and have the following joint PMF:
Find .
Solution
The formula needs , and . We start with , weighting each cell's product by its probability. The product is whenever or , so only the cells and add to the sum:
Next we find the marginal PMFs by summing out. The row sums give , and the column sums give :
From the marginal PMFs, each mean weights the values by their probabilities:
We subtract the product of the means from the mean of the product:
The covariance is negative: in this table, households with more cars are less likely to have someone who cycles to work.
Practice questions
4 questions
Random variables and have the following joint PMF:
What is ?
Select the correct answer:
+ 3 more questions · unlocked with a subscription
Every time you pull an answer from memory, the memory gets stronger. Reading doesn't do that. Nodeledge asks you questions on every step of every lesson, then asks again after days, weeks and months.