Correlation and Regression Workbook: 10 Exercises with Full Solutions

Ten correlation and regression exercises with full worked solutions, from the correlation coefficient and Spearman rank to fitting a least-squares line and predicting from it. Try them, then check your method.

This workbook accompanies the Correlation and Linear Regression article and is built for practice with a calculator. The ten exercises follow the lesson’s path, beginning with reading scatterplots and judging the sign of a correlation, then computing the correlation coefficient and the Spearman rank version, fitting a least-squares line, predicting from it, and finishing with the cautions about causation and extrapolation that matter most. Each exercise isolates one skill so you can pinpoint where your method needs work.

Attempt every exercise before reading the solutions, and write out each step rather than skipping to the answer, because in this subject the working earns the marks. The solutions name the formula, show the arithmetic, and interpret the result, so the goal is to compare your reasoning against the standard approach. Where summary statistics are given, use them directly, exactly as an exam would expect.

Part One: The Exercises

Exercise 1 (Sign of the correlation). State whether you would expect each pair of variables to be positively correlated, negatively correlated, or uncorrelated. (a) Outdoor temperature and ice cream sales. (b) The age of a used car and its resale value. (c) A person’s shoe size and their IQ.

Exercise 2 (Correlation and causation). Across a summer, ice cream sales and the number of drowning incidents at beaches are strongly positively correlated. Explain why it would be wrong to conclude that ice cream causes drowning, and identify the likely confounding variable.

Exercise 3 (Computing the correlation coefficient). For five observations, the summary statistics are: n = 5, the sum of x is 15, the sum of y is 25, the sum of x squared is 55, the sum of y squared is 135, and the sum of the products is 84. Compute the corrected sums and then the sample correlation coefficient r.

Exercise 4 (Properties of r). Answer each briefly. (a) If every x value is converted from metres to centimetres, does the value of r change? (b) What does a correlation of r = −0.95 indicate about the relationship? (c) Is the correlation of X with Y the same as the correlation of Y with X?

Exercise 5 (Spearman rank correlation). Six films are ranked by two critics. Critic one gives ranks 1, 2, 3, 4, 5, 6 and critic two gives ranks 2, 1, 4, 3, 6, 5 to the same six films in order. Compute the Spearman rank correlation coefficient.

Exercise 6 (Fitting a regression line). For eight observations, the summary statistics are: n = 8, the sum of x is 40, the sum of y is 120, the sum of the products is 680, and the sum of x squared is 240. Find the least-squares regression line of y on x.

Exercise 7 (Prediction within range). Using the regression line from Exercise 6, and given that the observed x values range from 1 to 9, predict the value of y when x is 6. State whether this is interpolation or extrapolation.

Exercise 8 (Extrapolation). A regression line estimated from data where x ranges between 2 and 8 is given by y-hat equals 20 minus 1.5x. Use it to predict y when x is 15, and explain why this prediction should not be trusted.

Exercise 9 (Dependent variable and slope). A company studies weekly advertising spend and weekly sales. State which variable should be the dependent variable and why. Then, given a fitted slope of 2, explain in words what that slope means.

Exercise 10 (r, slope, and r squared). Answer each briefly. (a) Does a large value of the absolute correlation imply that the regression line has a steep slope? (b) If r is 0.9, compute r squared and explain what it tells you about how the points relate to the regression line.

Part Two: Worked Solutions

Solution 1. Part (a) is positive, because warmer weather drives higher ice cream sales. Part (b) is negative, because an older car is generally worth less. Part (c) is uncorrelated, because there is no plausible linear relationship between shoe size and intelligence.

Solution 2. It is wrong because correlation does not imply causation, and here a third variable drives both quantities at once. Hot summer weather increases ice cream sales and also sends more people swimming, which raises the number of drownings. The confounding variable is the warm weather, or the summer season, so the link between ice cream and drowning is spurious rather than causal.

Solution 3. First compute the means: x-bar is 15 over 5, which is 3, and y-bar is 25 over 5, which is 5. Then the corrected sums follow.

Sxx=xi2nx2=555(3)2=10S_{xx} = \sum x_i^2 – n\bar{x}^2 = 55 – 5(3)^2 = 10
Syy=yi2ny2=1355(5)2=10S_{yy} = \sum y_i^2 – n\bar{y}^2 = 135 – 5(5)^2 = 10
Sxy=xiyinxy=845(3)(5)=9S_{xy} = \sum x_i y_i – n\bar{x}\bar{y} = 84 – 5(3)(5) = 9

The correlation coefficient is then their combination.

r=SxySxx,Syy=910×10=0.9r = \frac{S_{xy}}{\sqrt{S_{xx},S_{yy}}} = \frac{9}{\sqrt{10 \times 10}} = 0.9

This is a strong positive linear correlation.

Solution 4. Part (a): no, r does not change, because the correlation coefficient is independent of the scale of measurement. Part (b): a value of −0.95 indicates a strong negative linear relationship, where y falls steadily as x rises. Part (c): yes, the correlation is symmetric, so the correlation of X with Y equals the correlation of Y with X.

Solution 5. The rank differences for the six films are −1, 1, −1, 1, −1, 1, and squaring each gives 1 in every case, so the sum of squared differences is 6. Applying the Spearman formula with n equal to 6 gives the following.

rs=16di2n(n21)=16×66×(361)=136210=0.8286r_s = 1 – \frac{6\sum d_i^2}{n(n^2 – 1)} = 1 – \frac{6 \times 6}{6 \times (36 – 1)} = 1 – \frac{36}{210} = 0.8286

This is a strong positive agreement between the two critics’ rankings.

Solution 6. The means are x-bar equal to 40 over 8, which is 5, and y-bar equal to 120 over 8, which is 15. Compute the slope first, since the intercept depends on it.

b=xiyinxyxi2nx2=6808(5)(15)2408(5)2=8040=2b = \frac{\sum x_i y_i – n\bar{x}\bar{y}}{\sum x_i^2 – n\bar{x}^2} = \frac{680 – 8(5)(15)}{240 – 8(5)^2} = \frac{80}{40} = 2

Then the intercept.

a=ybx=152(5)=5a = \bar{y} – b\bar{x} = 15 – 2(5) = 5

So the estimated regression line is the following.

y^=5+2x\hat{y} = 5 + 2x

Solution 7. Substituting x equal to 6 into the fitted line gives the prediction.

y^=5+2(6)=17\hat{y} = 5 + 2(6) = 17

Because 6 lies inside the observed range of 1 to 9, this is interpolation, which is reliable.

Solution 8. Substituting x equal to 15 into the line gives a prediction.

y^=201.5(15)=2.5\hat{y} = 20 – 1.5(15) = -2.5

This should not be trusted because 15 lies far outside the observed range of 2 to 8, making it extrapolation. The relationship is only known to hold within the data range, and here it even produces an impossible negative value, which signals that the linear model cannot safely be pushed that far.

Solution 9. Sales should be the dependent variable, because sales react to advertising spend rather than the other way around, so advertising is the explanatory variable and sales the response. A slope of 2 means that for each one-unit increase in advertising spend, predicted sales rise by 2 units, in whatever units the two variables were measured.

Solution 10. Part (a): no, a large absolute correlation does not imply a steep slope. A strong correlation only means the points cluster tightly around their line, and that line may have a shallow or a steep gradient. Part (b): squaring the correlation gives r squared equal to 0.81. This indicates that the points lie close to the regression line, a strong linear fit, which corresponds to a small standard error for the slope.

How to Get the Most From This Workbook

The structure underneath these exercises is a short, repeatable pipeline. Plot or picture the data and judge the relationship, compute the three corrected sums, and from them get either the correlation coefficient by dividing the cross-product sum by the root of the product of the other two, or the regression slope by dividing the cross-product sum by the x sum of squares. The intercept then falls out of the means, and prediction is a single substitution. Two habits separate a strong answer from a weak one: always show the corrected sums as working, and always check whether a prediction sits inside the data range before you trust it. Master that pipeline and the cautions around it, and correlation and regression questions become some of the most dependable marks on the paper.

See you soon.

View Comments (1)

Leave a Reply

Subscribe to My Newsletter

Subscribe to my email newsletter to get the latest posts delivered right to your email. Pure inspiration, zero spam.

Discover more from Discuss Data Science, Machine Learning and Analytics

Subscribe now to keep reading and get access to the full archive.

Continue reading