Basic Statistics · Unit 8
Correlation and Regression Analysis
Exam-focused notes for Correlation and Regression Analysis (Basic Statistics, STA154): what the TU syllabus asks and how it has actually been tested, with 12 solved past questions from this unit.
Correlation and Regression Analysis in short
Many IT questions ask how two quantities move together, such as hours of debugging and bugs fixed. Correlation measures the strength of the link, and regression builds an equation to predict one variable from the other.
What this unit covers
- Correlation coefficient definition and properties
- Karl Pearson correlation coefficient
- Spearman rank correlation coefficient
- Interpretation of correlation results
- Simple linear regression model
- Regression equation fitting
- Regression coefficient interpretation
- Estimation using regression equations
- Assumptions of linear regression
Karl Pearson correlation coefficient
2082 · 10 marks
Question
A web development team records the number of hours spent on debugging (X) and the number of resolved issues (Y) across 10 sprints.
$$\begin{array}{|c|cccccccccc|}\hline X & 15 & 20 & 25 & 30 & 35 & 40 & 45 & 50 & 55 & 60 \ \hline Y & 3 & 6 & 8 & 11 & 12 & 14 & 16 & 19 & 21 & 22 \ \hline \end{array}$$
a) Calculate the Pearson correlation coefficient to assess the relationship between debugging hours and issues resolved.
b) Derive the regression equation of issues resolved on hours spent debugging.
c) Predict the number of issues resolved for 38 hours of debugging.
[10+0+0+0]
Show solved answerHide answer
Model Answer: Correlation and Regression Analysis
Given Data
| X (hours) | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 |
|---|---|---|---|---|---|---|---|---|---|---|
| Y (issues) | 3 | 6 | 8 | 11 | 12 | 14 | 16 | 19 | 21 | 22 |
$n = 10$
STEP 1: Compute the sums
| X | Y | XY | X² | Y² |
|---|---|---|---|---|
| 15 | 3 | 45 | 225 | 9 |
| 20 | 6 | 120 | 400 | 36 |
| 25 | 8 | 200 | 625 | 64 |
| 30 | 11 | 330 | 900 | 121 |
| 35 | 12 | 420 | 1225 | 144 |
| 40 | 14 | 560 | 1600 | 196 |
| 45 | 16 | 720 | 2025 | 256 |
| 50 | 19 | 950 | 2500 | 361 |
| 55 | 21 | 1155 | 3025 | 441 |
| 60 | 22 | 1320 | 3600 | 484 |
| 375 | 132 | 5820 | 16125 | 2112 |
$\sum X = 375,\ \sum Y = 132,\ \sum XY = 5820,\ \sum X^2 = 16125,\ \sum Y^2 = 2112$
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]}}$$
Compute components:
- $n\sum XY = 10 \times 5820 = 58200$
- $\sum X \sum Y = 375 \times 132 = 49500$
- $n\sum X^2 = 161250,\quad (\sum X)^2 = 140625 \Rightarrow 20625$
- $n\sum Y^2 = 21120,\quad (\sum Y)^2 = 17424 \Rightarrow 3696$
$$r = \frac{58200 - 49500}{\sqrt{20625 \times 3696}} = \frac{8700}{\sqrt{76245000}}$$
$$\sqrt{76245000} = 8731.95$$
$$r = \frac{8700}{8731.95} = 0.9963$$
$r \approx 0.996$: very strong positive correlation.
b) Regression Equation of Y on X
$$b = \frac{n\sum XY - \sum X \sum Y}{n\sum X^2 - (\sum X)^2} = \frac{8700}{20625} = 0.42182$$
Means:
$$\bar{X} = \frac{375}{10} = 37.5,\qquad \bar{Y} = \frac{132}{10} = 13.2$$
Intercept:
$$a = \bar{Y} - b\bar{X} = 13.2 - (0.42182)(37.5) = 13.2 - 15.818 = -2.618$$
$$\boxed{\hat{Y} = -2.618 + 0.4218,X}$$
c) Prediction for X = 38 hours
$$\hat{Y} = -2.618 + 0.4218(38) = -2.618 + 16.029 = 13.41$$
Approximately 13 issues resolved (13.4 if retaining decimals).
Since $r = 0.996$ and $X = 38$ lies inside the observed range $[15,60]$, the prediction is reliable.
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).
$$\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]
Show solved answerHide answer
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.
2080.1 · 5 marks
Karl Pearson's Coefficient of Correlation
From the following data on marks of 10 students in the two subjects, calculate the Karl Pearson's coefficient of correlation $r$ and interpret the result.
$$\begin{array}{|c|cccccccccc|}\hline \text{Maths} & 55 & 70 & 40 & 30 & 90 & 80 & 60 & 80 & 90 & 80 \ \hline \text{Basic Statistics} & 65 & 40 & 30 & 50 & 60 & 70 & 50 & 50 & 60 & 70 \ \hline \end{array}$$
[5]
Simple linear regression model
2079 · 10 marks
Pumpkin Weight Prediction Analysis
In Nepal, during the fall harvest season pumpkins are sold in large quantities at farm stands. Often instead of weighing the pumpkin prior to sale, the farm stand operators will just place the pumpkin in the appropriate circular cutout on the counter. When asked why this was done, one farmer replied, "I can tell the weight of the pumpkin from its circumference". To determine whether this was really true, a sample of 8 pumpkins' circumference and weights were measured:
| Circumference (cm) | 50 | 55 | 54 | 52 | 37 | 52 | 53 | 47 |
|---|---|---|---|---|---|---|---|---|
| Weight (gram × 100) | 12 | 20 | 15 | 17 | 50 | 10 | 15 | 14 |
i) Develop the estimating linear regression equation of weight of the pumpkin to the circumference.
ii) Estimate the weight of pumpkin if the circumference value is 40 cm. Can it be possible to predict the weight of a pumpkin if its circumference is 80 cm?
[10]
2078 · 10 marks
Regression Analysis: Experience and Performance
The following data gives the experience of Computer Operators in years and their performance as given by the number of good parts turned out per 100 pieces.
| Experience (X) | 16 | 12 | 18 | 4 | 3 | 10 | 5 | 12 |
|---|---|---|---|---|---|---|---|---|
| Performance (Y) | 87 | 88 | 89 | 68 | 78 | 80 | 75 | 83 |
i) Fit the regression equation of performance rating on experience.
ii) Estimate the probable performance of an operator with 8 years of experience and interpret the regression coefficient.
[10]
0 · 10 marks
Question
A big computer supplier in Kathmandu used to sell large number of computers in each year. His interest is to increase his sales volume in each year for which the supplier has started to take the help of advertisement and allocated some advertisement expenditure in his annual budget each year. The supplier wants to quantify the effect of advertise expenditure on sales of computers. The advertisement expenditure (in lakhs rupees) and their corresponding sales from the computers (in crores rupees) is tabulated as follows. (Assuming that the relationship between the advertisement expenditure and sales is linear.)
| Advertisement expenditure | 40 | 50 | 38 | 60 | 65 | 50 | 35 |
|---|---|---|---|---|---|---|---|
| Sales | 38 | 60 | 55 | 70 | 60 | 48 | 30 |
a.) Perform appropriate statistical analysis and quantify the effect of advertisement on sales obtained from the computer selling. Also interpret the results.
b.) Estimate the sales corresponding to advertising expenditure of Rs. 45 lakhs.
[5+5+0]
Spearman rank correlation coefficient
2079 · 5 marks
Following data represent the preference of 10 students studying BIT towards two brands of computers namely DELL and HP. Apply Pearson's rank correlation coefficient and compute correlation coefficient. Also interpret your result.
| Computer | Student preference | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| DELL | 5 | 2 | 9 | 8 | 1 | 10 | 3 | 4 | 6 | 7 |
| HP | 10 | 5 | 1 | 3 | 8 | 6 | 2 | 7 | 9 | 4 |
[5]
Correlation coefficient definition and properties
2078 · 5 marks
Define correlation coefficient? Calculate the coefficient of correlation for the following ages (in years) of husbands and wives and interpret it.
| Husband's age X: | 23 | 27 | 28 | 28 | 29 | 30 | 31 | 33 | 35 | 36 |
|---|---|---|---|---|---|---|---|---|---|---|
| Wife's age Y: | 18 | 20 | 27 | 21 | 29 | 27 | 27 | 29 | 28 | 29 |
[5]
Show solved answerHide answer
Correlation Coefficient: Definition and Calculation
Definition
The correlation coefficient is a statistical measure that expresses the degree and direction of the linear relationship between two variables. It ranges from $-1$ to $+1$:
- $+1$ = perfect positive correlation
- $-1$ = perfect negative correlation
- $0$ = no linear correlation
Pearson's 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]}}$$
Given Data (n = 10)
| X | Y | XY | X² | Y² |
|---|---|---|---|---|
| 23 | 18 | 414 | 529 | 324 |
| 27 | 20 | 540 | 729 | 400 |
| 28 | 27 | 756 | 784 | 729 |
| 28 | 21 | 588 | 784 | 441 |
| 29 | 29 | 841 | 841 | 841 |
| 30 | 27 | 810 | 900 | 729 |
| 31 | 27 | 837 | 961 | 729 |
| 33 | 29 | 957 | 1089 | 841 |
| 35 | 28 | 980 | 1225 | 784 |
| 36 | 29 | 1044 | 1296 | 841 |
Summations (verified)
- $\sum X = 23+27+28+28+29+30+31+33+35+36 = 300$
- $\sum Y = 18+20+27+21+29+27+27+29+28+29 = 255$
- $\sum XY = 414+540+756+588+841+810+837+957+980+1044 = 7767$
- $\sum X^2 = 529+729+784+784+841+900+961+1089+1225+1296 = 9138$
- $\sum Y^2 = 324+400+729+441+841+729+729+841+784+841 = 6659$
Note: the correct sums are $\sum X = 300$ (not 310), $\sum X^2 = 9138$ (not 9738) and $\sum Y^2 = 6659$ (not 6859). Rechecking $\sum Y^2$: $324+400=724$, $+729=1453$, $+441=1894$, $+841=2735$, $+729=3464$, $+729=4193$, $+841=5034$, $+784=5818$, $+841=6659$. Confirmed $6659$.
Substitution
Numerator: $$n\sum XY - \sum X\sum Y = 10(7767) - (300)(255) = 77670 - 76500 = 1170$$
X-term: $$n\sum X^2 - (\sum X)^2 = 10(9138) - (300)^2 = 91380 - 90000 = 1380$$
Y-term: $$n\sum Y^2 - (\sum Y)^2 = 10(6659) - (255)^2 = 66590 - 65025 = 1565$$
$$r = \frac{1170}{\sqrt{1380 \times 1565}} = \frac{1170}{\sqrt{2159700}} = \frac{1170}{1469.59}$$
$$\boxed{r \approx 0.796}$$
Interpretation
$r \approx +0.796$ indicates a strong positive correlation between husbands' and wives' ages. As the husband's age increases, the wife's age also tends to increase. This is consistent with real-world marriage patterns. The coefficient of determination $r^2 \approx 0.634$, so about 63% of the variation in wife's age is explained by husband's age.
A result of $r \approx -0.646$ comes from using $\sum X = 310$ instead of $300$, together with wrong squared sums, which flips the sign of the numerator.
0 · 5 marks
The following are the two regression lines: 3X+2Y=26 & 6X+3Y=31. Compute the correlation coefficient between them and interpret the result. [5]
Assumptions of linear regression
Make Unit 8 stick
Practice STA154 with flashcards & quizzes