Solar Panels on a School Roof, with Pearson's r Found from the Summary Sums
A school records, on 10 days, the hours of sunshine x and the electricity y kWh generated by the solar panels on its roof. The results give ∑ x = 60, ∑ y = 150, ∑ x2 = 400, ∑ y2 = 2340 and ∑ xy = 951. (a) Find Sxx, Syy and Sxy. (b) Calculate Pearson's product-moment correlation coefficient, and describe the correlation.
Pearson's r measures how closely the points lie to a straight line. It is built from three sums: Sxx and Syy measure the spread of each variable about its own mean, and Sxy measures how the two vary together.
- Measure the squares about the mean by subtracting (∑ x)2n: Sxx = ∑ x2 − (∑ x)2n = 400 − 60210 = 400 − 360 = 40.
- In the same way, Syy = 2340 − 150210 = 2340 − 2250 = 90 and Sxy = ∑ xy − ∑ x ∑ yn = 951 − 60 × 15010 = 951 − 900 = 51.
- (a) Sxx = 40, Syy = 90 and Sxy = 51.
- Divide Sxy by the square root of the product of the other two: r = Sxy√Sxx Syy = 51√40 × 90 = 51√3600 = 5160 = 0.850.
- (b) r = 0.850 is positive and close to 1, so there is strong positive linear correlation: on sunnier days the panels generate more electricity. Check: r lies between −1 and 1, as every correlation coefficient must.
answer(a) Sxx = 40, Syy = 90, Sxy = 51; (b) r = 0.850, strong positive linear correlation
techniquePearson’s Correlation Coefficient
Common pitfalls
- Putting the raw sums into the formula, 951√400 × 2340 = 0.983. The sums must first be measured about the means, which is what subtracting (∑ x)2n and ∑ x ∑ yn does.
- Confusing (∑ x)2 with ∑ x2. (∑ x)2 = 602 = 3600 is the square of the total, while ∑ x2 = 400 is the total of the squares.
Tomato Plants Under Grow Lamps, Tested by Two Researchers with Different Alternative Hypotheses
For 10 tomato plants grown under lamps, the hours of light each day x and the mass of tomatoes picked y kg give Sxx = 50, Syy = 72 and Sxy = 36. Before the trial, Researcher A predicted that more light gives more fruit. Researcher B wanted to know only whether the two are correlated. Assume the data come from a bivariate normal distribution. (a) Calculate r, and state each researcher's hypotheses. (b) Carry out each researcher's test at the 5% level, using the critical values for n = 10: 0.5494 for a one-tailed test and 0.6319 for a two-tailed test.
The test asks whether a sample correlation this large could easily come from a population with no correlation at all. The critical value depends on the sample size, on the level and on whether the alternative hypothesis names one direction or both.
- Pearson's correlation coefficient is r = Sxy√Sxx Syy = 36√50 × 72 = 36√3600 = 3660 = 0.600.
- (a) Let ρ be the correlation coefficient of the whole population of plants. Researcher A: H0: ρ = 0 and H1: ρ > 0, a one-tailed test. Researcher B: H0: ρ = 0 and H1: ρ ≠ 0, a two-tailed test.
- (b) For A, the whole 5% is in the upper tail, so the critical value is 0.5494. Since 0.600 > 0.5494, reject H0: there is evidence at the 5% level of positive correlation between the hours of light and the mass of tomatoes.
- For B, the 5% is split between the two tails, so the critical value is 0.6319. Since 0.600 < 0.6319, do not reject H0: there is not enough evidence at the 5% level that the two are correlated.
- The same r gives two conclusions because A's prediction put the whole 5% in one tail. The hypotheses must be chosen before the data are seen, or the test is not fair. Check: with t = 1.860, the upper 5% point of t on 8 degrees of freedom, t√t2 + 8 = 1.8603.385 = 0.5494.
answer(a) r = 0.600; A: H0: ρ = 0, H1: ρ > 0; B: H0: ρ = 0, H1: ρ ≠ 0; (b) A: 0.600 > 0.5494, so reject H0: evidence of positive correlation; B: 0.600 < 0.6319, so do not reject H0: not enough evidence of correlation
techniqueCritical Values of r · Pearson’s Correlation Coefficient
examsSAT
Common pitfalls
- Using 0.6319 for Researcher A as well. A named the direction in advance, so the critical region is the upper 5% only, and its boundary 0.5494 is lower.
- Reading B's result as proof that the two are not correlated. Not rejecting H0 means only that ten plants do not give enough evidence; a larger sample might.
A Print Shop's Charges for Eight Jobs, Where the Gradient Is the Cost of Each Extra Hundred Copies
A print shop charges $y for a job of x hundred copies. Eight recent jobs were: x = 2, 3, 5, 6, 8, 10, 12, 14 and y = 19.50, 26.50, 33.50, 40.00, 49.00, 57.00, 67.00, 73.50. You may use ∑ x = 60, ∑ y = 366, ∑ x2 = 578 and ∑ xy = 3321. (a) Find the equation of the least-squares regression line of y on x. (b) Explain what the gradient and the intercept mean for the shop's charges, and say which of the two is less reliable.
The least-squares line of y on x makes the sum of the squared vertical residuals as small as possible. Its gradient is b = SxySxx, and it always passes through the mean point (x, y).
- Work out the two sums the gradient needs: Sxx = 578 − 6028 = 578 − 450 = 128 and Sxy = 3321 − 60 × 3668 = 3321 − 2745 = 576.
- The gradient is b = SxySxx = 576128 = 4.5.
- The line passes through the mean point (x, y) = (7.5, 45.75), so the intercept is a = y − bx = 45.75 − 4.5 × 7.5 = 45.75 − 33.75 = 12.
- (a) The regression line of y on x is y = 4.5x + 12.
- (b) The gradient 4.5 means that each extra hundred copies adds about $4.50 to the charge, which is 4.5 cents a copy. The intercept 12 is the charge for no copies at all: a fixed charge of about $12 for setting up a job.
- The intercept is less reliable. The jobs start at 200 copies, so x = 0 lies outside the data and the fixed charge is read off the line beyond them. Check: at x = 8 the line gives 4.5 × 8 + 12 = $48, close to the $49 charged.
answer(a) y = 4.5x + 12; (b) each extra hundred copies costs about $4.50, and there is a fixed charge of about $12 a job; the intercept is less reliable because x = 0 lies outside the data
techniqueThe Least-Squares Regression Line
Common pitfalls
- Reading the gradient as the price of one copy, $4.50. x counts hundreds of copies, so $4.50 is the cost of a hundred more, which is 4.5 cents a copy.
- Dividing by Syy instead of Sxx for the gradient. The line of y on x measures its residuals in y, and its gradient is SxySxx.
A Girl's Height on Each Birthday from Two to Ten, Used Once Inside the Record and Once Twenty Years Beyond It
A girl's height y cm was measured on each birthday from age x = 2 to age x = 10 years. The nine heights were 86, 92, 102, 108, 113, 119, 125, 129 and 134 cm. The regression line of y on x is y = 6x + 76. (a) Use the line to estimate her height at age 7.5 years, and say whether the estimate is reliable. (b) Find the height the line gives at age 30, and explain why it should not be trusted.
A regression line is supported by the data only between the smallest and the largest value of x. A prediction inside that range is interpolation and can be trusted when the points lie close to the line. A prediction outside it is extrapolation, which assumes that the pattern carries on where nothing was measured.
- The measurements run from age 2 to age 10, so the line is supported by the data only for ages between 2 and 10.
- At x = 7.5: y = 6 × 7.5 + 76 = 45 + 76 = 121 cm.
- (a) Her estimated height at 7.5 years is 121 cm. The estimate is reliable: 7.5 lies inside the data, so this is interpolation, and the heights lie close to the line.
- At x = 30: y = 6 × 30 + 76 = 180 + 76 = 256 cm.
- (b) The line gives 256 cm, which is over 2.5 m and far taller than almost any adult. Age 30 is far outside the data, so this is extrapolation: the line assumes she grows 6 cm a year forever, but people stop growing in their late teens. Check: at the mean age 6 the line gives 6 × 6 + 76 = 112 cm, the mean of the nine heights.
answer(a) 121 cm, reliable because 7.5 lies inside the data; (b) 256 cm, which cannot be trusted because age 30 is far outside the data and people stop growing in their late teens
techniquePredicting from a Regression Line · The Least-Squares Regression Line
Common pitfalls
- Trusting the prediction at age 30 because the points lie so close to the line. A strong correlation shows that the line fits ages 2 to 10; it says nothing about ages the data do not cover.
- Rejecting the estimate at 7.5 years because no measurement was taken at that age. Between measured ages the line is interpolation, which the data support.
Two Judges at a Village Baking Contest, One Ranking the Cakes and One Scoring Them with a Tie
Two judges assess eight cakes, A to H. The first judge ranks them from 1 (best) to 8: A 3, B 6, C 1, D 5, E 8, F 2, G 4, H 7. The second judge gives each cake a score out of 20: A 17, B 10, C 18, D 15, E 13, F 19, G 15, H 12. (a) Rank the second judge's scores, sharing the rank of any tie between them, and calculate Spearman's rank correlation coefficient from the d2 formula. (b) Test at the 5% level whether there is an association between the two judges' rankings, using the two-tailed critical value 0.7381 for n = 8.
Spearman's coefficient compares two orders rather than two sets of measurements. Both columns are ranked in the same direction, the difference d between the two ranks is found for each cake, and rs = 1 − 6 ∑ d2n(n2 − 1).
- Rank the second judge's scores from the highest, as the first judge ranked from the best: F (19) is 1, C (18) is 2, A (17) is 3, E (13) is 6, H (12) is 7 and B (10) is 8.
- D and G both score 15, and they share the 4th and 5th places, so each takes the mean rank 4 + 52 = 4.5.
- The differences d between the first and second ranks, from A to H, are 0, −2, −1, 0.5, 2, 1, −0.5 and 0, so ∑ d2 = 0 + 4 + 1 + 0.25 + 4 + 1 + 0.25 + 0 = 10.5.
- (a) rs = 1 − 6 ∑ d2n(n2 − 1) = 1 − 6 × 10.58 × 63 = 1 − 63504 = 1 − 0.125 = 0.875.
- (b) H0: there is no association between the rankings, ρs = 0; H1: there is an association, ρs ≠ 0. Since 0.875 > 0.7381, reject H0: there is evidence at the 5% level of an association, and as rs is positive the two judges tend to agree. Check: Pearson's r worked out on the two columns of ranks gives 0.874, so with a single tie the formula is a close approximation.
answer(a) the second judge's ranks are A 3, B 8, C 2, D 4.5, E 6, F 1, G 4.5, H 7; ∑ d2 = 10.5 and rs = 0.875; (b) 0.875 > 0.7381, so reject H0: there is evidence at the 5% level of an association, the judges tending to agree
techniqueSpearman’s Rank Correlation · Critical Values of r
examsH2
Common pitfalls
- Giving the two scores of 15 the ranks 4 and 5 in some order, or both 4. Tied values share the places they cover, so each takes 4.5, and the eight ranks still add up to 36.
- Ranking the scores from the lowest while the first judge ranked from the best. The two columns must be ranked in the same direction, or rs comes out negative although the judges agree.
A French Mark Estimated from a Spanish Mark, for a Student Who Missed the French Exam
Ten students sat a French exam and a Spanish exam. Their French marks x and Spanish marks y give ∑ x = 550, ∑ y = 500, ∑ x2 = 30750, ∑ y2 = 27000 and ∑ xy = 28300. An eleventh student scored 60 in Spanish but was ill on the day of the French exam. (a) Find the regression line of x on y, and use it to estimate her French mark. (b) Find the regression line of y on x, rearrange it to give x, and explain why its estimate of her French mark is different.
Each regression line makes the squared residuals in one variable as small as possible: the line of y on x minimizes the vertical ones and the line of x on y the horizontal ones. The variable to be estimated is the one whose errors should be made small.
- Work out the three sums: Sxx = 30750 − 550210 = 30750 − 30250 = 500, Syy = 27000 − 500210 = 27000 − 25000 = 2000 and Sxy = 28300 − 550 × 50010 = 28300 − 27500 = 800.
- The French mark is estimated from a known Spanish mark, so use the line of x on y, x = c + dy, with d = SxySyy = 8002000 = 0.4. It passes through the mean point (x, y) = (55, 50), so c = 55 − 0.4 × 50 = 35.
- (a) The line of x on y is x = 35 + 0.4y. At y = 60: x = 35 + 0.4 × 60 = 35 + 24 = 59, so her French mark is estimated as 59.
- The line of y on x has gradient b = SxySxx = 800500 = 1.6 and intercept a = 50 − 1.6 × 55 = 50 − 88 = −38, so it is y = 1.6x − 38.
- (b) Rearranged, x = y + 381.6, which at y = 60 gives 981.6 = 61.25. It is different because the line of y on x minimizes the errors in the Spanish mark, while the French mark is the one being estimated. The two lines cross at the mean point and are the same line only when r = ± 1; here r = 800√500 × 2000 = 8001000 = 0.8.
answer(a) x = 35 + 0.4y, which estimates her French mark as 59; (b) y = 1.6x − 38, which rearranged gives 61.25; that line minimizes the errors in the Spanish mark, not in the French mark being estimated, so 59 is the estimate to use
techniqueThe Regression Line of x on y · The Least-Squares Regression Line · Pearson’s Correlation Coefficient
Common pitfalls
- Rearranging the line of y on x to estimate x. That line was chosen to make the errors in y small, so it is the wrong line for estimating x unless the correlation is perfect.
- Dividing by Sxx for the gradient of x on y. 800500 = 1.6 is the gradient of y on x; for x on y the denominator is Syy, the spread of the variable that is known.
Flats Sold in One Street: How Much of the Price the Floor Area Explains
An estate agent records the floor area x m2 and the selling price y thousand dollars of 10 flats sold in one street. The results give Sxx = 2500, Syy = 90000 and Sxy = 10500. The agent says that floor area decides the price. (a) Calculate r and the coefficient of determination r2. (b) Find the sum of the squared residuals about the regression line of y on x, and say what share of the variation in price the floor area explains.
The total variation in y is Syy, the sum of the squared distances of the prices from their mean. The regression line accounts for part of it, and what is left over is the sum of the squared residuals. The share accounted for is r2, the coefficient of determination.
- Pearson's correlation coefficient is r = Sxy√Sxx Syy = 10500√2500 × 90000 = 1050015000 = 0.7.
- (a) r = 0.7, and the coefficient of determination is r2 = 0.72 = 0.49.
- The total variation in price is Syy = 90000. The regression line accounts for Sxy2Sxx = 1050022500 = 44100 of it.
- (b) The squared residuals add up to the rest: 90000 − 44100 = 45900. Floor area explains 4410090000 = 0.49, that is 49% of the variation in price, and 51% is left to other things, such as the floor the flat is on and its condition.
- The agent's claim is too strong: r = 0.7 is a fairly strong correlation, but floor area accounts for less than half of the variation in price. Check: 4590090000 = 0.51 = 1 − r2.
answer(a) r = 0.7 and r2 = 0.49; (b) the squared residuals add up to 45900; floor area explains 49% of the variation in price, less than half
techniqueThe Coefficient of Determination · Pearson’s Correlation Coefficient
Common pitfalls
- Reading r = 0.7 as 70% of the variation explained. The share explained is r2 = 0.49, which is less than half.
- Taking r2 = 0.49 to mean that the line is wrong for about half of the flats. It is a share of the variation, the total squared distance of the prices from their mean, not a count of flats.
Bacteria Counted Every Hour in a Culture, Fitted by N = ab^x Through Logarithms
A biologist counts the bacteria in a drop of culture every hour. At x = 0, 1, 2, 3, 4 and 5 hours the counts N are 129, 245, 501, 1000, 1950 and 4074. She expects a model of the form N = abx. (a) Using logarithms to base 10, find the least-squares regression line of log N on x. (b) Find a and b, and estimate the count after 4.5 hours.
A least-squares line needs a straight-line pattern. Taking logarithms of N = abx gives log N = log a + x log b, which is a straight line in x and log N, so the line is fitted to the logarithms and a and b are read back from its intercept and gradient.
- Take logarithms to base 10 of both sides: log N = log a + x log b. This is a straight line in x and log N, with gradient log b and intercept log a.
- To 2 decimal places, the values of log N are 2.11, 2.39, 2.70, 3.00, 3.29 and 3.61. They rise by about 0.3 each hour, so the transformed points lie close to a straight line.
- Write Y = log N. Then ∑ x = 15, ∑ Y = 17.1, ∑ x2 = 55 and ∑ xY = 48, so Sxx = 55 − 1526 = 17.5 and SxY = 48 − 15 × 17.16 = 48 − 42.75 = 5.25. The gradient is 5.2517.5 = 0.3.
- (a) The intercept is Y − 0.3x = 2.85 − 0.3 × 2.5 = 2.1, so the line is log N = 2.1 + 0.3x.
- (b) log a = 2.1 gives a = 102.1 = 126 to 3 significant figures, and log b = 0.3 gives b = 100.3 = 2.00. The model is N = 126 × 2.00x, so the count doubles every hour.
- At x = 4.5: log N = 2.1 + 0.3 × 4.5 = 3.45, so N = 103.45 = 2820 to 3 significant figures. Check: at x = 3 the line gives log N = 3, which is N = 1000, the count recorded.
answer(a) log N = 2.1 + 0.3x; (b) a = 126 and b = 2.00, so N = 126 × 2.00x; after 4.5 hours about 2820 bacteria
techniqueNon-Linear Regression · The Least-Squares Regression Line · Predicting from a Regression Line
Common pitfalls
- Fitting a straight line to N itself. The counts double every hour, so they curve upward, and a straight line would lie above the middle counts and below the last one.
- Reading b as the gradient 0.3 and a as the intercept 2.1. The gradient is log b and the intercept is log a, so b = 100.3 = 2.00 and a = 102.1 = 126.
Engine Size Against Carbon Dioxide Emissions, Worked in Coded Units and Turned Back
For 8 car models, the engine size x cm3 and the carbon dioxide emitted y g per km are coded by u = x − 1000100 and v = y − 10010. The coded data give ∑ u = 40, ∑ v = 32, ∑ u2 = 250, ∑ v2 = 160 and ∑ uv = 196. (a) Find the correlation coefficient between u and v, and state the correlation coefficient between x and y. (b) Find the regression line of v on u, and hence the regression line of y on x.
Coding subtracts a constant and divides by a positive constant. That slides the points and rescales the axes, but it does not change how closely they lie to a line, so r is the same for the coded and the original data. A regression line, on the other hand, has units, so it must be turned back into x and y.
- Work out the three sums for the coded data: Suu = 250 − 4028 = 250 − 200 = 50, Svv = 160 − 3228 = 160 − 128 = 32 and Suv = 196 − 40 × 328 = 196 − 160 = 36.
- The correlation coefficient between u and v is r = 36√50 × 32 = 36√1600 = 3640 = 0.9.
- (a) Subtracting 1000 and 100 moves every point by the same amount, and dividing by 100 and 10 rescales each axis. Neither moves any point closer to or further from the line, so the correlation coefficient between x and y is also 0.9.
- The gradient of v on u is SuvSuu = 3650 = 0.72. The means are u = 5 and v = 4, so v = 4 + 0.72(u − 5) = 0.72u + 0.4.
- (b) Substitute the codes: y − 10010 = 0.72 × x − 1000100 + 0.4. Multiply both sides by 10: y − 100 = 0.072(x − 1000) + 4 = 0.072x − 72 + 4, so y = 0.072x + 32. Check: the mean point u = 5, v = 4 is x = 1500 and y = 140, and 0.072 × 1500 + 32 = 108 + 32 = 140.
answer(a) r = 0.9 between u and v, and also 0.9 between x and y; (b) v = 0.72u + 0.4, so y = 0.072x + 32
techniquePearson’s Correlation Coefficient · The Least-Squares Regression Line
Common pitfalls
- Writing the decoded line as y = 0.72x + 0.4. The gradient 0.72 is in coded units; one unit of u is 100 cm3 and one unit of v is 10 g per km, so the gradient in the original units is 0.72 × 10100 = 0.072.
- Multiplying r by the coding factors. r has no units, so changing the units leaves it unchanged; only a negative factor would change its sign.
Libraries and Car Thefts in Eight Towns, Compared Town by Town and per Resident
A councillor notices that towns with more libraries have more car thefts. For 8 towns with populations of 20, 40, 60, 80, 100, 120, 140 and 160 thousand she records the number of libraries x: 2, 6, 9, 8, 10, 18, 21, 16, and the number of car thefts last year y: 60, 120, 240, 320, 300, 360, 560, 640. You may use Sxx = 293.5, Syy = 275800 and Sxy = 7790. (a) Calculate r, and test at the 5% level for positive correlation, using the critical value 0.6215 for n = 8. (b) Work out the number of libraries and the number of thefts per 10000 residents in each town, and explain what they show.
A significant correlation shows that two variables are associated, not that one causes the other. When both grow with a third variable, a lurking variable, dividing each by it removes its effect, and what is left shows whether the two are still related.
- Pearson's correlation coefficient is r = 7790√293.5 × 275800 = 7790√80947300 = 77908997.1 = 0.866.
- (a) H0: ρ = 0 and H1: ρ > 0. Since 0.866 > 0.6215, reject H0: there is evidence at the 5% level of positive correlation between the number of libraries and the number of car thefts.
- Both counts grow with the size of the town. Divide each count by the population in tens of thousands. The libraries per 10000 residents are 1, 1.5, 1.5, 1, 1, 1.5, 1.5, 1 and the thefts per 10000 residents are 30, 30, 40, 40, 30, 30, 40, 40.
- Each of the four pairs (1, 30), (1, 40), (1.5, 30) and (1.5, 40) occurs twice. A town with more libraries per head is no more likely to have more thefts per head, and the correlation between the two rates is 0.
- (b) The population is a lurking variable that drives both counts: a bigger town has more libraries and more cars to steal. The correlation in (a) does not show that libraries attract thieves, and closing libraries would not reduce thefts. Check: the rates give back the counts, for example 1.5 × 6 = 9 libraries and 40 × 6 = 240 thefts in the town of 60 thousand.
answer(a) r = 0.866 > 0.6215, so reject H0: there is evidence of positive correlation; (b) per 10000 residents the correlation is 0: the population is a lurking variable driving both counts, so the libraries do not cause the thefts
techniquePearson’s Correlation Coefficient · Critical Values of r
Common pitfalls
- Concluding that libraries cause car thefts because the test is significant. The test shows only that the two counts are associated; it cannot say why.
- Using the two-tailed critical value. The councillor's claim names a direction, more libraries with more thefts, so the test is one-tailed and its critical value for n = 8 is 0.6215.