STA154 ยท 2081 ยท 10 marks
Question A software company tracks the number of hours its employees spend on coding (X) and the corresponding number of bugs they encounter during testing (Y). (a) Calculate the Pearson correlation coefficient. (b) Find the regression equation of Y on X. (c) Predict the number of bugs encountered i
Question
A software company tracks the number of hours its employees spend on coding (X) and the corresponding number of bugs they encounter during testing (Y).
$$\begin{array}{|c|cccccccccc|}\hline \text{Hours (X)} & 20 & 25 & 30 & 35 & 40 & 45 & 50 & 55 & 60 & 65 \ \hline \text{Bugs (Y)} & 5 & 7 & 8 & 12 & 15 & 13 & 17 & 18 & 20 & 25 \ \hline \end{array}$$
(a) Calculate the Pearson correlation coefficient.
(b) Find the regression equation of Y on X.
(c) Predict the number of bugs encountered if an employee spends 48 hours coding.
[10+0]
Model Answer: Correlation and Regression Analysis
Given Data
| X | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 |
|---|---|---|---|---|---|---|---|---|---|---|
| Y | 5 | 7 | 8 | 12 | 15 | 13 | 17 | 18 | 20 | 25 |
$n = 10$, predict Y at $X = 48$.
Computation Table
| X | Y | XY | Xยฒ | Yยฒ |
|---|---|---|---|---|
| 20 | 5 | 100 | 400 | 25 |
| 25 | 7 | 175 | 625 | 49 |
| 30 | 8 | 240 | 900 | 64 |
| 35 | 12 | 420 | 1225 | 144 |
| 40 | 15 | 600 | 1600 | 225 |
| 45 | 13 | 585 | 2025 | 169 |
| 50 | 17 | 850 | 2500 | 289 |
| 55 | 18 | 990 | 3025 | 324 |
| 60 | 20 | 1200 | 3600 | 400 |
| 65 | 25 | 1625 | 4225 | 625 |
Totals:
- $\sum X = 425$
- $\sum Y = 140$
- $\sum XY = 6785$
- $\sum X^2 = 20125$
- $\sum Y^2 = 2314$
Verification of totals: $\sum Y^2 = 25+49+64+144+225+169+289+324+400+625 = 2314$ โ
(a) Pearson Correlation Coefficient
$$r = \frac{n\sum XY - \sum X \sum Y}{\sqrt{[n\sum X^2 - (\sum X)^2][n\sum Y^2 - (\sum Y)^2]}}$$
Numerator: $$10(6785) - 425(140) = 67850 - 59500 = 8350$$
Denominator part 1: $$10(20125) - 425^2 = 201250 - 180625 = 20625$$
Denominator part 2: $$10(2314) - 140^2 = 23140 - 19600 = 3540$$
$$r = \frac{8350}{\sqrt{20625 \times 3540}} = \frac{8350}{\sqrt{73012500}} = \frac{8350}{8544.74} = 0.9772$$
$$\boxed{r \approx 0.977}$$
Watch the $X^2$ total: add the $X^2$ column carefully, since $\sum X^2 = 20125$ carries straight into $n\sum X^2 - (\sum X)^2 = 20625$ and into the product under the root, and a slip there changes $r$, $b$ and the prediction together.
Interpretation: Strong positive correlation; as coding hours increase, bugs tend to increase.
(b) Regression Equation of Y on X
$$b = \frac{n\sum XY - \sum X \sum Y}{n\sum X^2 - (\sum X)^2} = \frac{8350}{20625} = 0.40485$$
Means: $$\bar{X} = \frac{425}{10} = 42.5, \qquad \bar{Y} = \frac{140}{10} = 14$$
Intercept: $$a = \bar{Y} - b\bar{X} = 14 - 0.40485(42.5) = 14 - 17.2061 = -3.2061$$
$$\boxed{\hat{Y} = -3.2061 + 0.4048X}$$
(c) Prediction for X = 48
$$\hat{Y} = -3.2061 + 0.40485(48) = -3.2061 + 19.4328 = 16.2267$$
$$\boxed{\hat{Y} \approx 16.23 \approx 16 \text{ bugs}}$$
Conclusion: About 16 bugs are expected for 48 coding hours.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.