*Standard error of the mean measures how spread out the means of the sample can be from the actual population mean. Standard error allows you to build a relationship between a sample statistic (computed from a smaller sample of the population) and the population’s actual parameter.*

Standard Error – A practical guide with examples. Photo by Sergio.

## What is Standard Error?

The sample error serves as a means to understand the actual population parameter (like population mean) without actually estimating it.

Consider the following scenario:

A researcher ‘X’ is collecting data from a large population of voters. For practical reasons he can’t reach out to each and every voter. So, only a small randomized sample (of voters) is selected for data collection.

Once the data for the sample is collected, you calculate the mean (or any statistic) of that sample. But then, this mean you just computed is only the sample mean. It cannot be considered the entire population’s mean. You can however expect it to be somewhere close to population’s mean.

So how can you know the actual population mean?

While its not possible to compute the exactly value, you can use standard error to estimate how far the sample mean may spread from the actual population mean.

To be more precise,

**The Standard Error of the Mean describes how far a sample mean may vary from the population mean.**

In this post, you will understand clearly:

- What Standard Error Tells Us?
- What is the Sample Error Formula?
- How to calculate Standard Error?
- How to use standard error to compute confidence interval?
- Example Problem and solution

## How to understand Standard Error?

Let’s first clearly understand the intuition behind and the need for standard error.

Now, let’s suppose you are working in agriculture domain and you want to know the annual yield of a particular variety of coconut trees. While the entire population of coconut trees has a certain mean (and standard deviation) of annual yield, it is not practical to take measurements of each and every tree out there.

So, what do you do?

To estimate this you collect samples of coconut yield (number of nuts per tree per year) from different trees. And to keep your findings unbiased, you collect samples across different places.

Let’s say, you collected data from approx ~5 trees per sample from different places and the numbers are shown below.

```
# Annual yield of coconut
sample1 = [400, 420, 470, 510, 590]
sample2 = [430, 500, 570, 620, 710, 800, 900]
sample3 = [360, 410, 490, 550, 640]
```

In above data, the variables `sample1`

, `sample2`

and `sample3`

contain the samples of annual yield values collected, where each number represents the yield of one individual tree.

Observe that the yield varies not just across the trees, but also across the different samples.

Although we compute means of the samples, we are actually not interested in the means of the sample, but the overall mean annual yield of coconut of this variety.

Now, you may ask: ‘**Why can’t we just put the values from all these samples in one bucket and simply compute the mean and standard deviation and consider that as the population’s parameter?**‘

Well, the problem is, if you do that practically what happens is, as you receive few more samples, the real population’s parameter begins to come out which is likely to be (slightly) different from the parameter you computed earlier.

Below is a code demo.

```
from statistics import mean, stdev
# Overall mean from the first two samples
sample1 = [400, 420, 470, 510, 590]
sample2 = [430, 500, 570, 620, 710, 800, 900]
print("Mean of first two samples: ", mean(sample1 + sample2))
# Overall mean after introducing 3rd sample
sample3 = [360, 410, 490, 550, 640]
print("Mean after including 3rd sample: ", mean(sample1 + sample2 + sample3))
```

Output:

```
Mean of first two samples: 576.6666666666666
Mean after including 3rd sample: 551.1764705882352
```

As you add more and more samples, the computed parameters keep changing.

So how to tackle this?

If you notice, each sample has its own mean that varies between a particular range. This mean (of the sample) has its own standard deviation. This measure of **standard deviation of the mean is called the standard error of the mean**.

Its important to note, it is different from the standard deviation of the data. The difference is, while standard deviation tells you how the overall data is distributed around the mean, the **standard error tells you how the mean itself is distributed**.

This way, it can be used to generalize the sample mean so it can be used as an estimate of the whole population.

In fact, standard error can be generalized to any statistic like standard deviation, median etc. For example, if you compute the **standard deviation of the standard deviations** (of the samples), it is called, **standard error of the standard deviation**. Feels like a tongue twister. But most commonly, when someone mention ‘Standard error’ it typically refers to the ‘Standard error of of the mean’.

## What is the Formula?

To calculate standard error, you simply divide the standard deviation of a given sample by the square root of the total number of items in the sample.

$$SE_{\bar{x}} = \frac{\sigma}{\sqrt{n}}$$

where, $SE_{\bar{x}}$ is the standard error of the mean, $\sigma$ is the standard deviation of the sample and `n`

is the number of items in sample.

Do not confuse this with standard deviation. Because standard error of the sample statistic (like mean) is typically much smaller than the population standard deviation.

Notice few things here:

**The Standard error depends on the number of items in the sample**. As you increase the number of items in the sample, lower will be the standard error and more certain you will be about the estimates.**It uses statistics (standard deviation and number of items) computed from the sample itself**, and not of the population. That is, you don’t need to know the population parameters beforehand to compute standard error. This makes it pretty convenient.- Standard error can also be used as an
**estimate of how representative a given sample is of a population**. The smaller the value, more representative is the sample of the whole population.

Below is a computation for the standard error of the mean:

```
# Compute Standard Error
sample1 = [400, 420, 470, 510, 590]
se = stdev(sample1)/len(sample1)
print('Standard Error: ', round(se, 2))
```

```
Standard Error: 15.19
```

## How to calculate standard error?

**Problem Statement**

A school aptitude test for 15 year old students studying in a particular territory’s curriculum, is designed to have a mean score of 80 units and a standard deviation of 10 units. A sample of 15 answer papers has a mean score of 85. Can we assume that these 15 scores come from the designated population?

**Solution**

Our task is to determine if this sample comes from the above mentioned population.

How to solve this?

We approach this problem by computing the standard error of the sample means and use it to compute the confidence interval between which the sample means are expected to fall.

If the given sample mean falls inside this interval, then its safe to assume that the sample comes from the given population.

Time to get into the math.

## Using standard error to compute confidence interval

Standard error is often used to compute confidence intervals

We know, n = 15, x_bar = 85, σ = 10

$$SE_\bar{x} = \frac{\sigma}{\sqrt{n}} = \frac{10}{\sqrt{15}} = 2.581$$

From a property of normal distribution, we can say with 95% confidence level that the sample means are expected to lie within a confidence interval of plus or minus two standard errors of the sample statistic from the population parameter.

But where did ‘normal distribution’ come from? You may wonder how we can directly assume a normal distribution is followed in this case. Or rather shouldn’t we test if the sample follows a normal distribution first before computing the confidence intervals.

Well, that’s NOT required. Because, the Central Limit Theorem tells us that even if a population is not normally distributed, a collection of sample means from that population will infact follow a normal distribution. So, its a valid assumption.

Back to the problem, let’s compute the confidence intervals for 95% Confidence Level.

- Lower Limit :
`80 - (2*2.581)`

= 74.838 - Upper Limit :
`80 + (2*2.581)`

= 85.162

So, 95% of our 15 item sample means are expected to fall between 74.838 and 85.162.

Since the sample mean of 85.0 lies within the computed range, there is no reason to believe that the sample does not belong to the population.

## Conclusion

Standard error is a commonly used term that we sometimes ignore to fully understand its significance. I hope the concept is clear and you can now relate how you can use standard error in appropriate situations.

**Next topic:** Confidence Interval