Search for probability and statistics terms on Statlect
StatLect

Variance formula

by , PhD

A variance formula is an equation used to compute or define the variance.

There are several formulae that can be used, depending on the situation.

Table of Contents

General formula

We start with a general formula, used to define the variance of a random variable X:[eq1]where:

This is a definition and it is useful because of its generality. However, if you need to calculate the variance in practice, you need to use the equations below.

Formula for discrete variables

When the random variable is discrete the above formula becomes[eq2]where:

In other words, we need to compute a weighted average of the squared deviations of X from its mean.

Example

Suppose that X can take only two values, $x_{1}=1$ and $x_{2}=3$, each with probability $1/2$.

Then, the support of X is[eq4]and its probability mass function is[eq5]

We first need to calculate the expected value:[eq6]

Then, we can compute the variance:[eq7]

Formula for continuous variables

When X is continuous, the variance formula is[eq8]where:

To understand the next example you need to be familiar with integration rules.

Example

Suppose that X has a uniform distribution, with probability density[eq11]

We compute the expected value:[eq12]

The variance is:[eq13]

Variance formula based on moments

Instead of computing variance using the formulae above, it is often easier to use the following equivalent equation based on moments:[eq14]

Example

Let us continue with the example of the uniform distribution.

Instead of using the variance formula for continuous variables, we compute the first moment [eq15] (already done!) and the second moment[eq16]

Then, we plug the two moments in the equation:[eq17]

Use with moment generating function

When we know the moment generating function of X, we can use it to compute the two moments [eq18] and [eq15] and then plug their values in the formula above.

Formulae for the sample variance

Until now, we have discussed how to calculate the variance of a random variable.

However, there is another concept, that of sample variance, that applies when we need to assess the dispersion of some observations around their sample mean.

If you are interested in the formulae for sample variance, you can check the following pages:

More details, proofs and exercises

More details about these formulae - including proofs and solved exercises - can be found in the lecture entitled Variance.

Keep reading the glossary

Previous entry: Unbiased estimator

Next entry: Variance inflation factor

How to cite

Please cite as:

Taboga, Marco (2021). "Variance formula", Lectures on probability theory and mathematical statistics. Kindle Direct Publishing. Online appendix. https://www.statlect.com/glossary/variance-formula.

The books

Most of the learning materials found on this website are now available in a traditional textbook format.