#set document(title: "3.12 Measures of Variability", author: "OpenStax") #set page(width: 8.5in, height: auto, margin: 1in) #import "@preview/cetz:0.5.2" #set text(font: ("STIX Two Text", "Libertinus Serif", "New Computer Modern"), size: 10.5pt, lang: "en") #show math.equation: set text(font: ("STIX Two Math", "New Computer Modern Math")) #set par(justify: true, leading: 0.62em, spacing: 0.9em) #set enum(spacing: 1.1em) // room between list items so tall inline fractions don't collide #set list(spacing: 1.1em) #set table(stroke: 0.5pt + rgb("#c7ccd3")) #let BLUE = rgb("#183B6F") // brand navy — section bars + example/solution labels (white on navy 11.09:1) #let ORANGE = rgb("#A94509") // brand primary-700 — AA-safe deep orange for TEXT (5.93:1 on white; raw brand #F37021 is 2.94:1 and must never carry text) #let RED = rgb("#DC2626") // brand error-600 #let GREEN = rgb("#059669") // brand success-600 (decoration only; small green text uses green-text #007942) #show heading.where(level: 1): it => block(width: 100%, above: 0pt, below: 16pt, fill: gradient.linear(BLUE, rgb("#2C5AA0")), inset: (x: 14pt, y: 12pt), radius: 3pt, text(fill: white, weight: "bold", size: 19pt, it.body)) #show heading.where(level: 2): it => block(width: 100%, above: 18pt, below: 10pt, fill: BLUE, inset: (x: 10pt, y: 6pt), radius: 2pt, text(fill: white, weight: "bold", size: 12pt, it.body)) #show heading.where(level: 3): it => text(fill: ORANGE, weight: "bold", size: 12.5pt, it.body) #show heading.where(level: 4): it => text(fill: BLUE, weight: "bold", size: 10.5pt, it.body) #let examplebox(label, title, body) = block(width: 100%, breakable: true, fill: rgb("#EFF1F5"), stroke: 0.5pt + rgb("#CFDDF0"), radius: 4pt, inset: 10pt, above: 12pt, below: 12pt)[ #block(below: 6pt)[#box(fill: BLUE, inset: (x: 6pt, y: 2pt), radius: 2pt, text(fill: white, weight: "bold", size: 8.5pt, label)) #h(0.4em) #strong[#title]] #body] // rail = decorative left rule (raw brand token); labelcolor = AA-safe label text shade #let notebox(label, rail, labelcolor, tint, body) = block(width: 100%, breakable: true, fill: tint, stroke: (left: 3pt + rail), inset: (left: 10pt, rest: 8pt), radius: (right: 4pt), above: 11pt, below: 11pt)[ #text(fill: labelcolor, weight: "bold", size: 7.5pt, tracking: 0.5pt)[#upper(label)] #linebreak() #body] #let solutionbox(body) = block(above: 4pt, below: 8pt)[ #text(fill: BLUE, weight: "bold", size: 8.5pt)[Solution] #linebreak() #body] #let figph(msg) = block(width: 100%, height: 60pt, fill: rgb("#f6f7f9"), stroke: (paint: rgb("#c7ccd3"), dash: "dashed"), radius: 4pt, inset: 10pt)[ #align(center + horizon, text(fill: rgb("#889"), style: "italic", size: 9pt, msg))] // Standardize inlined figure sizes: measure the natural CeTZ canvas, then scale to a // consistent envelope (aspect-aware; see build_typst.py FIG_* constants). Unlike the // print preamble, dimensions are FLOORED: in an editor a user can trim a figure to a // degenerate 1-D shape (a bare line), and w/h or tw/w would then divide by zero. #let _STD_W = 3.5 #let _WIDE_W = 5.6 #let _MAX_H = 3.4 #let _ASPECT_WIDE = 2.2 #let _UPSCALE_MAX = 1.15 #let stdfig(body) = context { let m = measure(body) let w = calc.max(m.width / 1in, 0.01) let h = calc.max(m.height / 1in, 0.01) let tw = if w / h > _ASPECT_WIDE { _WIDE_W } else { _STD_W } let s = calc.min(tw / w, _MAX_H / h, _UPSCALE_MAX) align(center, box(scale(x: s * 100%, y: s * 100%, reflow: true, body))) } #show figure: set block(breakable: false) #set figure(gap: 8pt) #show figure.caption: set text(size: 8.5pt, fill: rgb("#555")) == 3.12#h(0.6em)Measures of Variability #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Prerequisites] Percentiles, Distributions, Measures of Central Tendency #linebreak() #linebreak() ] #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Learning Objectives] + Determine the relative variability of two distributions + Compute the range + Compute the inter-quartile range + Compute the variance in the population + Estimate the variance from a sample + Compute the standard deviation from the variance ] === What is Variability? Variability refers to how "spread out" a group of scores is. To see what we mean by spread out, consider graphs in Figure 1. These graphs represent the scores on two quizzes. The mean score for each quiz is 7.0. Despite the equality of means, you can see that the distributions are quite different. Specifically, the scores on Quiz 1 are more densely packed and those on Quiz 2 are more spread out. The differences among students were much greater on Quiz 2 than on Quiz 1. #figure(figph[Bar chart of the 20 Quiz 1 scores: two students scored 5, six scored 6, five scored 7, four scored 8, and three scored 9, on a frequency axis from 0 to 7. The scores are packed tightly around the mean of 7.], alt: "Bar chart of the 20 Quiz 1 scores: two students scored 5, six scored 6, five scored 7, four scored 8, and three scored 9, on a frequency axis from 0 to 7. The scores are packed tightly around the mean of 7.", caption: [Figure 1. Bar charts of two quizzes.]) #figure(figph[Bar chart of the 20 Quiz 2 scores: two students scored 4, four scored 5, three scored 6, three scored 7, two scored 8, three scored 9, and three scored 10, on a frequency axis from 0 to 5. The same mean of 7 is spread over a much wider range than on Quiz 1.], alt: "Bar chart of the 20 Quiz 2 scores: two students scored 4, four scored 5, three scored 6, three scored 7, two scored 8, three scored 9, and three scored 10, on a frequency axis from 0 to 5. The same mean of 7 is spread over a much wider range than on Quiz 1.", caption: none) The terms variability, spread, and dispersion are synonyms, and refer to how spread out a distribution is. Just as in the section on central tendency where we discussed measures of the center of a distribution of scores, in this chapter we will discuss measures of the variability of a distribution. There are four frequently used measures of variability: the range, interquartile range, variance, and standard deviation. In the next few paragraphs, we will look at each of these four measures of variability in more detail. Range #linebreak() The range is the simplest measure of variability to calculate, and one you have probably encountered many times in your life. The range is simply the highest score minus the lowest score. Let’s take a few examples. What is the range of the following group of numbers: 10, 2, 5, 6, 7, 3, 4? Well, the highest number is 10, and the lowest number is 2, so 10 - 2 = 8. The range is 8. Let’s take another example. Here’s a dataset with 10 numbers: 99, 45, 23, 67, 45, 91, 82, 78, 62, 51. What is the range? The highest number is 99 and the lowest number is 23, so 99 - 23 equals 76; the range is 76. Now consider the two quizzes shown in Figure 1. On Quiz 1, the lowest score is 5 and the highest score is 9. Therefore, the range is 4. The range on Quiz 2 was larger: the lowest score was 4 and the highest score was 10. Therefore the range is 6. === Interquartile Range The interquartile range (IQR) is the range of the middle 50% of the scores in a distribution. It is computed as follows: IQR = 75th percentile - 25th percentile For Quiz 1, the 75th percentile is 8 and the 25th percentile is 6. The interquartile range is therefore 2. For Quiz 2, which has greater spread, the 75th percentile is 9, the 25th percentile is 5, and the interquartile range is 4. Recall that in the discussion of box plots, the 75th percentile was called the upper hinge and the 25th percentile was called the lower hinge. Using this terminology, the interquartile range is referred to as the #strong[H-spread]. A related measure of variability is called the semi-interquartile range. The semi-interquartile range is defined simply as the interquartile range divided by 2. If a distribution is symmetric, the median plus or minus the semi-interquartile range contains half the scores in the distribution. === Variance Variability can also be defined in terms of how close the scores in the distribution are to the middle of the distribution. Using the mean as the measure of the middle of the distribution, the variance is defined as the average squared difference of the scores from the mean. The data from Quiz 1 are shown in Table 1. The mean score is 7.0. Therefore, the column "Deviation from Mean" contains the score minus 7. The column "Squared Deviation" is simply the previous column squared. Table 1. Calculation of Variance for Quiz 1 scores. #figure(table( columns: 3, align: left, inset: 6pt, [Scores], [Deviation from Mean], [Squared Deviation], [9], [2], [4], [9], [2], [4], [9], [2], [4], [8], [1], [1], [8], [1], [1], [8], [1], [1], [8], [1], [1], [7], [0], [0], [7], [0], [0], [7], [0], [0], [7], [0], [0], [7], [0], [0], [6], [-1], [1], [6], [-1], [1], [6], [-1], [1], [6], [-1], [1], [6], [-1], [1], [6], [-1], [1], [5], [-2], [4], [5], [-2], [4], [Means], [], [], [7], [0], [1.5], )) One thing that is important to notice is that the mean deviation from the mean is 0. This will always be the case. The mean of the squared deviations is 1.5. Therefore, the variance is 1.5. Analogous calculations with Quiz 2 show that its variance is 6.7. The formula for the variance is: #math.equation(block: true, alt: "σ squared equals the fraction ∑ open parenthesis X minus μ close parenthesis squared over N")[$σ^(2) = frac(∑ ( X − μ )^(2), N)$] where σ#super[2] is the variance, μ is the mean, and N is the number of numbers. For Quiz 1, μ = 7 and N = 20. If the variance in a sample is used to estimate the variance in a population, then the previous formula underestimates the variance and the following formula should be used: #math.equation(block: true, alt: "s squared equals the fraction ∑ open parenthesis X minus M close parenthesis squared over N minus 1")[$s^(2) = frac(∑ ( X − M )^(2), N − 1)$] where s#super[2] is the estimate of the variance and M is the sample mean. Note that M is the mean of a sample taken from a population with a mean of μ. Since, in practice, the variance is usually computed in a sample, this formula is most often used. The simulation "estimating variance" illustrates the bias in the formula with N in the denominator. Let's take a concrete example. Assume the scores 1, 2, 4, and 5 were sampled from a larger population. To estimate the variance in the population you would compute s#super[2] as follows: M = (1 + 2 + 4 + 5)/4 = 12/4 = 3. s#super[2] = \[(1-3)#super[2] + (2-3)#super[2] + (4-3)#super[2] + (5-3)#super[2]\]/(4-1) = (4 + 1 + 1 + 4)/3 = 10/3 = 3.333 There are alternate formulas that can be easier to use if you are doing your calculations with a hand calculator. You should note that these formulas are subject to rounding error if your values are very large and/or you have an extremely large number of observations. #math.equation(block: true, alt: "σ squared equals the fraction ∑ X squared minus the fraction open parenthesis ∑ X close parenthesis squared over N over N")[$σ^(2) = frac(∑ X^(2) − frac(( ∑ X )^(2), N), N)$] and #math.equation(block: true, alt: "s squared equals the fraction ∑ X squared minus the fraction open parenthesis ∑ X close parenthesis squared over N over N minus 1")[$s^(2) = frac(∑ X^(2) − frac(( ∑ X )^(2), N), N − 1)$] For this example, #figure(figph[Worked computation of the variance of the four scores 1, 2, 4, 5 using the computational formulas, shown in four lines: the sum of squares equals 1 squared plus 2 squared plus 4 squared plus 5 squared, which is 46; the squared sum over N equals (1 + 2 + 4 + 5) squared over 4, which is 144 over 4, which is 36; sigma squared equals (46 - 36) over 4, which is 2.5; and s squared equals (46 - 36) over 3, which is 3.333 — as with the other formula.], alt: "Worked computation of the variance of the four scores 1, 2, 4, 5 using the computational formulas, shown in four lines: the sum of squares equals 1 squared plus 2 squared plus 4 squared plus 5 squared, which is 46; the squared sum over N equals (1 + 2 + 4 + 5) squared over 4, which is 144 over 4, which is 36; sigma squared equals (46 - 36) over 4, which is 2.5; and s squared equals (46 - 36) over 3, which is 3.333 — as with the other formula.", caption: none) === Standard Deviation The standard deviation is simply the square root of the variance. This makes the standard deviations of the two quiz distributions 1.257 and 2.203. The standard deviation is an especially useful measure of variability when the distribution is normal or approximately normal (#link("https://onlinestatbook.com/2/normal_distribution/normal_distribution.html")[see Chapter on Normal Distributions]) because the proportion of the distribution within a given number of standard deviations from the mean can be calculated. For example, 68% of the distribution is within one standard deviation of the mean and approximately 95% of the distribution is within two standard deviations of the mean. Therefore, if you had a normal distribution with a mean of 50 and a standard deviation of 10, then 68% of the distribution would be between 50 - 10 = 40 and 50 +10 =60. Similarly, about 95% of the distribution would be between 50 - 2 x 10 = 30 and 50 + 2 x 10 = 70. The symbol for the population standard deviation is σ; the symbol for an estimate computed in a sample is s. Figure 2 shows two normal distributions. The red distribution has a mean of 40 and a standard deviation of 5; the blue distribution has a mean of 60 and a standard deviation of 10. For the red distribution, 68% of the distribution is between 35 and 45; for the blue distribution, 68% is between 50 and 70. #figure(figph[Two normal curves on a common axis from 0 to 100. The red curve is centered at 40 with a standard deviation of 5, so it is tall and narrow; the blue curve is centered at 60 with a standard deviation of 10, so it is lower and about twice as wide. The larger standard deviation shows directly as the flatter, more spread-out curve.], alt: "Two normal curves on a common axis from 0 to 100. The red curve is centered at 40 with a standard deviation of 5, so it is tall and narrow; the blue curve is centered at 60 with a standard deviation of 10, so it is lower and about twice as wide. The larger standard deviation shows directly as the flatter, more spread-out curve.", caption: [Figure 2. Normal distributions with standard deviations of 5 and 10.])