8 Correlation And Regression Analysis

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.

Correlation and Regression Analysis: notes

Correlation coefficient definition and properties

Correlation is the degree of linear relationship between two variables. The correlation coefficient $r$ measures it. It is positive when both rise together, negative when one rises as the other falls, and zero when there is no linear link.

Properties:

  • $-1 \le r \le +1$.
  • $r = +1$ means perfect positive and $r = -1$ means perfect negative correlation.
  • $r$ has no unit.
  • $r$ does not change if we add a constant to, or multiply by a positive constant, every value of $X$ or $Y$.
  • $r$ is the geometric mean of the two regression coefficients: $r = \pm\sqrt{b_{yx},b_{xy}}$.
  • Independent variables have $r = 0$, but $r = 0$ does not prove independence.
  • Correlation does not mean cause and effect.

Karl Pearson correlation coefficient

$$r = \frac{\text{Cov}(X, Y)}{s_x s_y} = \frac{S_{xy}}{\sqrt{S_{xx},S_{yy}}}$$ where $S_{xy} = \sum xy - \dfrac{\sum x \sum y}{n}$, $S_{xx} = \sum x^2 - \dfrac{(\sum x)^2}{n}$ and $S_{yy} = \sum y^2 - \dfrac{(\sum y)^2}{n}$.

Example: hours of study $X$ and score $Y$ for six students.

$X$2457810
$Y$3548911

$$\begin{aligned} \sum x &= 36, \quad \sum y = 40, \quad \sum xy = 284 \ \sum x^2 &= 258, \quad \sum y^2 = 316 \ S_{xy} &= 284 - \frac{36 \times 40}{6} = 44 \ S_{xx} &= 258 - \frac{36^2}{6} = 42 \ S_{yy} &= 316 - \frac{40^2}{6} = 49.33 \ r &= \frac{44}{\sqrt{42 \times 49.33}} = \frac{44}{45.52} = 0.967 \end{aligned}$$

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 answer

Model Answer: Correlation and Regression Analysis

Given Data

X (hours)15202530354045505560
Y (issues)36811121416192122

$n = 10$


STEP 1: Compute the sums

XYXYX²Y²
153452259
20612040036
25820062564
3011330900121
35124201225144
40145601600196
45167202025256
50199502500361
552111553025441
602213203600484
3751325820161252112

$\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.

Open this answer on its own page →

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 answer

Model Answer: Correlation and Regression Analysis

Given Data

X20253035404550556065
Y57812151317182025

$n = 10$, predict Y at $X = 48$.

Computation Table

XYXYX²Y²
20510040025
25717562549
30824090064
35124201225144
40156001600225
45135852025169
50178502500289
55189903025324
602012003600400
652516254225625

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.

Open this answer on its own page →

2080 · 5 marks

Properties of Correlation and Analysis

  1. Range: The correlation coefficient always lies between $-1$ and $+1$, i.e., $-1 \le r \le +1$. 2. Independent of change of origin and scale: Correlation is unaffected by adding/subtracting a constant or multiplying/dividing by a positive constant. 3. Pure number (unit-free): It has no units of...
Open this answer on its own page →

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]

Marks of 10 students: Student Maths (x) Basic Statistics (y) --------- 1 55 65 2 70 40 3 40 30 4 30 50 5 90 60 6 80 70 7 60 50 8 80 50 9 90 60 10 80 70 $n = 10$ $$r = \frac{n\sum xy - \sum x \sum y}{\sqrt{[n\sum x^2 - (\sum x)^2][n\sum y^2 - (\sum y)^2]}}$$ x y xy x² y² --------------- 55 65 3575...

Open this answer on its own page →

Simple linear regression model

2080 · 10 marks

Regression Analysis: Blood Pressure and Age

Regression is a statistical technique used to model and analyze the relationship between a dependent variable and one or more independent variables. It enables estimation or prediction of the dependent variable's value from known values of the independent variable(s). The simple linear regression...

Open this answer on its own page →

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)5055545237525347
Weight (gram × 100)1220151750101514

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]

Circumference X (cm) Weight Y (×100 g) ------ 50 12 55 20 54 15 52 17 37 50 52 10 53 15 47 14 - n = 8 - Required: (i) regression of weight on circumference, (ii) estimate weight at X = 40, and comment on X = 80. Computation table: X Y XY X² ------------ 50 12 600 2500 55 20 1100 3025 54 15 810 29...

Open this answer on its own page →

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)1612184310512
Performance (Y)8788896878807583

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]

X (Experience, yrs) 16 12 18 4 3 10 5 12 --------------------------- Y (Performance) 87 88 89 68 78 80 75 83 n = 8, estimate required at X = 8. X Y XY X² -------------- 16 87 1392 256 12 88 1056 144 18 89 1602 324 4 68 272 16 3 78 234 9 10 80 800 100 5 75 375 25 12 83 996 144 80 648 6727 1018

Open this answer on its own page →

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 expenditure40503860655035
Sales38605570604830

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]

Advertisement Expenditure (X) Sales (Y) ------------- 40 38 50 60 38 55 60 70 65 60 50 48 35 30 $n = 7$ X Y XY X² Y² ------------------- 40 38 1520 1600 1444 50 60 3000 2500 3600 38 55 2090 1444 3025 60 70 4200 3600 4900 65 60 3900 4225 3600 50 48 2400 2500 2304 35 30 1050 1225 900 ΣX = 338 ΣY = ...

Open this answer on its own page →

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.

ComputerStudent preference
DELL52981103467
HP10513862794

[5]

Student 1 2 3 4 5 6 7 8 9 10 ----------------------------------------- DELL (X) 5 2 9 8 1 10 3 4 6 7 HP (Y) 10 5 1 3 8 6 2 7 9 4 Number of students $n = 10$. Both rows are already ranks (1 to 10, no ties). Step 1: Compute rank differences $d = X - Y$ and $d^2$ Student X Y $d = X-Y$ $d^2$ --------...

Open this answer on its own page →

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:23272828293031333536
Wife's age Y:18202721292727292829

[5]

Show solved 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)

XYXYX²Y²
2318414529324
2720540729400
2827756784729
2821588784441
2929841841841
3027810900729
3127837961729
33299571089841
35289801225784
362910441296841

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.

Open this answer on its own page →

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]

  • Regression line A: $3X + 2Y = 26$ - Regression line B: $6X + 3Y = 31$ We must first decide which line is "Y on X" and which is "X on Y." The correct assignment is the one that gives a valid correlation coefficient, i.e. $r \le 1$, equivalently $b{yx} \cdot b{xy} \le 1$. Line A → Y on X:
Open this answer on its own page →

Assumptions of linear regression

2080.1 · 10 marks

Simple Linear Regression Analysis

  1. Linearity: The mean of the response $Y$ is a linear function of $X$. 2. Independence: The error terms (observations) are independent. 3. Homoscedasticity: Constant variance of errors across all values of $X$. 4. Normality: The error terms are normally distributed with mean zero. 5. Fixed X: Th...
Open this answer on its own page →