02.10 Lesson 10 of 12

1 h

Expectation, 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

Exercise

Summarize a pair of variables

Calculate descriptive statistics for a small set of observations and describe what the numbers do and do not establish.

  1. Calculate mean, variance and standard deviation for [2, 4, 4, 6].
  2. Use NumPy with an explicit ddof choice and state whether you are using population or sample variance.
  3. Calculate covariance and Pearson correlation for two short arrays.
  4. Multiply one array by 10 and recalculate covariance and correlation.
  5. Explain why correlation is unchanged by a positive rescaling while covariance changes.
Done when

Your output states the variance convention, correlation stays within [-1, 1], and your interpretation separates association from causation.

Free references

Study resources

3 links
  1. 01
    Calculating the Mean, Variance and Standard Deviation Video

    Watch the focused calculation and compare the definitions with the values in your exercise.

  2. 02
    Covariance, Clearly Explained Video

    Watch the single covariance explanation and focus on the sign and unit dependence.

  3. 03
    Pearson’s Correlation, Clearly Explained Video

    Watch the individual correlation explanation and note the difference from covariance.

Check your understanding

Self-test

2 questions
  1. Question 1

    What does variance measure?

  2. Question 2

    What does Pearson correlation add that covariance does not?

Completion check

Move on when

You can calculate the basic summaries and explain how mean, variance, covariance and correlation differ.

Quick find

Search Michi

Type to search every stage, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels