BACK Mascot image.
← FE0 1 · Introduction to Probability

Lesson 2

Summarising Data

The mean, median and mode; variance, standard deviation, Chebyshev's inequality, the empirical rule and quantiles; when the mean misleads; covariance and correlation; and the mean and variance of linear combinations, with portfolios as the main example.

Taught

Measures of Central Tendency

Suppose we collect nn pieces of data. We need some way of describing them, and we write them as

x1,x2,x3,,xn.x_1, x_2, x_3, \ldots, x_n .

Here x1x_1 is the first number and xnx_n the last, and nn is the number of numbers, the number of observations, also called the sample size. These are the values we observe. The letter xx is just a name for the set of numbers; we could just as easily use yy. If the data are 5,2,8,6,25, 2, 8, 6, 2, for example, then n=5n = 5, x1=5x_1 = 5 and x3=8x_3 = 8.

Sometimes the order of the observations means something. In the monthly returns of the last lesson the first observation corresponds to the first month. Sometimes it does not: in a survey each number corresponds to one respondent, and the list could be written in any order.

The Sample Mean

Definition 2.1 (Sample Mean).

The sample mean of x1,,xnx_1, \ldots, x_n is their average,

xˉ=sumn=x1+x2++xnn.\bar{x} = \frac{\text{sum}}{n} = \frac{x_1 + x_2 + \cdots + x_n}{n} .

The symbol xˉ\bar{x} is read ”xx bar”.

There is a more compact way to write the sum x1+x2++xnx_1 + x_2 + \cdots + x_n, called summation notation:

i=1nxi=x1+x2++xn.\sum_{i=1}^{n} x_i = x_1 + x_2 + \cdots + x_n .

It means that for each value of ii from 11 to nn we add to the sum the value indicated, in this case xix_i. Using it,

xˉ=1ni=1nxi.\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i .

For the data 5,2,8,6,25, 2, 8, 6, 2 the mean is xˉ=5+2+8+6+25=235=4.6\bar{x} = \dfrac{5 + 2 + 8 + 6 + 2}{5} = \dfrac{23}{5} = 4.6.

Example 2.2 (Summation notation).

Think of each row of this table as an observation on two variables. To make things concrete, each row is a year, and xx and yy are the annual returns on two different assets: in year 11 asset xx returned 7%7\%, and in year 44 asset yy returned 3%3\%.

year iixix_iyiy_i
110.070.070.110.11
220.060.060.050.05
330.040.040.090.09
440.030.030.030.03

The two means are

xˉ=0.07+0.06+0.04+0.034=0.204=0.05,yˉ=0.11+0.05+0.09+0.034=0.284=0.07.\bar{x} = \frac{0.07 + 0.06 + 0.04 + 0.03}{4} = \frac{0.20}{4} = 0.05, \qquad \bar{y} = \frac{0.11 + 0.05 + 0.09 + 0.03}{4} = \frac{0.28}{4} = 0.07 .

A sum need not run over all the observations. Here we sum only the second and third:

i=23xi=x2+x3=0.06+0.04=0.10.\sum_{i=2}^{3} x_i = x_2 + x_3 = 0.06 + 0.04 = 0.10 .

For each value of ii we can add in anything we want, such as the product of the two returns, or the distance of xix_i from its mean:

i=14xiyi=0.0077+0.0030+0.0036+0.0009=0.0152,i=14(xixˉ)=0.02+0.010.010.02=0.\sum_{i=1}^{4} x_i y_i = 0.0077 + 0.0030 + 0.0036 + 0.0009 = 0.0152, \qquad \sum_{i=1}^{4} (x_i - \bar{x}) = 0.02 + 0.01 - 0.01 - 0.02 = 0 .

We think of the mean as the centre of the data. In a class survey of how many beers students claim they can drink, one answer was deleted because nobody believed it. Among the rest, the women claimed on average that they could drink 4.24.2 beers and the men 7.97.9, so in this sense the men claim to drink more.

For the equity returns of the last lesson the means are

xˉCanada=0.00907,xˉJapan=0.00234.\bar{x}_{\text{Canada}} = 0.00907, \qquad \bar{x}_{\text{Japan}} = 0.00234 .

This is a big difference: about 0.9%0.9\% a month against about 0.2%0.2\%. It was hard to see in the histograms, because it is small compared with the variation of the returns.

Problem 2.1.

For the returns in the table above, compute i=14yi2\displaystyle\sum_{i=1}^{4} y_i^2, i=34(xi+yi)\displaystyle\sum_{i=3}^{4} (x_i + y_i) and i=14(yiyˉ)\displaystyle\sum_{i=1}^{4} (y_i - \bar{y}).

The Median

Definition 2.3 (Median).

After the data have been put in order, the median is the middle value. If there is an even number of observations, the median is the average of the two middle values.

So the median of 1,2,3,4,51, 2, 3, 4, 5 is 33, and the median of 1,1,2,3,4,51, 1, 2, 3, 4, 5 is 2+32=2.5\dfrac{2 + 3}{2} = 2.5.

Mean versus Median

The mean and the median are both good measures of the centre of a distribution, but the median is much less sensitive to extreme values. It depends only on which observations sit in the middle of the ordering, so making the largest value larger, or the smallest smaller, leaves it unchanged.

datameanmedian
1,2,3,4,51, 2, 3, 4, 53333
1,2,3,4,1001, 2, 3, 4, 100222233

Extreme values like the 100100 are the outliers of the last lesson. We used to call them funny points, but outliers sounds more scientific. Outliers are sometimes the most interesting aspect of a data set, and sometimes they are just coding errors.

Example 2.4 (A sex survey).

In the 2004 American Sex Survey, a random-sample telephone poll of 1,5011{,}501 adults, women reported a median of 33 sex partners in their lifetimes and men a median of 88. The means were far larger: an average of 66 partners for women and 2020 for men. The report explains that the averages are higher because a small number of individuals, especially men, report a very large number of partners. Whether those answers are true or boasts, a handful of them moves the mean a long way and the median hardly at all.

Source: ABC News, American Sex Survey

The Mode

Definition 2.5 (Mode).

The mode of a data set is the value that appears most frequently, the highest point of its histogram.

People also use the word more loosely, calling any lump in a histogram a mode.

Measures of Dispersion

The mean and the median locate the centre of a set of observations, for different notions of centre. They do not measure its dispersion, or spread. Are most of the observations close to the centre, or not? What is the typical range the data fall into? The data sets 5,5,5,5,55, 5, 5, 5, 5 and 1,3,5,8,81, 3, 5, 8, 8 both have mean 55, but the second is clearly the more variable.

Often we care about the variability as well as the centre.

  1. Medicine: we may know the average life expectancy given a diagnosis, but what are the best and the worst cases?
  2. Exams: we may know the class average and our own score, but how do we really compare with the rest of the class?
  3. Investments: we may know the historical average annual return of a stock or a mutual fund, but is a big loss possible? Beside the average return we need a measure of risk.

Example 2.6 (Daily temperatures in two cities).

Figure 2.1 shows the daily mean temperatures in Seattle and in Chicago over 2024 and 2025, drawn on the same scale. The means of the two cities are very close, 11.711.7 °C and 11.211.2 °C, but the distributions are very different: the temperature in Chicago is far more variable.

Source: Open-Meteo historical weather API, ERA5 reanalysis, daily mean temperature at 22 metres for Seattle and Chicago, 1 January 2024 to 31 December 2025, 731731 days each.

mean 11.7 °C−20−10010203001020304050daily mean temperature (°C)daysSeattlemean 11.2 °C−20−10010203001020304050daily mean temperature (°C)daysChicago
Figure 2.1. Daily mean temperatures in Seattle and Chicago, 2024–2025, in one-degree bins. The dashed lines mark the means.

Example 2.7 (Two share prices).

Figure 2.2 shows the daily closing prices of Tesla (TSLA) and Visa (V) shares over five years. Again the means are very close, $247.34 and $248.20, but the Tesla price is clearly more variable.

Source: Yahoo Finance daily closing prices, 1 September 2020 to 29 August 2025, 1,2551{,}255 trading days, adjusted for share splits.

mean 247.34 dollars100150200250300350400450050100150daily closing price (US dollars)daysTesla (TSLA)mean 248.20 dollars100150200250300350400450050100150daily closing price (US dollars)daysVisa (V)
Figure 2.2. Daily closing prices of Tesla and Visa shares, September 2020 to August 2025, in bins of ten dollars. The dashed lines mark the means.

Problem 2.2.

In both examples the two distributions have almost the same mean but very different spreads. Suggest a single number that could measure the spread of a set of data.

The Variance

The basic idea is to view variability in terms of the distance between each observation and the mean, xixˉx_i - \bar{x}. Figure 2.3 shows these distances for the two small sets of returns in the table above: overall, the distances for yy are bigger than those for xx.

xy0.0300.0450.0600.0750.0900.105
Figure 2.3. The four xx returns and the four yy returns on one scale. The vertical bars mark the means, and the horizontal bars run from each mean to the observations, so their lengths are the distances xixˉx_i - \bar{x} and yiyˉy_i - \bar{y}.

We need an overall measure of how big the distances are, one number as the mean is one number. We cannot just add the distances up, because the negative distances cancel the positive ones and the sum is always zero:

i=1n(xixˉ)=i=1nxinxˉ=nxˉnxˉ=0.\sum_{i=1}^{n} (x_i - \bar{x}) = \sum_{i=1}^{n} x_i - n\bar{x} = n\bar{x} - n\bar{x} = 0 .

Instead we square the distances, which makes them all positive, and average them.

Definition 2.8 (Variance).

The variance of x1,,xnx_1, \ldots, x_n is the average squared distance from the mean,

σx2=1ni=1n(xixˉ)2.\sigma_x^2 = \frac{1}{n}\sum_{i=1}^{n} (x_i - \bar{x})^2 .

Example 2.9 (The heights of a rowing crew).

The eight rowers of a crew are 182182, 185185, 188188, 190190, 191191, 193193, 195195 and 196196 cm tall (constructed data). Their mean height is xˉ=15208=190\bar{x} = \dfrac{1520}{8} = 190 cm, and

xix_i182182185185188188190190191191193193195195196196
xixˉx_i - \bar{x}8-85-52-20011335566
(xixˉ)2(x_i - \bar{x})^2646425254400119925253636

so the variance is

σx2=64+25+4+0+1+9+25+368=1648=20.5 cm2.\sigma_x^2 = \frac{64 + 25 + 4 + 0 + 1 + 9 + 25 + 36}{8} = \frac{164}{8} = 20.5\ \text{cm}^2 .

The heights are in centimetres, so the variance is in square centimetres.

The Sample Variance

Definition 2.10 (Sample Variance).

The sample variance of x1,,xnx_1, \ldots, x_n is

sx2=1n1i=1n(xixˉ)2.s_x^2 = \frac{1}{n - 1}\sum_{i=1}^{n} (x_i - \bar{x})^2 .

We use n1n - 1 instead of nn for technical reasons, to do with using a sample to estimate the variability of the population it came from, and the intuition does not change: we still think of sx2s_x^2 as the average squared distance of the observations from their mean. For large nn the two versions are almost equal. In this lesson σx2\sigma_x^2, with divisor nn, is called the variance and sx2s_x^2, with divisor n1n - 1, the sample variance. Statistical software usually reports the sample version.

Problem 2.3.

  1. What is the smallest value a variance can take, and for what data does it take it?
  2. What are the units of the variance of a set of heights measured in metres, and of a set of monthly returns?

The Standard Deviation

It is helpful to have a measure of spread in the original units of the data. If the data have units uu, the variance has units u2u^2, which cannot be compared with the data or with the mean. The standard deviation solves this problem.

Definition 2.11 (Standard Deviation).

The standard deviation is the square root of the variance, σx=σx2\sigma_x = \sqrt{\sigma_x^2}, and the sample standard deviation is the square root of the sample variance, sx=sx2s_x = \sqrt{s_x^2}. Both have the same units as the data.

So if we want a measure of variability that can be compared with the mean, we should use the standard deviation rather than the variance. For the rowers, σx=20.5=4.53\sigma_x = \sqrt{20.5} = 4.53 cm.

Example 2.12 (Two small sets of returns).

For the returns in the table of the last chapter, the distances from the means are

xixˉ=0.02, 0.01, 0.01, 0.02,yiyˉ=0.04, 0.02, 0.02, 0.04,x_i - \bar{x} = 0.02,\ 0.01,\ -0.01,\ -0.02, \qquad y_i - \bar{y} = 0.04,\ -0.02,\ 0.02,\ -0.04,

so

sx2=0.0004+0.0001+0.0001+0.00043=0.00103,sx=0.0183,sy2=0.0016+0.0004+0.0004+0.00163=0.00403,sy=0.0365.\begin{aligned} s_x^2 &= \frac{0.0004 + 0.0001 + 0.0001 + 0.0004}{3} = \frac{0.0010}{3}, & s_x &= 0.0183, \\ s_y^2 &= \frac{0.0016 + 0.0004 + 0.0004 + 0.0016}{3} = \frac{0.0040}{3}, & s_y &= 0.0365 . \end{aligned}

The sample standard deviation of the yy data is bigger than that of the xx data. This numerically captures the fact, visible in Figure 2.3, that yy has more variation about its mean than xx.

For the equity returns of the last lesson,

countrynnmeansample standard deviation
Canada1071070.009070.009070.038330.03833
Japan1071070.002340.002340.073680.07368

and the standard deviations measure the greater spread in the Japanese returns which the histograms showed.

We now have two numerical summaries of a set of data: xˉ\bar{x}, which says where the data are, and sxs_x, which says how spread out, how variable, they are. The mean is easy to interpret, as a sort of centre of the data. We know that the bigger sxs_x is, the more variable the data are, but how do we really interpret the number? What is a big sxs_x, and what is a small one?

Variability and Risk

Example 2.13 (A gift or a gamble).

Suppose someone offers a choice between a gift of $100 and the chance to flip a fair coin for $300. We can think of the outcomes in each case as the data points of a distribution. The first is a distribution with exactly one data point, $100. The second has two data points, $0 for tails and $300 for heads. For the coin flip, in dollars,

xˉ=0+3002=150,σx2=(0150)2+(300150)22=22,500,σx=150.\bar{x} = \frac{0 + 300}{2} = 150, \qquad \sigma_x^2 = \frac{(0 - 150)^2 + (300 - 150)^2}{2} = 22{,}500, \qquad \sigma_x = 150 .
choicemeanstandard deviation
gift$100$0
coin flip$150$150

The gamble has the larger mean, and a standard deviation as large as its mean, which measures its risk. Which to choose depends on how much that risk matters to us.

For the temperatures of Figure 2.1,

citymean temperaturestandard deviation
Seattle11.711.7 °C5.65.6 °C
Chicago11.211.2 °C10.710.7 °C

and the standard deviation of the temperature in Chicago is about twice that in Seattle. For the share prices of Figure 2.2,

sharemean pricestandard deviation
Tesla$247.34$66.78
Visa$248.20$47.37

The standard deviation of the Tesla price is about 27%27\% of its mean, and that of the Visa price about 19%19\%.

Remark.

The ratio of the standard deviation to the mean only makes sense as a measure of variability for data which cannot be negative. For data such as returns, which take both signs, the mean can be close to zero however large the spread.

The Standard Deviation and Outliers

Sometimes the standard deviation is large because of one outlier.

Example 2.14 (Attendance at tutorials).

The five tutorial groups of a course had these attendances one week (constructed data).

groupABCDE
attendance202066272725252121

The mean is xˉ=995=19.8\bar{x} = \dfrac{99}{5} = 19.8, and

σx2=0.22+13.82+7.22+5.22+1.225=270.85=54.16,σx=7.4.\sigma_x^2 = \frac{0.2^2 + 13.8^2 + 7.2^2 + 5.2^2 + 1.2^2}{5} = \frac{270.8}{5} = 54.16, \qquad \sigma_x = 7.4 .

If we remove the outlier, group B, the mean becomes 934=23.25\dfrac{93}{4} = 23.25 and

σx2=3.252+3.752+1.752+2.2524=32.754=8.19,σx=2.9.\sigma_x^2 = \frac{3.25^2 + 3.75^2 + 1.75^2 + 2.25^2}{4} = \frac{32.75}{4} = 8.19, \qquad \sigma_x = 2.9 .

One unusual group makes the standard deviation more than twice as large.

Problem 2.4.

Is the standard deviation a satisfying measure of variability? What is it conveying, and what is it not conveying?

Because it squares the distances, the standard deviation can be made large by the influence of a few outliers, so it can be a pessimistic notion of variability.

Chebyshev’s Inequality

There is a guarantee which says how most observations sit relative to the standard deviation. It is called Chebyshev’s inequality: for any k>1k > 1,

at most a fraction 1k2 of the observations are more than k standard deviations from the mean.\text{at most a fraction } \frac{1}{k^2} \text{ of the observations are more than } k \text{ standard deviations from the mean.}

Equivalently, at least a fraction 11k21 - \dfrac{1}{k^2} of them lie within kk standard deviations of the mean. With k=2k = 2, for example, at least 114=75%1 - \frac14 = 75\% of the observations are no more than two standard deviations from the mean, whatever the data.

The reason is short. Suppose that a fraction ff of the nn observations lie more than kσxk\sigma_x from the mean, and that there is at least one of them. Each of these fnfn observations contributes more than k2σx2k^2\sigma_x^2 to the sum of the squared distances, and no term of the sum is negative, so

nσx2=i=1n(xixˉ)2>fnk2σx2.n\sigma_x^2 = \sum_{i=1}^{n} (x_i - \bar{x})^2 > fn \cdot k^2\sigma_x^2 .

Dividing both sides by nk2σx2nk^2\sigma_x^2 gives f<1k2f < \dfrac{1}{k^2}. The sample standard deviation is at least as large as σx\sigma_x, so the guarantee holds for sxs_x as well.

The Standard Deviation Can Overestimate Variability

We know for sure that at least 75%75\% of the observations lie in the window xˉ±2σx\bar{x} \pm 2\sigma_x. Very often the truth is far better than that. In Figure 2.4 almost all the days in each city, about 97%97\%, are within two standard deviations of the mean, and about 64%64\% are within one standard deviation. In such cases the width of the window xˉ±2σx\bar{x} \pm 2\sigma_x gives, qualitatively, an overestimate of the variability.

−20−10010203001020304050daily mean temperature (°C)daysSeattle: 63.7% within one standard deviation, 97.7% within two−20−10010203001020304050daily mean temperature (°C)daysChicago: 64.0% within one standard deviation, 96.9% within two
Figure 2.4. The temperatures of Figure 2.1 with dotted lines one standard deviation either side of the mean and dashed lines two standard deviations either side.

The Empirical Rule

For data whose histogram is a single roughly symmetric mound, a much sharper statement is usually close to the truth.

Definition 2.15 (Empirical Rule).

For mound-shaped data,

  1. approximately 68%68\% of the data lie in the interval (xˉsx,xˉ+sx)=xˉ±sx(\bar{x} - s_x, \bar{x} + s_x) = \bar{x} \pm s_x;
  2. approximately 95%95\% of the data lie in the interval (xˉ2sx,xˉ+2sx)=xˉ±2sx(\bar{x} - 2s_x, \bar{x} + 2s_x) = \bar{x} \pm 2s_x.

The empirical rule helps us understand sxs_x and relate the two summaries back to the histogram. For the Canadian returns, xˉ=0.00907\bar{x} = 0.00907 and sx=0.03833s_x = 0.03833, so

xˉ±sx=(0.02926, 0.04740),xˉ±2sx=(0.06759, 0.08573).\bar{x} \pm s_x = (-0.02926,\ 0.04740), \qquad \bar{x} \pm 2s_x = (-0.06759,\ 0.08573) .

The empirical rule says that roughly 68%68\% of the observations are between the dotted lines of Figure 2.5 and roughly 95%95\% between the dashed lines. Counting, 6767 of the 107107 returns, 63%63\%, lie within one standard deviation of the mean and 103103, 96%96\%, lie within two. That looks reasonable.

x̄ − 2sx̄ + 2sx̄ − sx̄ + s−0.10−0.050.000.050.10051015monthly returncount
Figure 2.5. The Canadian monthly returns with the mean (solid), xˉ±sx\bar{x} \pm s_x (dotted) and xˉ±2sx\bar{x} \pm 2s_x (dashed).

The same thing can be seen from the time series plot in Figure 2.6. Five per cent of the 107107 observations outside the dashed lines would be about 55 points; there are 44 points outside, which is pretty close.

198919901991199219931994199519961997−0.10−0.050.000.050.10monthreturn
Figure 2.6. The Canadian monthly returns as a time series, with the mean and the lines xˉ±2sx\bar{x} \pm 2s_x. The four months outside are highlighted.

Remark.

Chebyshev’s inequality holds for any data at all; the empirical rule is only an approximation, and only for mound-shaped data. For the temperatures of Figure 2.4, whose histograms are not single symmetric mounds, the proportions within one and two standard deviations still happen to be close to 68%68\% and 95%95\%.

Quantiles

Quantiles tell us what fraction of the data falls in each range, which gives a more complete picture of variability.

Definition 2.16 (Quantiles).

The qq-quantiles of a set of data are the q1q - 1 numbers which divide the ordered data into qq groups of equal size. The 1010-quantiles are the deciles, the 44-quantiles the quartiles and the 100100-quantiles the percentiles. The median is the 22-quantile.

−20−100102030010203040Chicago daily mean temperature (°C)days
Figure 2.7. The deciles of Chicago’s daily temperatures. Each of the ten groups between neighbouring dashed lines, or beyond the outermost, contains a tenth of the days.

We can measure variability by the distance between two quantiles, the width of the window they make. For example, the distance from the 1010th percentile to the 9090th:

citymeanstandard deviation1010th percentile9090th percentile10109090 window
Seattle11.711.7 °C5.65.6 °C4.74.7 °C19.419.4 °C14.714.7 °C
Chicago11.211.2 °C10.710.7 °C2.5-2.5 °C24.024.0 °C26.526.5 °C

The quantiles tell us exactly what percentage of the data fall in a range. Here 80%80\% of the days fall between the 1010th and 9090th percentiles, because 10%10\% of the days lie below the 1010th percentile and 10%10\% above the 9090th. So in each city we can reasonably expect the temperature to be in the window on 80%80\% of days, and the width of the window is a measure of the variability. The quantiles also give us a better sense of the shape of the distribution, because they show where the data are packed tightly and where they are thin.

Remark.

When the 10%10\% point falls between two observations, different books and programs choose the percentile slightly differently, for instance by taking one of the two neighbours or by interpolating between them. For large data sets the choice makes little difference; the percentiles here are interpolated.

Problem 2.5.

How does the information we get from the standard deviation differ from the information we get from the quantiles?

Comparing Assets

We can use means and standard deviations to compare investments. For nine mutual funds and other assets, over the same 180180 months, the means and sample standard deviations of the monthly returns are these.

assetnnmeanstandard deviation
drefus1801800.006770.006770.047240.04724
fidel1801800.004700.004700.056590.05659
keystne1801800.006540.006540.084240.08424
Putnminc1801800.005520.005520.030080.03008
scudinc1801800.004430.004430.035970.03597
windsor1801800.010020.010020.048640.04864
eqmrkt1801800.010820.010820.068560.06856
valmrkt1801800.006810.006810.048000.04800
tbill1801800.005980.005980.002520.00252

Plotting the means against the standard deviations puts all nine on one picture, Figure 2.8. It is considered good to have a large mean return and a small standard deviation, so the best assets are towards the top left. Treasury bills have almost no variability, and keystne has the largest standard deviation without a larger mean to show for it.

drefusfidelkeystnePutnmincscudincwindsoreqmrktvalmrkttbill0.000.020.040.060.080.0040.0060.0080.010standard deviation of monthly returnmean monthly return
Figure 2.8. Mean monthly return against standard deviation for nine assets.

The same picture compares countries, here from the monthly returns of 19881988 to 19961996.

AustraliaBelgiumCanadaFinlandFranceGermanyHong KongItalyJapanUSASingapore0.030.040.050.060.070.080.0000.0050.0100.0150.020standard deviation of monthly returnmean monthly return
Figure 2.9. Mean monthly return against standard deviation for eleven countries, February 1988 to December 1996.

When the Mean Misleads

The Mean Is Often Good

The mean is one proxy for the centre of a distribution, and it is common to treat the centre as the typical value. In some cases this is reasonable.

Example 2.17 (Repeated experiments).

We carry out nn independent experiments to measure the value of a fixed, bounded quantity μ\mu, such as

  1. the average concentration of microplastics in the London water supply;
  2. the plasticity of a protein;
  3. the fraction of students who think a hot dog is a sandwich.

Because of natural variation and measurement error, each experiment gives a possibly noisy measurement of μ\mu. In such an experiment the mean of the measurements is likely to be very close to μ\mu, as long as nn is large enough; this is the law of large numbers.

But many kinds of data we meet are not like this. The features of a data set which can throw off the mean as a measure of the typical value are

  1. multimodal data;
  2. skewed and heavy-tailed distributions;
  3. outliers;
  4. high variability.

Multimodal Data

A common intuition is that the mean is roughly where the mode is. In some cases, like the repeated experiments, this is true. But sometimes a data set is naturally multimodal.

Example 2.18 (The body mass of penguins).

The top histogram of Figure 2.10 shows the body masses of 342342 penguins of three species recorded near Palmer Station in Antarctica. There are two lumps. Many data sets like this one can be decomposed into natural subsets: here the Adélie and Chinstrap penguins, 219219 birds with mean mass 3,7113{,}711 g, and the Gentoo penguins, 123123 birds with mean mass 5,0765{,}076 g. Within each subset there is only one mode, and within the subset the mean and the mode match.

Source: Palmer Station penguin data, Gorman, Williams and Fraser (2014), in the palmerpenguins data set; the 342342 penguins with body mass and bill measurements recorded.

3,0003,5004,0004,5005,0005,5006,0006,50001020body mass (g)penguinsall 342 penguinsAdélie and Chinstrap, mean 3,711 gGentoo, mean 5,076 g3,0003,5004,0004,5005,0005,5006,0006,50001020body mass (g)penguinsGentoo penguins highlighted
Figure 2.10. The body masses of 342342 penguins in bins of 100100 g, first all together and then with the Gentoo penguins highlighted.

In a multimodal data set the mean of the whole data set lies between the means of the different modes, and then it is not representative of a typical observation. The mean mass of all 342342 penguins is 4,2024{,}202 g, which is heavier than 85%85\% of the Adélie and Chinstrap penguins and lighter than 95%95\% of the Gentoos: a typical penguin of neither kind.

The same happens when we split the penguins by sex, in Figure 2.11. The mean for the entire data set is on the large end for a female, heavier than 68%68\% of the females, and on the small end for a male, lighter than 55%55\% of the males.

mean of all penguins 4,202 gfemale mean 3,862 g3,0003,5004,0004,5005,0005,5006,0006,500051015body mass (g)penguinsfemale penguinsmean of all penguins 4,202 gmale mean 4,546 g3,0003,5004,0004,5005,0005,5006,0006,500051015body mass (g)penguinsmale penguins
Figure 2.11. Body masses of the female and male penguins on the same scale, with the mean of all penguins and the mean of each sex.

Problem 2.6.

  1. Should the median of a multimodal data set be influenced by the multiple modes?
  2. Should its quantiles?
  3. Should its standard deviation?

All three are influenced, in the sense that the median, quantiles and standard deviation of the aggregate data do not reflect what is going on within the separate modes.

Why It Matters

Many times the mean and other summary statistics are used to make decisions. When the decisions are based on statistics of all the data, instead of mode by mode, they might not be the right decisions for everyone.

Example 2.19 (The duration of symptoms).

A medical researcher at a hospital records how long 100100 patients experience the symptoms of a new disease (constructed data). The average duration is 2020 days, and the histogram at the top of Figure 2.12 does not look obviously multimodal. But suppose the researcher analyses separately the 6060 patients without hypertension and the 4040 with it. The average duration is 1414 days for the patients without hypertension and 2929 days for those with it. Advice built on 2020 days would ask most patients without hypertension to wait too long, and tell most patients with hypertension to expect their symptoms to end too soon.

mean 20 days05101520253035404502468duration of symptoms (days)patientsall 100 patientsno hypertension, mean 14hypertension, mean 2905101520253035404502468duration of symptoms (days)patientspatients with hypertension highlighted
Figure 2.12. The durations of symptoms of 100100 patients, first all together and then with the patients who have hypertension highlighted.

Problem 2.7.

Cheng et al. study the time from exposure to the onset of COVID-19 symptoms. Could such data be multimodal? Suppose recommendations for how long to isolate after close contact are based on the distribution of this time. In what sense is that problematic, and what trade-offs have to be made?

Misleading Means in the Media

The American Medical Association reports that the average American consumes about 3,4003{,}400 milligrams of sodium a day, against a recommended limit of 2,3002{,}300 milligrams.

Problem 2.8.

Is the figure of 3,4003{,}400 mg representative of most people? Could the data be multimodal? Is there a lot of variability?

A closer look comes from a national study which estimated sodium intake from 2424-hour urine samples. It found a mean of 4,2054{,}205 mg a day for men and 3,0393{,}039 mg for women, and that on a given day 75.1%75.1\% of adults, 83.5%83.5\% of men and 67.1%67.1\% of women, consumed at least the recommended 2,3002{,}300 mg. So

  1. the data are multimodal: men and women consume quite different amounts on average;
  2. the variability is limited, in the sense that three adults in four are above the recommended amount.

The conclusion that Americans eat more salt than the medical community suggests they should is still valid, but a single figure of 3,4003{,}400 mg describes neither men nor women well.

Source: American Medical Association, What doctors wish patients knew about sodium consumption; Cogswell et al., Estimated 24-hour urinary sodium and potassium excretion in US adults, JAMA (2018).

Skew

Even when a distribution has only one mode, it can be skewed: its histogram stretches out to the left or to the right. There are several quantitative measures of skewness, and only the concept matters here. The stretched-out part looks like a tail, so a skewed distribution is sometimes also said to be heavy-tailed.

Right Skew

Types of data which tend to be skewed to the right are

  1. incomes, GDP, the number of awards won, and views or clicks online, where the rich get richer;
  2. waiting times, such as the time between earthquakes or volcanic eruptions;
  3. the sizes of some natural objects, such as lakes, rocks and mineral deposits.

If a distribution is skewed to the right, then typically the median and the mode are smaller than the mean.

Example 2.20 (GDP).

In 2000 the 204204 countries with a recorded GDP had a mean GDP of $164.7 billion and a median of only $7.9 billion. A few enormous economies pull the mean far to the right of where almost every country lies, as Figure 2.13 shows.

Source: World Bank, GDP (current US$), indicator NY.GDP.MKTP.CD, individual countries only.

median 7.9 bnmean 164.7 bn7 countries above 1,000 bn not shown02004006008001,0000255075100125GDP in 2000 (billions of US dollars)countries
Figure 2.13. GDP of the countries of the world in 2000, in bins of 2525 billion dollars, with the median and the mean.

Left Skew

Types of data which tend to be skewed to the left are the age at death and exam scores. If a distribution is skewed to the left, then typically the median and the mode are larger than the mean.

Example 2.21 (Exam scores).

The 4040 scores of a class on an exam (constructed data) pile up between 8080 and 100100, with a tail of weaker scripts down to 3838. The mean is 80.380.3 and the median is 84.584.5.

mean 80.3median 84.540506070809010002468exam scorestudents
Figure 2.14. Forty exam scores in bins of five marks, with the mean and the median.

Measuring Skew

The gap between the mean and the median is one quantitative measure of skew. It is positive for the GDP data, which are skewed to the right, and negative for the exam scores, which are skewed to the left.

Outliers

Outliers, abnormally large or small values, can move the mean away from the median or the mode. Outliers and skew are related, since outliers do skew the distribution; the distinction is usually that we think of outliers as anomalies, whereas skew can be a natural property of the data.

Example 2.22 (Time on social media).

A class survey asked “How many minutes per day do you spend on social media?” (constructed data). Twenty students answered between 1010 and 240240 minutes, and one replied 1818 hours, that is 1,0801{,}080 minutes. This is an outlier.

statisticwith the outlierwithout the outlier
mean125.5125.5 min77.877.8 min
standard deviation220.7220.7 min57.657.6 min
median6060 min6060 min

The standard deviations use divisor nn. The one answer moves the mean by nearly 5050 minutes and multiplies the standard deviation by almost four, and it does not move the median at all.

18 hours01202403604806007208409601,0800246minutes per day on social mediastudents
Figure 2.15. Twenty-one answers for time spent on social media, in half-hour bins, with the outlier highlighted.

The tutorial attendances earlier showed the same effect of an outlier on the standard deviation.

High Variability

If the variability of a data set is high, then neither the mean nor the median is representative of a typical observation.

Example 2.23 (Hours of study).

A survey asked 3030 students “How many hours per week do you spend studying?” (constructed data). The mean, 14.514.5 hours, and the median, 1212 hours, are pretty close. But the answers run from 11 to 3030 hours with a standard deviation of 8.58.5 hours, so neither 14.514.5 nor 1212 can be taken as the answer of a typical student.

mean 14.5median 1204812162024283201234hours of study per weekstudents
Figure 2.16. Thirty answers for hours of study per week, in two-hour bins, with the mean and the median.

Gambling gives another situation where the mean is not necessarily representative. When we flip a fair coin for $300, the mean outcome is $150, but the outcome is either $0 or $300, and neither is anything like the mean.

A Robust Measure of Variability

If the standard deviation is so easily inflated by outliers and heavy tails, what should we use instead? Quantile widths are much more robust to outliers. In the social media survey, the window from the 1010th to the 9090th percentile is 133.5133.5 minutes wide without the outlier and 160160 minutes wide with it, while the standard deviation jumps from 57.657.6 to 220.7220.7 minutes.

Relating Two Variables

The mean and the standard deviation summarise a set of numbers which are measurements of just one thing, one variable. A different question is how one thing relates to another. Often each observation contains measurements of several variables:

  1. medical records: age, weight, blood pressure;
  2. property sales: price, floor area;
  3. the penguins: flipper length, body mass, bill length.

We often want to know whether two variables are positively or negatively associated. When we examine two variables at a time, the scatter plot is the main graphical tool, and covariance and correlation are the main numerical summaries.

Scatter Plots

Example 2.24 (Beer and weight).

In the class survey of how many beers students claim they can drink, each student also gave their weight in pounds. The first ten answers are these.

student ii1122334455667788991010
beers12121212555577131344121212121212
weight192192160160155155120120150150175175100100165165165165150150

Now we think of each pair of numbers as an observation. Each pair corresponds to a person, with two numbers associated with them, the number of beers and the weight, and each pair corresponds to a point on the plot. Is the number of beers you can drink related to your weight?

100120140160180200051015weight (pounds)number of beers
Figure 2.17. Claimed number of beers against weight for the ten students in the table.

In general the data look like nn pairs, and the iith observation is a pair of numbers (xi,yi)(x_i, y_i). The plot enables us to see the relationship between xx and yy. As another example, we could plot the monthly returns on the windsor mutual fund against the returns on the market as a whole, valmrkt, with each point a month, to ask whether the returns on a fund are related to the market’s.

In both examples there does seem to be a relationship. Even more, the relationship looks linear, in that we could draw a line through the plot to capture the pattern. Covariance and correlation summarise how strong a linear relationship there is between two variables.

Covariance and Correlation

Definition 2.25 (Sample Covariance and Sample Correlation).

The sample covariance between xx and yy is

sxy=1n1i=1n(xixˉ)(yiyˉ).s_{xy} = \frac{1}{n - 1}\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y}) .

The sample correlation between xx and yy is the covariance divided by the two standard deviations,

rxy=sxysxsy.r_{xy} = \frac{s_{xy}}{s_x s_y} .

The correlation is always a number between 1-1 and 11:

1rxy1.-1 \leqslant r_{xy} \leqslant 1 .
  1. The closer rr is to 11, the stronger the linear relationship with a positive slope: when one variable goes up, the other tends to go up.
  2. The closer rr is to 1-1, the stronger the linear relationship with a negative slope: when one goes up, the other tends to go down.

The correlation between windsor and valmrkt is 0.9230.923, and over the whole beer survey the correlation between the number of beers and weight is 0.6920.692 (for the ten students in the table alone it is 0.790.79). The larger correlation between windsor and valmrkt indicates that their linear relationship is the stronger one. Figure 2.18 shows some more examples.

r = 1.000r = −1.000r = 0.049r = 0.790r = −0.983r = −0.127
Figure 2.18. Six constructed scatter plots of 100100 points with their correlations. The last is a parabola, y=12x2y = \frac12 x^2.

The last plot is a warning. The correlation only measures linear relationships: here its value is small, but there is a strong nonlinear relationship between xx and yy.

Example 2.26 (The country data).

Which countries’ markets go up and down together? With many countries that would be a lot of scatter plots. Figure 2.19 shows one of them, the USA against Canada, with correlation 0.6510.651.

To summarise all of them we compute every pairwise correlation.

AusBelCanFinFraGerHKItaJapUSA
Belgium0.1890.189
Canada0.5070.5070.3570.357
Finland0.3870.3870.1830.1830.3860.386
France0.2750.2750.7340.7340.3420.3420.1760.176
Germany0.2260.2260.6910.6910.3020.3020.3040.3040.7090.709
Hong Kong0.3340.3340.3010.3010.5580.5580.3550.3550.3590.3590.3390.339
Italy0.1590.1590.3670.3670.3340.3340.3890.3890.3520.3520.4650.4650.2610.261
Japan0.2510.2510.4180.4180.2710.2710.3070.3070.4210.4210.3180.3180.2190.2190.4260.426
USA0.3600.3600.4290.4290.6510.6510.2640.2640.5010.5010.3720.3720.4290.4290.2400.2400.2460.246
Singapore0.4090.4090.3550.3550.4780.4780.3910.3910.4080.4080.4670.4670.6470.6470.4160.4160.4070.4070.4730.473

The upper half of the table is left blank because the correlation between two countries does not depend on the order in which we take them, so it would repeat the lower half, and the diagonal would only record that each country is perfectly correlated with itself. The most closely linked markets are neighbours: Belgium and France, France and Germany, Canada and the USA, Hong Kong and Singapore.

−0.10−0.050.000.050.10−0.10−0.050.000.050.10Canada monthly returnUSA monthly return
Figure 2.19. Monthly returns of the USA against those of Canada, February 1988 to December 1996.

Understanding the Formulae

To get a feeling for how these formulae capture a relationship, we go back to the four years of returns on two assets and compute their covariance and correlation. First the covariance, which is the necessary ingredient:

sxy=13[(0.070.05)(0.110.07)+(0.060.05)(0.050.07)+(0.040.05)(0.090.07)+(0.030.05)(0.030.07)]=13[(0.02)(0.04)+(0.01)(0.02)+(0.01)(0.02)+(0.02)(0.04)]=13[0.00080.00020.0002+0.0008]=0.00123=0.0004.\begin{aligned} s_{xy} &= \frac{1}{3}\bigl[(0.07 - 0.05)(0.11 - 0.07) + (0.06 - 0.05)(0.05 - 0.07) + (0.04 - 0.05)(0.09 - 0.07) + (0.03 - 0.05)(0.03 - 0.07)\bigr] \\ &= \frac{1}{3}\bigl[(0.02)(0.04) + (0.01)(-0.02) + (-0.01)(0.02) + (-0.02)(-0.04)\bigr] \\ &= \frac{1}{3}\bigl[0.0008 - 0.0002 - 0.0002 + 0.0008\bigr] = \frac{0.0012}{3} = 0.0004 . \end{aligned}

Each of the four points makes a contribution to the sum. Figure 2.20 shows which point does what.

(x₁, y₁): +0.0008(x₂, y₂): −0.0002(x₃, y₃): −0.0002(x₄, y₄): +0.0008IIIIIIIV0.030.040.050.060.070.030.050.070.090.11xy
Figure 2.20. The four points with dashed lines at xˉ=0.05\bar{x} = 0.05 and yˉ=0.07\bar{y} = 0.07, and each point’s contribution (xixˉ)(yiyˉ)(x_i - \bar{x})(y_i - \bar{y}).
  1. A point in region I has both xx and yy bigger than their means, so it makes a positive contribution to the covariance.
  2. A point in region II has both xx and yy less than their means, so it also makes a positive contribution.
  3. In regions III and IV one of xx and yy is less than its mean and the other is greater, so the contribution is negative.

The further out the point is, the bigger its contribution. A scatter plot with most of its points in regions I and II, and just a few relatively small contributions from regions III and IV, has a positive covariance. So

  1. a positive covariance means that when one variable is above its average the other tends to be above its average as well: they move up and down together;
  2. a negative covariance means that when one is up the other tends to be down: they move in opposite directions;
  3. a small covariance means that their movements are almost linearly unrelated.

We finish the example with the correlation, using sx=0.0183s_x = 0.0183 and sy=0.0365s_y = 0.0365 from before:

rxy=0.0004(0.0183)(0.0365)=0.60.r_{xy} = \frac{0.0004}{(0.0183)(0.0365)} = 0.60 .

The division by the standard deviations standardises the covariance, so that the correlation is always between 1-1 and 11. The correlation has the same sign as the covariance, since standard deviations are always positive, so its sign carries the same information: a positive sign means a positive relationship and a negative sign a negative one. The correlation is more informative, though, because it is unit-less and always between 1-1 and 11 by construction, which makes it the better measure of the strength of the relationship.

The Slope of the Best-Fit Line

Should the body mass of a penguin be positively or negatively associated with its bill length? Figure 2.21 suggests a positive association: heavier penguins tend to have longer bills. How can we quantify it? One idea is the slope of the best-fit line through the scatter plot, but the slope has two problems.

The slope is sensitive to units. With body mass in grams the slope of the best-fit line is 0.004050.00405 mm per gram. If we measure the same penguins in ounces, the points and the line look exactly the same, but the slope becomes 0.1150.115 mm per ounce. An ounce is 28.3528.35 grams, so the same rise in bill length now happens over a run 28.3528.35 times smaller in number, and the slope is 28.3528.35 times larger.

3,0004,5006,000354555body mass (g)bill length (mm)grams: slope 0.00405 mm per g100150200354555body mass (oz)bill length (mm)ounces: slope 0.115 mm per oz
Figure 2.21. Bill length against body mass for 342342 penguins with the best-fit line, with mass in grams and then in ounces.

The slope is also sensitive to variability. Some variables vary much less than others, and then the slope can never be large. Bill length varies only from 32.132.1 to 59.659.6 mm, while body mass varies from 2,7002{,}700 to 6,3006{,}300 g.

Problem 2.9.

  1. What is the slope of the line through the points (3000,40)(3000, 40) and (6000,50)(6000, 50)?
  2. Explain why, if a variable xx varies in the range 2,7002{,}700 to 6,3006{,}300 and a variable yy varies in the range 3232 to 6060, the slope of the best-fit line of yy on xx will never get close to 11.

When we meet a number we always want to put it in context. What can we compare it with? Can we transform it so that it is easier to compare? In the last lesson we transformed counts into percentages to make them easier to compare, and instead of the dollars lost to fraud we looked at the percentage of the budget lost to fraud. Here we set up a measure of association which is easy to compare across different kinds of data, by rescaling the data so that they are unitless and have the same variability.

Standardising

Definition 2.27 (Standardised Data).

To standardise the data x1,,xnx_1, \ldots, x_n, subtract the mean xˉ\bar{x} from every observation and divide by the standard deviation σx\sigma_x. The standardised data are z1,,znz_1, \ldots, z_n, where

zi=xixˉσx.z_i = \frac{x_i - \bar{x}}{\sigma_x} .

Problem 2.10.

Explain why standardised data always have mean 00 and standard deviation 11, and why they are unitless.

So standardising equalises the variability: if we want to find an association between two data sets and standardise both first, both have the same standard deviation.

The Correlation Coefficient

Our data contain pairs (xi,yi)(x_i, y_i), and we want to measure the association between xx and yy. The correlation coefficient is the slope of the best-fit line through the standardised xx and yy data, and it can be computed as the average product of the standardised values:

r=1ni=1nxixˉσxyiyˉσy.r = \frac{1}{n}\sum_{i=1}^{n} \frac{x_i - \bar{x}}{\sigma_x} \cdot \frac{y_i - \bar{y}}{\sigma_y} .

This is the same number as the sample correlation rxy=sxysxsyr_{xy} = \dfrac{s_{xy}}{s_x s_y}. The sum is 1n(xixˉ)(yiyˉ)\dfrac{1}{n}\sum (x_i - \bar{x})(y_i - \bar{y}) divided by σxσy\sigma_x\sigma_y. Using divisor n1n - 1 throughout, in the covariance and in both standard deviations, multiplies the top by nn1\dfrac{n}{n - 1} and the bottom by nn1nn1=nn1\sqrt{\dfrac{n}{n - 1}}\sqrt{\dfrac{n}{n - 1}} = \dfrac{n}{n - 1} as well, so the factors cancel.

For the penguins, with xx the body mass and yy the bill length, the association is positive but not perfect: r=0.595r = 0.595.

−2−10123−2−10123standardised body massstandardised bill length
Figure 2.22. Standardised bill length against standardised body mass for the 342342 penguins. The best-fit line through the origin has slope r=0.595r = 0.595.

Remark.

The quantity 1ni=1n(xixˉ)(yiyˉ)\dfrac{1}{n}\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y}), the covariance with divisor nn, is sometimes itself called the correlation. It is the correlation coefficient without the rescaling by the standard deviations.

What Correlation Can Tell Us

Covariance, correlation and the correlation coefficient are summary statistics of two variables which quantify the association between them.

  1. If there is a strong association between two variables, knowing one helps a lot in predicting the other. The correlation between body mass and bill length, for instance, lets us estimate the average bill length of penguins of a given weight.
  2. When there is a weak association, information about one variable does not help much in guessing the other.

The correlation coefficient has three useful properties.

  1. It is unitless.
  2. Changing the units of xx or of yy, as from grams to ounces, does not change it.
  3. It does not change if we interchange xx and yy: like the covariance, it is symmetric in the two variables.

Correlation Is Not Causation

If xx and yy are correlated, can we infer that xx causes yy, or that yy causes xx? No. Many variables are correlated without any causal relationship between them. For the years 20002000 to 20092009 the divorce rate in the US state of Maine and the consumption of margarine per person in the US have a correlation coefficient of 0.9930.993. Both fell over the decade, for quite unrelated reasons.

Source: Tyler Vigen, Spurious Correlations

Robustness

Like the mean and the standard deviation, the correlation can be greatly affected by outliers.

Example 2.28 (GDP in 1960 and 2000).

For the 111111 countries with a GDP recorded in both 19601960 and 20002000, the correlation between the two is 0.9330.933. But the data are dominated by a few very large economies: 9494 of the 111111 countries, 85%85\% of them, had a GDP below the 19601960 mean. For those 9494 countries alone the correlation is only 0.6740.674.

Source: World Bank, GDP (current US$), individual countries with values for both years.

020040060005,00010,000GDP 1960 (US dollars, bn)GDP 2000 (US dollars, bn)all 111 countries: r = 0.93305100200400600GDP 1960 (US dollars, bn)GDP 2000 (US dollars, bn)94 below the 1960 mean: r = 0.674
Figure 2.23. GDP in 2000 against GDP in 1960, for all 111111 countries and for the 9494 countries below the 1960 mean. The scales of the two plots are different.

Associations Not Captured by Correlation

Variables can be associated without being linearly associated. In the last plot of Figure 2.18, yy is a quadratic function of xx, so knowing xx tells us yy exactly, yet the correlation coefficient is only 0.127-0.127.

Simpson’s Paradox

Sometimes, if a data set has several groups or modes, the slope of the best-fit line for the whole data set differs from the slope for each group, even in sign. This phenomenon is called Simpson’s paradox.

Example 2.29 (The bills of penguins).

The length and depth of the penguins’ bills appear negatively associated when we look at all three species together: the correlation is 0.235-0.235. But when we look at each species separately, the two are clearly positively associated, with correlations 0.3910.391 for the Adélie, 0.6540.654 for the Chinstrap and 0.6430.643 for the Gentoo penguins. The Gentoos have long, shallow bills and the Adélies short, deep ones, and that difference between the species produces the downward slope of the combined data.

354555141720bill length (mm)bill depth (mm)all penguins: r = −0.235AdélieChinstrapGentoo354555141720bill length (mm)bill depth (mm)each species separately
Figure 2.24. Bill depth against bill length for the 342342 penguins, all together and then species by species, each with its best-fit line.

Linearly Related Variables

We have studied data sets which display some kind of relationship with each other, such as the returns on a mutual fund and on the market. Sometimes there is an exact linear relationship between two variables,

y=c0+c1x.y = c_0 + c_1 x .

Can we then say something about the mean of yy if all we know is the mean of xx, and something about the standard deviation of yy if all we know is the standard deviation of xx?

Example 2.30 (Celsius and Fahrenheit).

These temperatures are recorded in degrees Celsius and in degrees Fahrenheit, which are related by F=32+95CF = 32 + \frac95 C.

Celsius10101515202025254040303050507070
Fahrenheit50505959686877771041048686122122158158

If we plot the Fahrenheit values against the Celsius values, every point lies on one straight line, and the correlation is exactly 11.

Definition 2.31 (Linear Function).

The variable yy is a linear function of the variable xx if

y=c0+c1x,y = c_0 + c_1 x,

where the constants c0c_0 and c1c_1 are fixed numbers, the intercept and the slope, while xx and yy vary.

Example 2.32 (A film star's pay).

A film star has a deal which pays a fee of $10 million per film plus 10%10\% of the film’s gross takings. In millions of dollars the star’s income from a film is

income=10+0.1×gross,\text{income} = 10 + 0.1 \times \text{gross},

a linear function of the gross, with intercept 1010 and slope 0.10.1.

Mean and Standard Deviation of a Linear Function

Suppose the data yy are a linear function of the data xx. To see how the mean and standard deviation of yy are related to those of xx, take eight Celsius temperatures, multiply them by 95\frac95, and then add 3232 to obtain Fahrenheit.

meansample standard deviation
Celsius10-100010101515202025253030353515.62515.62515.2215.22
×95\times \frac9518-180018182727363645455454636328.12528.12527.4027.40
Fahrenheit1414323250505959686877778686959560.12560.12527.4027.40
celmulfahr−20020406080100
Figure 2.25. The eight Celsius temperatures, the same values multiplied by 95\frac95, and the Fahrenheit temperatures, on one scale.
  1. When we multiply by 95\frac95 we increase both the mean and the standard deviation proportionally: 15.625×95=28.12515.625 \times \frac95 = 28.125 and 15.22×95=27.4015.22 \times \frac95 = 27.40.
  2. When we add a constant, 3232 here, we simply increase the mean by the value of the constant and leave the dispersion unaffected.

In general, if yi=c0+c1xiy_i = c_0 + c_1 x_i for every ii, then

yˉ=c0+c1xˉ,sy=c1sx,sy2=c12sx2.\bar{y} = c_0 + c_1\bar{x}, \qquad s_y = |c_1|\, s_x, \qquad s_y^2 = c_1^2 s_x^2 .

We see this by averaging, yˉ=1ni=1n(c0+c1xi)=c0+c1xˉ\bar{y} = \dfrac{1}{n}\sum_{i=1}^{n} (c_0 + c_1 x_i) = c_0 + c_1\bar{x}, which gives yiyˉ=c1(xixˉ)y_i - \bar{y} = c_1(x_i - \bar{x}). Squaring, (yiyˉ)2=c12(xixˉ)2(y_i - \bar{y})^2 = c_1^2(x_i - \bar{x})^2, and summing and dividing by n1n - 1 gives sy2=c12sx2s_y^2 = c_1^2 s_x^2.

Problem 2.11.

  1. The film star makes 1010 films, and the mean and standard deviation of the gross takings of the films are 100100 and 3030 million dollars. What are the mean and the standard deviation of the star’s income per film?
  2. The data xx have mean 100100 and standard deviation 1010. What are the mean, standard deviation and variance of y=2xy = -2x, of y=5+xy = 5 + x and of y=52xy = 5 - 2x?

Linear Combinations

We may want a variable to be related to several others instead of just one. Suppose the film star also receives 5%5\% of all sales of the soundtrack album released with the film. In millions of dollars, the star’s income is then related to the film’s gross and to the album’s sales by

income=10+0.1×gross+0.05×album sales.\text{income} = 10 + 0.1 \times \text{gross} + 0.05 \times \text{album sales} .

Definition 2.33 (Linear Combination).

A variable yy is a linear combination of the variables x1,x2,,xkx_1, x_2, \ldots, x_k if

y=c0+c1x1+c2x2++ckxky = c_0 + c_1 x_1 + c_2 x_2 + \cdots + c_k x_k

for constants c0,c1,,ckc_0, c_1, \ldots, c_k. The constant cic_i is the coefficient of xix_i.

Portfolios

The most important example of a linear combination is a portfolio.

Example 2.34 (Splitting an investment).

Suppose we have $100 to invest in two assets. Let x1x_1 be the return on asset 11: if x1=0.1x_1 = 0.1 and we put all our money into asset 11, we have $110 at the end of the period. Let x2x_2 be the return on asset 22: if x2=0.15x_2 = 0.15 and we put all our money into asset 22, we have $115. Suppose instead we put half the money into each. At the end of the period we have, in dollars,

100×0.5×(1+0.1)+100×0.5×(1+0.15)=100(1+0.5×0.1+0.5×0.15)=100(1+0.125),100 \times 0.5 \times (1 + 0.1) + 100 \times 0.5 \times (1 + 0.15) = 100\,(1 + 0.5 \times 0.1 + 0.5 \times 0.15) = 100\,(1 + 0.125),

so the return on the split investment is 0.5×0.1+0.5×0.15=0.1250.5 \times 0.1 + 0.5 \times 0.15 = 0.125.

To generalise, let w1w_1 be the fraction of our wealth invested in asset 11, w2w_2 the fraction invested in asset 22, and MM our wealth. The ww‘s are called the portfolio weights, and w1+w2=1w_1 + w_2 = 1. At the end of the period we have

w1M(1+x1)+w2M(1+x2)=M(w1+w2+w1x1+w2x2)=M(1+w1x1+w2x2),w_1 M(1 + x_1) + w_2 M(1 + x_2) = M(w_1 + w_2 + w_1 x_1 + w_2 x_2) = M(1 + w_1 x_1 + w_2 x_2),

so the return on the portfolio is

Rp=w1x1+w2x2.R_p = w_1 x_1 + w_2 x_2 .

The return on the portfolio is a linear combination of the asset returns, whose coefficients are the portfolio weights. In the same way, if we have mm assets, the return on the iith is xix_i, and we put a fraction wiw_i of our wealth into asset ii, then the portfolio is determined by its weights and its return is

Rp=w1x1+w2x2++wmxm=i=1mwixi.R_p = w_1 x_1 + w_2 x_2 + \cdots + w_m x_m = \sum_{i=1}^{m} w_i x_i .

The portfolio weights always add up to one: if we invest 30%30\% of our wealth in asset 11 and have only two assets, we must invest 70%70\% in asset 22.

Problem 2.12.

  1. Can the portfolio weights add up to one with some of them negative? What does it mean to invest 30%-30\% of our wealth in asset 11 and 130%130\% in asset 22?
  2. What is the equally weighted portfolio of mm assets?
  3. What is a value-weighted portfolio?

Example 2.35 (The country data again).

Suppose we had put half our money into the USA and half into Hong Kong. For each month the portfolio return is 12×Hong Kong+12×USA\frac12 \times \text{Hong Kong} + \frac12 \times \text{USA}. The first five months are these.

monthHong KongUSAportfolio
February 19880.020.020.040.040.0300.030
March 19880.060.060.03-0.030.0150.015
April 19880.020.020.010.010.0150.015
May 19880.03-0.030.010.010.010-0.010
June 19880.080.080.050.050.0650.065

How do the returns on this portfolio compare with those of Hong Kong and the USA? In Figure 2.26 the mean of the portfolio is right in between the means of the USA and Hong Kong. Its standard deviation, however, is closer to the USA’s than halfway.

Hong KongUSA½ Hong Kong + ½ USA0.030.040.050.060.070.01200.01450.01700.01950.0220standard deviationmean
Figure 2.26. Mean against standard deviation of monthly return for Hong Kong, the USA and the half-and-half portfolio.

A portfolio can also use three countries. Suppose we go short on Canada, that is we borrow Canadian shares worth half our wealth and sell them, and invest in the other two:

Rp=12×Canada+1×USA+12×Hong Kong.R_p = -\tfrac12 \times \text{Canada} + 1 \times \text{USA} + \tfrac12 \times \text{Hong Kong} .

The weights add up to 11. This portfolio has a mean monthly return of 0.01940.0194, above the USA’s and close to Hong Kong’s 0.02100.0210, with a standard deviation of 0.04700.0470, far below Hong Kong’s 0.07220.0722. Forming portfolios is clearly an interesting thing to do.

Hong KongUSACanada−½ Canada + USA + ½ Hong Kong0.030.040.050.060.070.00600.01050.01500.01950.0240standard deviationmean
Figure 2.27. Mean against standard deviation for Hong Kong, the USA, Canada and the portfolio short in Canada.

Why would we form portfolios? Perhaps a portfolio has a nicer mean and variance, a nicer average return and a nicer risk, than the assets it is made of. Some basic formulae relate the mean and standard deviation of a linear combination to the means, variances and covariances of its inputs, and applying them to portfolios shows how the mean and variance of a portfolio depend on the assets in it. These formulae are the basic part of the tool-kit of anyone working in finance.

Mean and Variance of a Linear Combination

First we consider the case of only two inputs. If yi=c0+c1x1i+c2x2iy_i = c_0 + c_1 x_{1i} + c_2 x_{2i} for every observation ii, then

yˉ=c0+c1xˉ1+c2xˉ2,sy2=c12sx12+c22sx22+2c1c2sx1x2.\bar{y} = c_0 + c_1\bar{x}_1 + c_2\bar{x}_2, \qquad s_y^2 = c_1^2 s_{x_1}^2 + c_2^2 s_{x_2}^2 + 2c_1 c_2 s_{x_1x_2} .

We see this as for a single input. Averaging gives the formula for yˉ\bar{y}, and then

yiyˉ=c1(x1ixˉ1)+c2(x2ixˉ2).y_i - \bar{y} = c_1(x_{1i} - \bar{x}_1) + c_2(x_{2i} - \bar{x}_2) .

Squaring,

(yiyˉ)2=c12(x1ixˉ1)2+c22(x2ixˉ2)2+2c1c2(x1ixˉ1)(x2ixˉ2),(y_i - \bar{y})^2 = c_1^2(x_{1i} - \bar{x}_1)^2 + c_2^2(x_{2i} - \bar{x}_2)^2 + 2c_1 c_2(x_{1i} - \bar{x}_1)(x_{2i} - \bar{x}_2),

and summing over ii and dividing by n1n - 1 gives the formula for sy2s_y^2. The covariance term is what makes the variance of a combination more than the combination of the variances.

Problem 2.13.

Going back to the film star, suppose the average sales of the album are $5 million with a standard deviation of $1 million, and that the correlation between a film’s gross and its album sales is 0.80.8.

  1. What are the mean and the standard deviation of the star’s income?
  2. How would the answer change if the correlation were 00?

Example 2.36 (Checking the formulae on the country data).

For the portfolio 12×Hong Kong+12×USA\frac12 \times \text{Hong Kong} + \frac12 \times \text{USA}, the mean returns on the USA and Hong Kong are 0.013460.01346 and 0.021030.02103. Knowing the portfolio returns, the sample mean of the portfolio return is 0.017240.01724, and the formula agrees:

0.5×0.01346+0.5×0.02103=0.01724.0.5 \times 0.01346 + 0.5 \times 0.02103 = 0.01724 .

The sample variances and covariances of the three series are these.

Hong KongUSAportfolio
Hong Kong0.005214970.00521497
USA0.001030370.001030370.001107740.00110774
portfolio0.003122670.003122670.001069060.001069060.002095860.00209586

The diagonal elements are variances and the off-diagonal elements are covariances; a table like this is a variance–covariance matrix. As before we can check the formula for the variance:

(0.5)2(0.00521497)+(0.5)2(0.00110774)+2(0.5)(0.5)(0.00103037)=0.00130374+0.00027694+0.00051519=0.00209587,(0.5)^2(0.00521497) + (0.5)^2(0.00110774) + 2(0.5)(0.5)(0.00103037) = 0.00130374 + 0.00027694 + 0.00051519 = 0.00209587,

which is the variance of the portfolio up to rounding.

Let us do it one more time, for the portfolio 14×USA+34×Hong Kong\frac14 \times \text{USA} + \frac34 \times \text{Hong Kong}, whose sample variance is 0.003389050.00338905:

(0.25)2(0.00110774)+(0.75)2(0.00521497)+2(0.25)(0.75)(0.00103037)=0.00006923+0.00293342+0.00038639=0.00338904.(0.25)^2(0.00110774) + (0.75)^2(0.00521497) + 2(0.25)(0.75)(0.00103037) = 0.00006923 + 0.00293342 + 0.00038639 = 0.00338904 .

Example 2.37 (The effect of the covariance).

Each plot of Figure 2.28 shows 2020 constructed pairs (x1,x2)(x_1, x_2), and in each case y=0.5x1+0.5x2y = 0.5x_1 + 0.5x_2.

  1. In the first plot sx12=1.334636s_{x_1}^2 = 1.334636, sx22=1.106238s_{x_2}^2 = 1.106238 and sx1x2=1.208679s_{x_1x_2} = -1.208679, so sy2=0.25(1.334636)+0.25(1.106238)+0.5(1.208679)=0.005879s_y^2 = 0.25(1.334636) + 0.25(1.106238) + 0.5(-1.208679) = 0.005879. The variance of yy is much smaller than those of the xx‘s, because the covariance is large and negative: whenever x1x_1 is above its mean x2x_2 tends to be below its mean by about as much, and the average hardly moves.
  2. In the second, sx12=1.158167s_{x_1}^2 = 1.158167, sx22=0.960946s_{x_2}^2 = 0.960946 and sx1x2=1.046490s_{x_1x_2} = 1.046490, so sy2=0.289542+0.240237+0.523245=1.053024s_y^2 = 0.289542 + 0.240237 + 0.523245 = 1.053024. The variance of yy is not much smaller than those of the xx‘s, because the two move up and down together and averaging cancels almost nothing.
  3. In the third, sx12=1.387054s_{x_1}^2 = 1.387054, sx22=0.824789s_{x_2}^2 = 0.824789 and sx1x2=0.197619s_{x_1x_2} = 0.197619, so sy2=0.346764+0.206197+0.098810=0.651771s_y^2 = 0.346764 + 0.206197 + 0.098810 = 0.651771. The covariance is small, and the variance of yy is noticeably smaller than those of the xx‘s: averaging two variables which are nearly unrelated reduces the variability.
variance of y: 0.0059variance of y: 1.0530variance of y: 0.6518
Figure 2.28. Three sets of 2020 pairs (x1,x2)(x_1, x_2) with dashed lines at the means, and the variance of y=0.5x1+0.5x2y = 0.5x_1 + 0.5x_2 for each.

With kk inputs, if y=c0+c1x1+c2x2++ckxky = c_0 + c_1 x_1 + c_2 x_2 + \cdots + c_k x_k, the same argument gives yˉ=c0+c1xˉ1++ckxˉk\bar{y} = c_0 + c_1\bar{x}_1 + \cdots + c_k\bar{x}_k and

sy2=i=1kci2sxi2+2i<jcicjsxixj,s_y^2 = \sum_{i=1}^{k} c_i^2 s_{x_i}^2 + 2\sum_{i < j} c_i c_j s_{x_ix_j},

where the second sum runs over all pairs of inputs. For three inputs this is

sy2=c12sx12+c22sx22+c32sx32+2c1c2sx1x2+2c1c3sx1x3+2c2c3sx2x3.s_y^2 = c_1^2 s_{x_1}^2 + c_2^2 s_{x_2}^2 + c_3^2 s_{x_3}^2 + 2c_1 c_2 s_{x_1x_2} + 2c_1 c_3 s_{x_1x_3} + 2c_2 c_3 s_{x_2x_3} .

Example 2.38 (A portfolio of three funds).

Take the portfolio 0.1×fidel+0.4×eqmrkt+0.5×windsor0.1 \times \text{fidel} + 0.4 \times \text{eqmrkt} + 0.5 \times \text{windsor}. The sample variances and covariances of the four series are these.

portfoliofideleqmrktwindsor
portfolio0.003067600.00306760
fidel0.002802240.002802240.003202100.00320210
eqmrkt0.003693840.003693840.003191500.003191500.004700210.00470021
windsor0.002619670.002619670.002410870.002410870.002989220.002989220.002365800.00236580

The formula for three inputs gives

sy2=(0.1)2(0.00320210)+(0.4)2(0.00470021)+(0.5)2(0.00236580)+2[(0.1)(0.4)(0.00319150)+(0.1)(0.5)(0.00241087)+(0.4)(0.5)(0.00298922)]=0.00003202+0.00075203+0.00059145+2[0.00012766+0.00012054+0.00059784]=0.00137550+0.00169209=0.00306760,\begin{aligned} s_y^2 &= (0.1)^2(0.00320210) + (0.4)^2(0.00470021) + (0.5)^2(0.00236580) \\ &\qquad + 2\bigl[(0.1)(0.4)(0.00319150) + (0.1)(0.5)(0.00241087) + (0.4)(0.5)(0.00298922)\bigr] \\ &= 0.00003202 + 0.00075203 + 0.00059145 + 2\bigl[0.00012766 + 0.00012054 + 0.00059784\bigr] \\ &= 0.00137550 + 0.00169209 = 0.00306760, \end{aligned}

which is exactly the variance of the portfolio.

Exercises

Exercise 2.1.

The first five monthly returns of Hong Kong and the USA were 0.02,0.06,0.02,0.03,0.080.02, 0.06, 0.02, -0.03, 0.08 and 0.04,0.03,0.01,0.01,0.050.04, -0.03, 0.01, 0.01, 0.05.

  1. Compute by hand the mean and the sample variance of each series, and their sample covariance.
  2. Use the formulae for a linear combination to find the mean and the sample variance of the portfolio 12×Hong Kong+12×USA\frac12 \times \text{Hong Kong} + \frac12 \times \text{USA} over these five months.
  3. Check your answers against the portfolio returns 0.030,0.015,0.015,0.010,0.0650.030, 0.015, 0.015, -0.010, 0.065.

Exercise 2.2.

Of the 107107 monthly Japanese returns, 2626 lie more than one standard deviation from the mean, 77 lie more than two standard deviations from it, and one lies more than three.

  1. What proportions lie within one, two and three standard deviations of the mean?
  2. Compare these proportions with what Chebyshev’s inequality guarantees and with what the empirical rule predicts.

Exercise 2.3.

In the American Sex Survey, men reported a median of 88 lifetime partners and a mean of 2020, and women a median of 33 and a mean of 66.

  1. What do these figures suggest about the shape of each distribution?
  2. Which of the two summaries better describes a typical respondent, and why?
  3. A newspaper headline reads “The average man has had 20 partners”. What is misleading about it?

Exercise 2.4.

Seattle’s daily mean temperatures over 2024 and 2025 have mean 11.6911.69 °C and standard deviation 5.635.63 °C, with 1010th and 9090th percentiles 4.74.7 °C and 19.419.4 °C. Using F=32+95CF = 32 + \frac95 C, find the mean, the standard deviation and the 10109090 percentile window in degrees Fahrenheit, and explain why the correlation between the Seattle and Chicago temperatures would not change if both were converted to Fahrenheit.

Exercise 2.5.

Over the 107107 months, the Canadian and USA monthly returns have means 0.009070.00907 and 0.013460.01346, standard deviations 0.038330.03833 and 0.033280.03328, and correlation 0.6510.651. Find the mean and the standard deviation of the portfolio 12×Canada+12×USA\frac12 \times \text{Canada} + \frac12 \times \text{USA}, and compare them with those of the two countries.

Exercise 2.6.

The five pairs (x,y)(x, y) are (1,2)(1, 2), (2,4)(2, 4), (3,5)(3, 5), (4,4)(4, 4) and (5,7)(5, 7).

  1. Compute by hand the sample covariance and the correlation between xx and yy.
  2. Find the sample covariance and the correlation between u=3xu = 3x and v=y+10v = y + 10.

Exercise 2.7.

Show that if vi=a+byiv_i = a + b y_i for every ii, with b0b \neq 0, then the correlation between xx and vv equals the correlation between xx and yy when b>0b > 0, and is its negative when b<0b < 0.

Exercise 2.8.

Chicago’s daily mean temperatures over 2024 and 2025 have mean 11.2111.21 °C and standard deviation 10.6610.66 °C, and 99.7%99.7\% of the days lie within three standard deviations of the mean.

  1. What proportion does Chebyshev’s inequality guarantee within three standard deviations?
  2. Find the interval of temperatures within three standard deviations of the mean.
  3. The coldest day was 21.1-21.1 °C. Was it inside the interval?

Check Yourself

 

Fresh questions on the whole lesson — none of them is worked out above. Do each on paper first; the box only tells you whether you got there.

Answers are checked in your browser, as often as you like. Nothing is sent anywhere and nothing is kept but your own work. A formula may be written with the symbols themselves or with ~ & | -> <-> ^, and \and, \or, \to expand as you type.

Exercise 2.9.

What is the mean of 3,7,8,10,123, 7, 8, 10, 12?

answer one of these

Exercise 2.10.

What is the median of 2,9,4,7,1,82, 9, 4, 7, 1, 8?

answer one of these

Exercise 2.11.

What is the sample variance of 2,4,62, 4, 6?

answer one of these

Exercise 2.12.

Masses are recorded in kilograms. In what units is their variance?

answer one of these

Exercise 2.13.

If 55 is added to every observation, what happens to the mean and the standard deviation?

answer one of these

Exercise 2.14.

The data xx have standard deviation 55. What is the standard deviation of y=32xy = 3 - 2x?

answer one of these

Exercise 2.15.

By Chebyshev’s inequality, at most what fraction of any data set lies more than three standard deviations from the mean?

answer one of these

Exercise 2.16.

For mound-shaped data, about what percentage of the observations lie within two standard deviations of the mean?

answer one of these

Exercise 2.17.

What is the correlation between xx and yy for the pairs (1,3)(1, 3), (2,5)(2, 5), (3,7)(3, 7)?

answer one of these

Exercise 2.18.

A distribution is strongly skewed to the right. Which is usually true?

answer one of these

Exercise 2.19.

Two assets have mean returns 0.010.01 and 0.030.03. What is the mean return of the portfolio with weights 0.250.25 and 0.750.75?

answer one of these

Exercise 2.20.

The variables x1x_1 and x2x_2 have sample variances 44 and 99 and sample covariance 00. What is the sample variance of x1+x2x_1 + x_2?

answer one of these

Exercise 2.21.

The correlation between body mass in grams and bill length in millimetres is 0.5950.595. What is the correlation between body mass in kilograms and bill length in centimetres?

answer one of these

Exercise 2.22.

What fraction of a data set lies between its 1010th and 9090th percentiles?

answer one of these