This article was co-authored by Mario Banuelos, PhD. Mario Banuelos is an Assistant Professor of Mathematics at California State University, Fresno. With over eight years of teaching experience, Mario specializes in mathematical biology, optimization, statistical models for genome evolution, and data science. Mario holds a BA in Mathematics from California State University, Fresno, and a Ph.D. in Applied Mathematics from the University of California, Merced. Mario has taught at both the high school and collegiate levels.
There are 13 references cited in this article, which can be found at the bottom of the page.
wikiHow marks an article as reader-approved once it receives enough positive feedback. This article has 44 testimonials from our readers, earning it our reader-approved status.
This article has been viewed 2,970,033 times.
What is variance? Variance is a measure of how spread out a data set is, and we calculate it by finding the average of each data point's squared difference from the mean.[1] It's useful when creating statistical models since low variance can be a sign that you are over-fitting your data. Once you get the hang of the formula, you'll just have to plug in the right numbers to find your answer. Read on for a complete step-by-step tutorial that'll teach you how to calculate both sample variance and population variance.
Steps
Calculating Sample Variance
-
1Use the sample variance formula if you're working with a partial data set. In most cases, statisticians only have access to a sample, or a subset of the population they're studying. For example, instead of analyzing the population "cost of every car in Germany," a statistician could find the cost of a random sample of a few thousand cars. He can use this sample to get a good estimate of German car costs, but it will likely not match the actual numbers exactly.[2]
- Example: Analyzing the number of muffins sold each day at a cafeteria, you sample six days at random and get these results: 38, 37, 36, 28, 18, 14, 12, 11, 10.7, 9.9. This is a sample, not a population, since you don't have data on every single day the cafeteria was open.
- If you have every data point in a population, skip down to the method below instead.
-
2Write down the sample variance formula. The variance of a data set tells you how spread out the data points are. The closer the variance is to zero, the more closely the data points are clustered together. When working with sample data sets, use the following formula to calculate variance:[3]
- = ∑[( - x̅)]/(n - 1)
- is the variance. Variance is always measured in squared units.
- represents a term in your data set.
- ∑, meaning "sum," tells you to calculate the following terms for each value of , then add them together.
- x̅ is the mean of the sample.
- n is the number of data points.
Advertisement -
3Calculate the mean of the sample. The symbol x̅ or "x-bar" refers to the mean of a sample.[4] Calculate this as you would any mean: add all the data points together, then divide by the number of data points.[5]
-
Example: First, add your data points together: 17 + 15 + 23 + 7 + 9 + 13 = 84
Next, divide your answer by the number of data points, in this case six: 84 ÷ 6 = 14.
Sample mean = x̅ = 14. - You can think of the mean as the "center-point" of the data. If the data clusters around the mean, variance is low. If it is spread out far from the mean, variance is high.[6]
-
Example: First, add your data points together: 17 + 15 + 23 + 7 + 9 + 13 = 84
-
4Subtract the mean from each data point. Now it's time to calculate - x̅, where is each number in your data set. Each answer tells you that number's deviation from the mean, or in plain language, how far away it is from the mean.[7]
-
Example:
- x̅ = 17 - 14 = 3
- x̅ = 15 - 14 = 1
- x̅ = 23 - 14 = 9
- x̅ = 7 - 14 = -7
- x̅ = 9 - 14 = -5
- x̅ = 13 - 14 = -1 - It's easy to check your work, as your answers should add up to zero. This is due to the definition of mean, since the negative answers (distance from mean to smaller numbers) exactly cancel out the positive answers (distance from mean to larger numbers).
-
Example:
-
5Square each result. As noted above, your current list of deviations ( - x̅) sum up to zero. This means the "average deviation" will always be zero as well, so that doesn't tell use anything about how spread out the data is. To solve this problem, find the square of each deviation.[8] This will make them all positive numbers, so the negative and positive values no longer cancel out to zero.[9]
-
Example:
( - x̅)
- x̅)
92 = 81
(-7)2 = 49
(-5)2 = 25
(-1)2 = 1 - You now have the value ( - x̅) for each data point in your sample.
-
Example:
-
6Find the sum of the squared values. Now it's time to calculate the entire numerator of the formula: ∑[( - x̅)]. The upper-case sigma, ∑, tells you to sum the value of the following term for each value of . You've already calculated ( - x̅) for each value of in your sample, so all you need to do is add the results of all of the squared deviations together.[10] [11]
- Example: 9 + 1 + 81 + 49 + 25 + 1 = 166.
-
7Divide by n - 1, where n is the number of data points. A long time ago, statisticians just divided by n when calculating the variance of the sample. This gives you the average value of the squared deviation, which is a perfect match for the variance of that sample. But remember, a sample is just an estimate of a larger population. If you took another random sample and made the same calculation, you would get a different result. As it turns out, dividing by n - 1 instead of n gives you a better estimate of variance of the larger population, which is what you're really interested in. This correction is so common that it is now the accepted definition of a sample's variance.[12]
-
Example: There are six data points in the sample, so n = 6.
Variance of the sample = 33.2
-
Example: There are six data points in the sample, so n = 6.
-
8Understand variance and standard deviation. Note that, since there was an exponent in the formula, variance is measured in the squared unit of the original data. This can make it difficult to understand intuitively. Instead, it's often useful to use the standard deviation. You didn't waste your effort, though, as the standard deviation is defined as the square root of the variance. This is why the variance of a sample is written , and the standard deviation of a sample is .
- For example, the standard deviation of the sample above = s = √33.2 = 5.76.
Calculating Population Variance
-
1Use the population variance formula if you've collected data from every point in the population. The term "population" refers to the total set of relevant observations. For example, if you're studying the age of Texas residents, your population would include the age of every single Texas resident. You would normally create a spreadsheet for a large data set like that, but here's a smaller example data set:[13]
-
Example: There are exactly six fish tanks in a room of the aquarium. The six tanks contain the following numbers of fish:
-
Example: There are exactly six fish tanks in a room of the aquarium. The six tanks contain the following numbers of fish:
-
2Write down the population variance formula. Since a population contains all the data you need, this formula gives you the exact variance of the population. In order to distinguish it from sample variance (which is only an estimate), statisticians use different variables:[14]
- σ = (∑( - μ))/n
- σ = population variance. This is a lower-case sigma, squared. Variance is measured in squared units.
- represents a term in your data set.
- The terms inside ∑ will be calculated for each value of , then summed.
- μ is the population mean
- n is the number of data points in the population
-
3Find the mean of the population. When analyzing a population, the symbol μ ("mu") represents the arithmetic mean. To find the mean, add all the data points together, then divide by the number of data points.[15]
- You can think of the mean as the "average," but be careful, as that word has multiple definitions in mathematics.
- Example: mean = μ = = 10.5
-
4Subtract the mean from each data point. Data points close to the mean will result in a difference closer to zero. Repeat the subtraction problem for each data point, and you might start to get a sense of how spread out the data is.[16]
-
Example:
- μ = 5 - 10.5 = -5.5
- μ = 5 - 10.5 = -5.5
- μ = 8 - 10.5 = -2.5
- μ = 12 - 10.5 = 1.5
- μ = 15 - 10.5 = 4.5
- μ = 18 - 10.5 = 7.5
-
Example:
-
5Square each answer. Right now, some of your numbers from the last step will be negative, and some will be positive. If you picture your data on a number line, these two categories represent numbers to the left of the mean, and numbers to the right of the mean. This is no good for calculating variance, since these two groups will cancel each other out. Square each number so they are all positive instead.[17]
-
Example:
( - μ) for each value of i from 1 to 6:
(-5.5) = 30.25
(-5.5) = 30.25
(-2.5) = 6.25
(1.5) = 2.25
(4.5) = 20.25
(7.5) = 56.25
-
Example:
-
6Find the mean of your results. Now you have a value for each data point, related (indirectly) to how far that data point is from the mean. Take the mean of these values by adding them all together, then dividing by the number of values.[18]
-
Example:
Variance of the population = 24.25
-
Example:
-
7Relate this back to the formula. If you're not sure how this matches the formula at the beginning of this method, try writing out the whole problem in longhand:
- After finding the difference from the mean and squaring, you have the value ( - μ), ( - μ), and so on up to ( - μ), where is the last data point in the set.
- To find the mean of these values, you sum them up and divide by n: ( ( - μ) + ( - μ) + ... + ( - μ) ) / n
- After rewriting the numerator in sigma notation, you have (∑( - μ))/n, the formula for variance.
Help Calculating Variance
Expert Q&A
Did you know you can get expert answers for this article?
Unlock expert answers by supporting wikiHow
-
QuestionWhat are deviations?Mario Banuelos, PhDMario Banuelos is an Assistant Professor of Mathematics at California State University, Fresno. With over eight years of teaching experience, Mario specializes in mathematical biology, optimization, statistical models for genome evolution, and data science. Mario holds a BA in Mathematics from California State University, Fresno, and a Ph.D. in Applied Mathematics from the University of California, Merced. Mario has taught at both the high school and collegiate levels.
Assistant Professor of Mathematics -
QuestionWhat is the easiest way to find variance?Mario Banuelos, PhDMario Banuelos is an Assistant Professor of Mathematics at California State University, Fresno. With over eight years of teaching experience, Mario specializes in mathematical biology, optimization, statistical models for genome evolution, and data science. Mario holds a BA in Mathematics from California State University, Fresno, and a Ph.D. in Applied Mathematics from the University of California, Merced. Mario has taught at both the high school and collegiate levels.
Assistant Professor of Mathematics -
QuestionHow do I calculate the variance of four numbers?Community AnswerFollow these steps: Work out the mean (the simple average of the numbers.) Then, for each number, subtract the mean and square the result (the squared difference). Finally, work out the average of those squared differences.
References
- ↑ https://www.scribbr.com/statistics/variance/
- ↑ https://www.simplilearn.com/tutorials/machine-learning-tutorial/population-vs-sample
- ↑ https://www.youtube.com/watch?v=VgKHjVDK0uM
- ↑ http://stattrek.com/statistics/notation.aspx
- ↑ Mario Banuelos, PhD. Assistant Professor of Mathematics. Expert Interview. 11 December 2021.
- ↑ Mario Banuelos, PhD. Assistant Professor of Mathematics. Expert Interview. 11 December 2021.
- ↑ Mario Banuelos, PhD. Assistant Professor of Mathematics. Expert Interview. 11 December 2021.
- ↑ https://www.webpages.uidaho.edu/learn/statistics/lessons/lesson03/3_7.htm
- ↑ https://www.youtube.com/watch?v=sOb9b_AtwDg
- ↑ Mario Banuelos, PhD. Assistant Professor of Mathematics. Expert Interview. 11 December 2021.
- ↑ https://www.webpages.uidaho.edu/learn/statistics/lessons/lesson03/3_7.htm
- ↑ https://www.youtube.com/watch?v=sOb9b_AtwDg
- ↑ https://methods.sagepub.com/video/calculating-variance
- ↑ https://www.youtube.com/watch?v=VgKHjVDK0uM
- ↑ https://www.ncl.ac.uk/webtemplate/ask-assets/external/maths-resources/statistics/descriptive-statistics/variance-and-standard-deviation.html
- ↑ https://www.sciencebuddies.org/science-fair-projects/science-fair/variance-and-standard-deviation
- ↑ http://www.hunter.cuny.edu/dolciani/pdf_files/brushup-materials/calculating-variance-and-standard-deviation.pdf
- ↑ http://www.hunter.cuny.edu/dolciani/pdf_files/brushup-materials/calculating-variance-and-standard-deviation.pdf
- ↑ http://datapigtechnologies.com/blog/index.php/understanding-standard-deviation-2/
- ↑ http://www.statsdirect.com/help/default.htm#basics/degrees_freedom.htm
About This Article
To calculate the variance of a sample, or how spread out the sample data is across the distribution, first add all of the data points together and divide by the number of data points to find the mean. For example, if your data points are 3, 4, 5, and 6, you would add 3 + 4 + 5 + 6 and get 18. Then, you would divide 18 by the total number of data points, which is 4, and get 4.5. Therefore, the mean of the data set is 4.5. Next, subtract the mean from each data point in the sample. In this example, you would subtract the mean, or 4.5, from 3, then 4, then 5, and finally 6 and end up with -1.5, -0.5, 0.5, and 1.5. Now, square each of these results by multiplying each result by itself. If you square -1.5, -0.5, 0.5, and 1.5, you would get 2.25, 0.25, 0.25, and 2.25. Then, add up all of the squared values. Here, you would add 2.25 + 0.25 + 0.25 + 2.25 and get 5. Finally, divide the sum by n - 1, where n is the total number of data points. In the example there are 4 data points, so you would divide the sum, which is 5, by 4 - 1, or 3, and get 1.66. Therefore, the variance of the sample is 1.66. To learn how to calculate the variance of a population, scroll down!