- Build and read frequency tables, bar charts, dotplots, stem-and-leaf plots, histograms, and boxplots.
- Describe the shape, center, spread, and unusual features of a distribution, in context.
- Compute and interpret the mean, median, mode, trimmed mean, and weighted mean, and say which is appropriate.
- Compute the range, IQR, variance, and standard deviation by hand, and explain why we divide by \(n-1\).
- Find quartiles and percentiles, apply the 1.5 IQR outlier rule, and compute z-scores.
- Predict how adding a constant or multiplying by a constant changes each summary.
- Summarize grouped data, measure skewness and kurtosis, and spot misleading graphs.
Describing categorical data
The first step with any dataset is simply to look at it. For a categorical variable that means counting how many observations fall in each category.
- The frequency of a category is the number of observations in it. The relative frequency is the frequency divided by the total \(n\) (often shown as a percentage).
- A frequency table lists each category with its frequency and relative frequency.
- The mode is the most frequent category.
Example 3.1: Frequency table and Pareto chart for commute modes
Forty students are asked how they usually get to campus.
| Mode | Frequency | Relative frequency | Cumulative % |
|---|---|---|---|
| Bus | 14 | 0.350 | 35.0% |
| Car | 9 | 0.225 | 57.5% |
| Walk | 8 | 0.200 | 77.5% |
| Bike | 5 | 0.125 | 90.0% |
| Train | 4 | 0.100 | 100.0% |
| Total | 40 | 1.000 |
The mode is Bus (35 percent). Relative frequencies sum to 1; always check this. A Pareto chart sorts the bars from tallest to shortest and adds the cumulative percentage line: here, the top three modes account for 77.5 percent of students.
Which graph for categorical data?
- Bar chart: the default. Bars start at zero, have equal widths, and gaps between them (categories are separate). Order bars by size for nominal data, by the natural order for ordinal data.
- Pie chart: shows parts of a whole, but humans compare angles poorly. Use only with a few slices that sum to a meaningful 100 percent. A sorted bar chart almost always communicates better. Avoid 3D pies entirely.
- Pareto chart: a sorted bar chart plus cumulative line; excellent for finding "the vital few" causes of defects or complaints.
Displaying numerical data
Dotplots and stem-and-leaf plots
For small datasets we can show every value. A dotplot puts a dot above each value on a number line. A stem-and-leaf plot splits each number into a stem (leading digits) and a leaf (last digit) and keeps the original values visible.
Example 3.2: Stem-and-leaf plot of exam scores
Twenty exam scores: 45, 52, 58, 61, 63, 65, 67, 68, 70, 71, 72, 74, 75, 77, 78, 80, 83, 85, 88, 94. Use the tens digit as the stem and the units digit as the leaf.
4 | 5 5 | 2 8 6 | 1 3 5 7 8 7 | 0 1 2 4 5 7 8 8 | 0 3 5 8 9 | 4 Key: 7 | 4 means 74
Reading the plot: the scores center in the low 70s, there is a slight tail toward the low scores (45), and there are no gaps. The plot doubles as a sideways histogram while preserving the exact data.
Histograms
For larger datasets, group the values into consecutive intervals called bins (or classes) and draw a bar for each whose height shows how many observations fall in the bin. There are no gaps between bars because the number line is continuous.
- Choose a bin width and a starting point so that bins do not overlap and every value falls in exactly one bin. By convention a value on a boundary belongs to the bin on its right (bins are \([a, b)\)).
- Count the observations in each bin (frequency), or divide by \(n\) (relative frequency).
- Draw adjacent bars. Label both axes.
Rules of thumb for the number of bins: Sturges' rule \(k \approx 1 + \log_2 n\) (good for small or moderate \(n\)), or the square-root rule \(k \approx \sqrt{n}\). Software often uses the Freedman-Diaconis bin width \(2 \cdot \text{IQR} \cdot n^{-1/3}\).
Too few bins hides structure; too many bins turns the histogram into noise. The same data can look bimodal or unimodal depending on bins. Always try more than one width before drawing conclusions. Use the lab below to see this for yourself.
Describing a distribution: SOCS
Whenever you describe a numerical distribution, cover four features, remembered as SOCS:
| Feature | What to say |
|---|---|
| Shape | Symmetric, skewed right (long tail to the high side), skewed left (long tail to the low side), unimodal (one peak), bimodal (two peaks, often two hidden groups), uniform (flat) |
| Outliers | Any values far from the rest, and possible reasons (data entry error? a genuinely different case?) |
| Center | A typical value: the mean or median |
| Spread | How much variation: standard deviation, IQR, or range |
"Skewed right with a median of 12 minutes and IQR of 9 minutes" is a description. "Waiting times at the clinic are mostly short (median 12 minutes) but a few patients wait very long, pulling the distribution to the right" is statistical communication. Always say what the numbers are about and use the units.
Cumulative frequency and the ogive
The cumulative relative frequency of a value \(x\) is the proportion of observations that are \(\le x\). Plotting it against the right end of each bin and joining the points gives an ogive. It lets you read percentiles directly: go up from the value, across to the axis. The steepest parts of the ogive correspond to the tallest bars of the histogram.
Measures of center
A measure of center answers "what is a typical value?". There are three classic answers, and they can disagree.
For the median: if \(n\) is odd it is the value in position \((n+1)/2\); if \(n\) is even it is the average of the values in positions \(n/2\) and \(n/2+1\).
| Mean | Median | Mode | |
|---|---|---|---|
| Idea | Balance point; "fair share" | Middle: half above, half below | Most common |
| Uses every value | Yes | No (only order) | No |
| Resistant to outliers | No | Yes | Yes |
| Works for | Numerical data | Numerical or ordinal data | Any data, including nominal |
| Best when | Roughly symmetric, no extreme outliers | Skewed data or outliers (incomes, house prices) | Categories; finding peaks |
A statistic is resistant if it is not much changed by a few extreme values. The median and the IQR are resistant. The mean, standard deviation, and range are not.
Example 3.3: How one outlier moves the mean but not the median
Monthly incomes (in thousand rupees) of eight people in a small firm: 42, 45, 48, 50, 52, 55, 58, 250 (the owner).
Mean \(= (42+45+48+50+52+55+58+250)/8 = 600/8 = 75.0\). Sorted data have \(n=8\), so the median is the average of the 4th and 5th values: \((50+52)/2 = 51\).
Mean \(= 350/7 = 50.0\). Median is the 4th value: \(50\).
One extreme value moved the mean from 50 to 75 (a 50 percent jump) but moved the median only from 50 to 51. Nobody in the firm except the owner earns anything near 75, so "the average income is 75" misleads. For skewed data like incomes, prices, and waiting times, report the median (and often both).
A 12.5 percent trimmed mean drops the lowest and highest 12.5 percent of the sorted values (one from each end here) and averages the rest: \((45+48+50+52+55+58)/6 = 51.33\).
Mean versus median tells you about skewness
- Roughly symmetric: mean \(\approx\) median.
- Skewed right (long right tail): mean \(>\) median, because the tail drags the mean up.
- Skewed left (long left tail): mean \(<\) median.
The weighted mean
When some values count more than others, use weights \(w_i\):
\[ \bar{x}_w = \frac{\sum w_i x_i}{\sum w_i}. \]Example 3.4: Grade point average as a weighted mean
A student earns 3.7 in a 4-credit course, 3.0 in a 3-credit course, 4.0 in a 3-credit course, and 2.7 in a 2-credit course. The credits are the weights.
\[ \text{GPA} = \frac{4(3.7) + 3(3.0) + 3(4.0) + 2(2.7)}{4+3+3+2} = \frac{14.8 + 9.0 + 12.0 + 5.4}{12} = \frac{41.2}{12} \approx 3.433. \]The unweighted mean of the four grades, \((3.7+3.0+4.0+2.7)/4 = 3.35\), would ignore that some courses count for more.
Going deeper: The mean minimizes squared distance; the median minimizes absolute distance
Define \(f(c) = \sum (x_i - c)^2\). Differentiating, \(f'(c) = -2\sum (x_i - c) = 0\) gives \(c = \bar{x}\), so the mean is the single number closest to all the data in the least-squares sense (and, equivalently, deviations from the mean sum to zero: \(\sum (x_i - \bar{x}) = 0\)). Now define \(g(c) = \sum |x_i - c|\). Moving \(c\) to the right increases \(g\) by the number of points to the left and decreases it by the number to the right, so the minimum is where half the points are on each side: the median. Squaring gives extreme values more influence, which is exactly why the mean is not resistant.
Measures of spread
Two classes can have the same mean exam score of 70, yet in one everyone scored between 65 and 75, and in the other scores ranged from 30 to 100. The mean cannot tell them apart. We need a measure of spread.
Range and interquartile range
The range is max minus min. It is easy but uses only two values and is destroyed by one outlier. The interquartile range is \(\text{IQR} = Q_3 - Q_1\), the width of the middle 50 percent of the data. It is resistant.
Variance and standard deviation
The idea: measure how far each value is from the mean (its deviation \(x_i - \bar{x}\)), then average the size of these deviations. Deviations always sum to zero, so we square them first.
Population versions divide by \(N\): \(\sigma^2 = \dfrac{\sum (x_i - \mu)^2}{N}\). The standard deviation has the same units as the data; the variance has squared units.
Example 3.5: Standard deviation by hand
Data: 4, 7, 5, 9, 10 (\(n = 5\)).
\(\bar{x} = (4+7+5+9+10)/5 = 35/5 = 7\).
| \(x_i\) | \(x_i - \bar{x}\) | \((x_i - \bar{x})^2\) |
|---|---|---|
| 4 | -3 | 9 |
| 7 | 0 | 0 |
| 5 | -2 | 4 |
| 9 | 2 | 4 |
| 10 | 3 | 9 |
| Sum | 0 | 26 |
\(s^2 = 26/(5-1) = 6.5\) and \(s = \sqrt{6.5} \approx 2.550\). (If these five values were an entire population, \(\sigma^2 = 26/5 = 5.2\) and \(\sigma \approx 2.280\).)
Interpretation: a typical value lies about 2.5 units from the mean of 7. Always interpret \(s\) in context and units.
Why divide by \(n-1\)?
The data are used twice: once to estimate the center (\(\bar{x}\)) and then to measure spread around that center. But \(\bar{x}\) is, by construction, the value closest to the data, so deviations from \(\bar{x}\) are slightly smaller than deviations from the unknown true mean \(\mu\). Dividing by \(n\) would therefore underestimate the variance on average. Dividing by \(n-1\) corrects this exactly. Another view: once we know \(\bar{x}\) and \(n-1\) of the deviations, the last deviation is forced (they sum to zero), so only \(n-1\) deviations are free. The number \(n-1\) is called the degrees of freedom, a phrase you will meet again and again.
Going deeper: Proof that \(s^2\) is unbiased for \(\sigma^2\)
Let \(X_1, \dots, X_n\) be independent with mean \(\mu\) and variance \(\sigma^2\). Write \(X_i - \mu = (X_i - \bar{X}) + (\bar{X} - \mu)\), square, and sum. The cross term vanishes because \(\sum (X_i - \bar{X}) = 0\):
\[ \sum (X_i - \mu)^2 = \sum (X_i - \bar{X})^2 + n(\bar{X} - \mu)^2. \]Take expectations. Each \(E(X_i - \mu)^2 = \sigma^2\), and \(E(\bar{X} - \mu)^2 = \operatorname{Var}(\bar{X}) = \sigma^2/n\):
\[ n\sigma^2 = E\Big[\sum (X_i - \bar{X})^2\Big] + n \cdot \frac{\sigma^2}{n} \quad\Longrightarrow\quad E\Big[\sum (X_i - \bar{X})^2\Big] = (n-1)\sigma^2. \]Therefore \(E\!\left[\dfrac{1}{n-1}\sum (X_i - \bar{X})^2\right] = \sigma^2\). Note that \(s\) itself is slightly biased low for \(\sigma\) (square roots are concave), but the bias is small and ignored in practice.
Other measures of spread
- Median absolute deviation (MAD): the median of \(|x_i - \text{median}|\). It is resistant. For 4, 7, 5, 9, 10 the median is 7, absolute deviations are 3, 0, 2, 2, 3, and the MAD is 2.
- Coefficient of variation: \(\text{CV} = s/\bar{x}\) (often in percent). It is unit-free, so you can compare the relative variability of quantities in different units (for example, heights in cm versus weights in kg). Use it only for ratio-scale data with a positive mean.
What does the standard deviation tell us?
For any distribution, Chebyshev's inequality guarantees that at least \(1 - 1/k^2\) of the data lie within \(k\) standard deviations of the mean (for \(k > 1\)): at least 75 percent within 2 SDs, and at least 88.9 percent within 3 SDs. For bell-shaped data the empirical rule is much tighter: about 68, 95, and 99.7 percent within 1, 2, and 3 SDs (Chapter 7).
Position: quartiles, percentiles, z-scores, and boxplots
Percentiles and quartiles
The \(p\)th percentile is a value with about \(p\) percent of the data at or below it. The quartiles are the 25th, 50th, and 75th percentiles: \(Q_1\), median, \(Q_3\).
There are at least nine published percentile definitions. Two you will meet most: (1) the interpolation method used by R, Excel's QUARTILE.INC, and this course's calculators, where \(Q_1\) sits at position \(1 + 0.25(n-1)\) in the sorted list, with linear interpolation between neighbors; (2) the median of halves method in many textbooks, where you split the sorted data at the median (leaving the median out when \(n\) is odd) and take the median of each half. They usually agree closely; on tiny datasets they can differ. In an exam, use the method your course specifies. The tool below shows both.
Example 3.6: Quartiles, IQR, and the 1.5 IQR rule with two methods
Data (\(n=11\)): 12, 15, 17, 18, 20, 21, 22, 25, 27, 30, 62. The median is the 6th value, 21.
\(Q_1\) is at position \(1 + 0.25 \times 10 = 3.5\): halfway between the 3rd (17) and 4th (18) values, so \(Q_1 = 17.5\). \(Q_3\) is at position \(1 + 0.75 \times 10 = 8.5\): halfway between the 8th (25) and 9th (27), so \(Q_3 = 26\). \(\text{IQR} = 26 - 17.5 = 8.5\).
Lower half (excluding the median): 12, 15, 17, 18, 20, with median 17. Upper half: 22, 25, 27, 30, 62, with median 27. So \(Q_1 = 17\), \(Q_3 = 27\), \(\text{IQR} = 10\).
Fences: \(Q_1 - 1.5\,\text{IQR} = 17.5 - 12.75 = 4.75\) and \(Q_3 + 1.5\,\text{IQR} = 26 + 12.75 = 38.75\). The value 62 is above 38.75, so it is flagged as an outlier. (Method 2 gives fences 2 and 42: same conclusion.)
The five-number summary (Method 1, excluding the outlier as the upper whisker): min 12, \(Q_1\) 17.5, median 21, \(Q_3\) 26, max 62.
The five-number summary and the boxplot
The five-number summary is the minimum, \(Q_1\), median, \(Q_3\), maximum. A boxplot draws it: a box from \(Q_1\) to \(Q_3\) with a line at the median, and whiskers. In a modified boxplot (the standard in software), the whiskers extend to the most extreme values that are still inside the fences, and any values outside the fences are plotted individually as outliers.
A value outside the fences is flagged as a potential outlier. Flagging is a prompt to investigate, not to delete: an outlier may be an error, or the most interesting observation in the dataset.
z-scores
A z-score says how many standard deviations a value is from the mean:
\[ z = \frac{x - \bar{x}}{s} \quad\text{(sample)}, \qquad z = \frac{x - \mu}{\sigma} \quad\text{(population)}. \]A z-score is unitless, so it lets us compare values from different distributions. Positive means above the mean, negative below. Values with \(|z| > 2\) are somewhat unusual and \(|z| > 3\) rarely happen in bell-shaped data.
Example 3.7: Who did better, relative to the class?
Ali scored 78 on a test with class mean 70 and SD 8. Sara scored 85 on a different test with class mean 78 and SD 10.
\[ z_{\text{Ali}} = \frac{78 - 70}{8} = 1.00, \qquad z_{\text{Sara}} = \frac{85 - 78}{10} = 0.70. \]Sara's raw score is higher, but relative to her class Ali did better: he is 1.0 SD above his class mean, she only 0.7 SD above hers.
Effects of changing units: linear transformations
What happens to summaries if every value is changed by \(y = a x + b\)? For example, converting temperatures from Celsius to Fahrenheit uses \(a = 1.8\) and \(b = 32\).
Adding a constant \(b\) shifts every measure of center and position but leaves every measure of spread unchanged. Multiplying by \(a\) scales both center and spread (spread by \(|a|\)).
Example 3.8: Celsius to Fahrenheit
Daily high temperatures in a city have mean \(20^\circ\)C and SD \(4^\circ\)C. In Fahrenheit, \(F = 1.8C + 32\):
\[ \bar{F} = 1.8(20) + 32 = 68^\circ\text{F}, \qquad s_F = 1.8(4) = 7.2^\circ\text{F}. \]The "+32" moves the mean but does not affect the SD, because shifting every value equally does not change how spread out they are.
\(z = (x - \bar{x})/s\) subtracts the mean (so the new mean is 0) and divides by \(s\) (so the new SD is 1). Every dataset converted to z-scores has mean 0 and standard deviation 1. This "standardizing" is why z-scores from different distributions are comparable.
Shape numerically, and grouped data
Skewness and kurtosis
The \(k\)th central moment is \(m_k = \frac{1}{n}\sum (x_i - \bar{x})^k\). The second moment is the (population-style) variance. Standardized higher moments describe shape:
\[ \text{skewness} = \frac{m_3}{m_2^{3/2}}, \qquad \text{excess kurtosis} = \frac{m_4}{m_2^{2}} - 3. \]- Skewness is 0 for symmetric data, positive for a long right tail, negative for a long left tail. As a rough guide, \(|\text{skewness}| > 1\) is strongly skewed.
- Excess kurtosis is 0 for the normal distribution. Positive means heavier tails and a sharper peak than normal (more extreme values); negative means lighter tails and a flatter shape.
- A quick rule from Karl Pearson: skewness \(\approx 3(\text{mean} - \text{median})/s\).
Software packages differ in small-sample correction factors, so exact values may differ slightly between programs. For the twenty exam scores in Example 3.2 the skewness is about \(-0.24\) (slightly left-skewed, matching the low-score tail) and the excess kurtosis about \(-0.22\) (a touch flatter than normal).
Grouped data
Sometimes we only have a frequency table, not the raw data. We can approximate summaries by pretending every value in a class sits at the class midpoint \(m_j\), with frequency \(f_j\) and total \(n = \sum f_j\):
\[ \bar{x} \approx \frac{\sum f_j m_j}{n}, \qquad s^2 \approx \frac{\sum f_j (m_j - \bar{x})^2}{n-1}. \]Example 3.9: Mean and standard deviation from a grouped table
Waiting times (minutes) of 30 patients:
| Class | Midpoint \(m\) | Frequency \(f\) | \(f \cdot m\) | \(f(m-\bar{x})^2\) |
|---|---|---|---|---|
| 0 to under 10 | 5 | 5 | 25 | 1,027.22 |
| 10 to under 20 | 15 | 12 | 180 | 225.33 |
| 20 to under 30 | 25 | 8 | 200 | 256.89 |
| 30 to under 40 | 35 | 5 | 175 | 1,227.22 |
| Total | 30 | 580 | 2,736.67 |
Mean \(\approx 580/30 = 19.33\) minutes (this is the value of \(\bar{x}\) used in the last column). Variance \(\approx 2736.67/29 = 94.37\), so \(s \approx 9.71\) minutes.
Grouping loses information, so these are approximations to the values you would get from the raw data.
Graphs that mislead
A good graph shows the data honestly. A misleading one can be created by accident or on purpose. Watch for:
- Truncated axes. A bar chart whose axis starts at 95 instead of 0 makes a 2 percent difference look like a 10-fold difference. Bars encode value by length, so they must start at zero. (Line charts may zoom, but should say so.)
- Distorted areas and volumes. Doubling both height and width of an icon quadruples its area; readers perceive the larger effect. Prefer bars to icons.
- Uneven bins or scales. Unequal class widths in a histogram without adjusting heights (use density) distort shape.
- Cherry-picked time windows. Starting a trend chart at a peak or a trough tells a different story than the full history.
- Dual axes that are scaled to make two unrelated series appear to move together.
- 3D effects, chart junk, and pie charts with many slices. Decoration reduces accuracy.
The statistician Edward Tufte defined the lie factor as the size of the effect shown in the graphic divided by the size of the effect in the data. An honest graph has a lie factor near 1.
Chapter summary
- Categorical: frequency, relative frequency, bar chart (start at zero), Pareto. Numerical: dotplot, stem-and-leaf, histogram (bin width matters), ogive.
- Describe distributions with SOCS: shape, outliers, center, spread, in context.
- Center: \(\bar{x}\) (not resistant), median (resistant), mode. Right skew: mean \(>\) median.
- Spread: range, IQR (resistant), \(s^2 = \sum(x_i-\bar{x})^2/(n-1)\), \(s\). MAD, CV.
- \(n-1\) corrects the bias from using \(\bar{x}\) in place of \(\mu\); it is the degrees of freedom.
- Outlier fences: \(Q_1 - 1.5\,\text{IQR}\) and \(Q_3 + 1.5\,\text{IQR}\). Five-number summary and boxplot.
- \(z = (x - \bar{x})/s\); compare across distributions. Chebyshev: at least \(1 - 1/k^2\) within \(k\) SDs.
- \(y = ax + b\): \(\bar{y} = a\bar{x} + b\), \(s_y = |a| s_x\).
- Skewness (sign shows tail direction), excess kurtosis (tail weight). Grouped data use midpoints.
- Bars must start at zero; check axes, scales, and time windows before trusting a graph.
Key terms
| Term | Meaning |
|---|---|
| Deviation | \(x_i - \bar{x}\), the signed distance from the mean |
| IQR | \(Q_3 - Q_1\), the spread of the middle half of the data |
| Outlier | A value far from the bulk of the data (commonly outside the 1.5 IQR fences) |
| Percentile | A value with a given percent of the data at or below it |
| Resistant | Not much affected by a few extreme values |
| Skewed | Asymmetric, with a longer tail on one side |
| Standard deviation | Typical distance of values from the mean, in the data's units |
| z-score | Number of SDs a value lies from the mean |