02.10 Lesson 10 of 12
1 hExpectation, Variance & Covariance
Summarize a distribution with its expected value and spread, then describe how two variables move together.
By the end of this lesson
You will be able to
- Calculate an empirical mean and variance.
- Explain expected value as a probability-weighted average.
- Interpret the sign of covariance.
- Distinguish covariance from standardized correlation.
Expectation and variance summarize one variable
For a discrete random variable, expected value is the probability-weighted average of its possible values. For observed data, the sample mean is the average of the observed values. Variance is the average squared distance from the mean under the chosen population or sample convention; standard deviation is its square root and returns to the original units. Variance grows quadratically when values are rescaled.
values = np.array([2.0, 4.0, 4.0, 6.0])
print(values.mean())
print(values.var())
print(values.std()) Covariance and correlation describe pairs
Covariance is positive when two variables tend to be above or below their own means together, and negative when one tends to be high while the other is low. Its magnitude depends on the units. Pearson correlation standardizes the relationship to a value from -1 to 1 and describes linear association. Neither statistic alone establishes that one variable causes the other.
temperature = np.array([10, 12, 15, 18, 20], dtype=float)
demand = np.array([30, 34, 41, 45, 48], dtype=float)
print(np.cov(temperature, demand, ddof=1)[0, 1])
print(np.corrcoef(temperature, demand)[0, 1]) Apply what you learned
ExerciseSummarize a pair of variables
Calculate descriptive statistics for a small set of observations and describe what the numbers do and do not establish.
- Calculate mean, variance and standard deviation for
[2, 4, 4, 6]. - Use NumPy with an explicit
ddofchoice and state whether you are using population or sample variance. - Calculate covariance and Pearson correlation for two short arrays.
- Multiply one array by 10 and recalculate covariance and correlation.
- Explain why correlation is unchanged by a positive rescaling while covariance changes.
Your output states the variance convention, correlation stays within [-1, 1], and your interpretation separates association from causation.
Free references
Study resources
- 01 Calculating the Mean, Variance and Standard Deviation Video
Watch the focused calculation and compare the definitions with the values in your exercise.
- 02 Covariance, Clearly Explained Video
Watch the single covariance explanation and focus on the sign and unit dependence.
- 03 Pearson’s Correlation, Clearly Explained Video
Watch the individual correlation explanation and note the difference from covariance.
Check your understanding
Self-test
-
Question 1
What does variance measure?
It measures average squared deviation from the mean, so it summarizes spread in squared units. -
Question 2
What does Pearson correlation add that covariance does not?
It standardizes covariance by both standard deviations, making the result unit-free and bounded between -1 and 1.
Completion check
Move on when
You can calculate the basic summaries and explain how mean, variance, covariance and correlation differ.