 StatLect

# Variance formula

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. ## General formula

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

• denotes the variance;

• denotes the expected value operator.

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 where:

• is the set of all possible realizations of (called the support of );

• is the probability mass function of ;

• the notation indicates that we need to perform a sum over all the values that can take.

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

### Example

Suppose that can take only two values, and , each with probability .

Then, the support of is and its probability mass function is We first need to calculate the expected value: Then, we can compute the variance: ## Formula for continuous variables

When is continuous, the variance formula is where:

• is the probability density function of ;

• the notation indicates that we need to take an integral between and .

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

### Example

Suppose that has a uniform distribution, with probability density We compute the expected value: The variance is: ## 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: ### 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 (already done!) and the second moment Then, we plug the two moments in the equation: ### Use with moment generating function

When we know the moment generating function of , we can use it to compute the two moments and 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.

Previous entry: Unbiased estimator