Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Statistics - Mean


The mean is a type of average value, which describes where center of the data is located.


Mean

The mean is usually referred to as 'the average'.

The mean is the sum of all the values in the data divided by the total number of values in the data.

The mean is calculated for numerical variables. A variable is something in the data that can vary, like:

  • Age
  • Height
  • Income

Note: There are are multiple types of mean values. The most common type of mean is the arithmetic mean.

In this tutorial 'mean' refers to the arithmetic mean.


Calculating the Mean

You can calculate the mean for both the population and the sample.

The formulas are the same and uses different symbols to refer to the population mean (\(\mu\)) and sample mean (\(\bar{x}\)).

Calculating the population mean (\(\mu\)) is done with this formula:

\(\displaystyle \mu = \frac{\sum x_{i}}{n}\)

Calculating the sample mean (\(\bar{x}\)) is done with this formula:

\(\displaystyle \bar{x} = \frac{\sum x_{i}}{n}\)

The bottom part of the fraction (\(n\)) is the total number of observations.

\(\sum \) is the symbol for adding together a list of numbers.

\(x_{i}\) is the list of values in the data: \(x_{1}, x_{2}, x_{3}, \ldots \)

The top part of the fraction (\(\sum x_{i}\)) is the sum of \(x_{1}, x_{2}, x_{3}, \ldots \) added together.

So, if a sample has 4 observations with values: 4, 11, 7, 14 the calculation is:

\(\displaystyle \bar{x} = \frac{4 + 11 + 7 + 14}{4} = \frac{36}{4} = \underline{9} \)



Calculation with Programming

The mean can easily be calculated with many programming languages.

Using software and programming to calculate statistics is more common for bigger sets of data, as calculating by hand becomes difficult.

Example

With Python use the NumPy library mean() method to find the mean of the values 4,11,7,14:

import numpy

values = [4,11,7,14]

x = numpy.mean(values)

print(x)
Try it Yourself »

Example

Use the R mean() function to find the mean of the values 4,11,7,14:

values <- c(4,7,11,14)

mean(values)
Try it Yourself »

Statistics Symbol Reference

Symbol Description
\( \mu \) The population mean. Pronounced 'mu'.
\( \bar{x} \) The sample mean. Pronounced 'x-bar'.
\( \sum \) The summation operator, 'capital sigma'.
\( x \) The variable 'x' we are calculating the average for.
\( i \) The index 'i' of the variable 'x'. This identifies each observation for a variable.
\( n \) The number of observations.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.