7 Correlation And Linear Regression

Statistics I · Unit 7 · 7 hrs

Correlation and Linear Regression

Exam-focused notes for Correlation and Linear Regression (Statistics I, STA169): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.

Correlation and Linear Regression in short

Many quantities of interest come in pairs, hours studied and marks scored, CPU load and response time, and this chapter measures how strongly two such variables move together, and builds an equation to predict one from the other.

Correlation and Linear Regression: notes

Bivariate data

Bivariate data consists of two measurements recorded on every unit of study, such as the number of hours a student spends practising touch-typing and the typing speed they achieve, written as pairs $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$. This is distinct from univariate data, where only a single variable is recorded per unit; when three or more variables are recorded together, the data is called multivariate.

Bivariate frequency distribution

When bivariate data is voluminous, it is condensed into a bivariate frequency distribution: a two-way table whose rows are class intervals (or categories) of one variable, whose columns are class intervals of the other, and whose cells record how many units fall into each combination, with row and column totals giving the marginal frequency distribution of each variable separately, exactly as in a joint probability distribution table.

Correlation between two variables

Correlation measures the degree and direction of the linear relationship between two variables. It is positive if both variables tend to increase or decrease together, and negative if one tends to increase as the other decreases. It is linear if equal changes in one variable are associated with roughly equal changes in the other, and non-linear (curvilinear) otherwise. Studying the relationship between exactly two variables is simple correlation; studying three or more variables together gives multiple correlation (the relationship between one variable and the joint effect of several others) or partial correlation (the relationship between two variables with the effect of one or more further variables held constant).

What this unit covers

  • Bivariate data
  • Bivariate frequency distribution
  • Correlation between two variables
  • Karl Pearson's coefficient of correlation(r)
  • Spearman's rank correlation
  • Regression Analysis: Fitting of lines of regression by the least squares method
  • coefficient of determination
  • Problems and illustrative examples related to computer Science and IT

Karl Pearson's coefficient of correlation

2080 · 10 marks

Correlation and Regression Analysis

Show solved answer

Correlation and Regression Analysis

Given Data

$n = 8$

Number of weeks (x)453971045
Speed gain (y)851204819216423474110

Meaning of Correlation Types

i. Positive Correlation: Two variables move in the same direction. When one increases, the other also increases (and vice versa). Example: height and weight.

ii. Negative Correlation: Two variables move in opposite directions. When one increases, the other decreases. Example: price and demand.

iii. Perfect Correlation: A change in one variable produces an exactly proportional change in the other, so all points lie on a straight line. Perfect positive gives $r = +1$; perfect negative gives $r = -1$.


Calculation Table

xyx²y²xy
485167225340
51202514400600
34892304144
919281368641728
716449268961148
10234100547562340
474165476296
51102512100550
Σx=47Σy=1027Σx²=321Σy²=160021Σxy=7146

Verification of sums: $\Sigma x = 47$, $\Sigma y = 1027$, $\Sigma x^2 = 321$, $\Sigma xy = 7146$, and $\Sigma y^2 = 160021$. All confirmed.


Part (a): Correlation Coefficient

$$r = \frac{n\Sigma xy - \Sigma x \Sigma y}{\sqrt{[n\Sigma x^2 - (\Sigma x)^2][n\Sigma y^2 - (\Sigma y)^2]}}$$

Numerator: $$8(7146) - 47(1027) = 57168 - 48269 = 8899$$

First bracket: $$8(321) - 47^2 = 2568 - 2209 = 359$$

Second bracket: $$8(160021) - 1027^2 = 1280168 - 1054729 = 225439$$

$$r = \frac{8899}{\sqrt{359 \times 225439}} = \frac{8899}{\sqrt{80932601}} = \frac{8899}{8996.26}$$

$$\boxed{r \approx 0.989}$$

Interpretation: Since $r = 0.989$ is very close to $+1$, there is a very high positive correlation between weeks in the program and speed gain. As weeks increase, speed gain increases strongly.


Part (b): Regression Equation of Speed Gain (y) on Weeks (x)

$$\hat{y} = a + bx$$

$$b = \frac{n\Sigma xy - \Sigma x \Sigma y}{n\Sigma x^2 - (\Sigma x)^2} = \frac{8899}{359} = 24.79$$

$$\bar{x} = \frac{47}{8} = 5.875, \quad \bar{y} = \frac{1027}{8} = 128.375$$

$$a = \bar{y} - b\bar{x} = 128.375 - 24.79(5.875) = 128.375 - 145.64 = -17.26$$

$$\boxed{\hat{y} = -17.26 + 24.79x}$$


Part (c): Estimate for 6 Weeks and Slope Interpretation

$$\hat{y} = -17.26 + 24.79(6) = -17.26 + 148.74 = 131.48$$

$$\boxed{\hat{y} \approx 131.48 \text{ units of speed gain}}$$

Slope interpretation: $b = 24.79$ means that for each additional week in the program, the reading speed gain increases by about 24.79 units on average.

Open this answer on its own page →

2079 · 10 marks

Question

What are the assumptions of Pearson's correlation? Bradford Electric Illuminating is studying the relationship between kilowatt-hours (thousands) used and the number of rooms in private single-family residences. A random sample of 5 houses yields the following.

$$\begin{array}{c|ccccc} \text{Number of rooms} & 11 & 10 & 14 & 7 & 9 \ \hline \text{Kilowatts-hours (thousands) used} & 9 & 8 & 11 & 5 & 9 \ \end{array}$$

i. Find the correlation coefficient between the number of rooms and kilowatts-hours used. Interpret the result.

ii. Determine the regression equation of kilowatts hours used on the number of rooms. Interpret the value of the regression coefficient.

iii. Estimate the kilowatts-hours used for an 8 rooms house.

[10]

  1. Linear relationship: The two variables X and Y have a linear relationship. 2. Normality: The variables follow a bivariate normal distribution. 3. Continuous, quantitative data: Both variables are measured on an interval or ratio scale. 4. Homoscedasticity: Variance of Y is constant across valu...
Open this answer on its own page →

2080.1 · 10 marks

Difference between Correlation and Regression Analysis

Raw materials are used in the production of synthesis and fiber are stored in a place which has no humidity control. Measurement of relative humidity in the storage place and the moisture content of a sample of raw materials (both in percentage) on 10 days yields the following results.

$$\begin{array}{c|cccccccccc} \text{Humidity % (X)} & 48 & 55 & 30 & 44 & 36 & 31 & 62 & 48 & 42 & 50 \ \text{Moisture content % (Y)} & 11 & 13 & 10 & 12 & 9 & 7 & 16 & 11 & 9 & 14 \ \end{array}$$

i. Compute correlation coefficient between humidity and moisture content and interpret the result.

ii. Find the regression equation of moisture content on humidity.

iii. Estimate the moisture content if humidity is 45%.

iv. Interpret the value of regression coefficient.

[10]

Show solved answer

Difference Between Correlation and Regression Analysis

BasisCorrelationRegression
MeaningMeasures degree and direction of linear relationship between two variablesEstablishes functional relationship to predict one variable from another
PurposeFind strength of associationEstimate/predict dependent variable
VariablesBoth treated equallyOne independent (X), one dependent (Y)
ResultA single value $r \in [-1, +1]$An equation (regression line)
Symmetry$r(X,Y)=r(Y,X)$Regression of Y on X $\neq$ X on Y
Cause-EffectDoes not imply causationAssumes a dependence relationship

Given Data

$n = 10$

X48553044363162484250
Y11131012971611914

Preliminary Calculations

XYX²Y²XY
48112304121528
55133025169715
3010900100300
44121936144528
369129681324
31796149217
62163844256992
48112304121528
429176481378
50142500196700
4461122083413185210

$$\bar{X}=\frac{446}{10}=44.6,\qquad \bar{Y}=\frac{112}{10}=11.2$$

$$\Sigma X^2-n\bar X^2 = 20834-10(44.6)^2=20834-19891.6=942.4$$ $$\Sigma Y^2-n\bar Y^2 = 1318-10(11.2)^2=1318-1254.4=63.6$$ $$\Sigma XY-n\bar X\bar Y = 5210-10(44.6)(11.2)=5210-4995.2=214.8$$


Part (i): Correlation Coefficient

$$r=\frac{\Sigma XY-n\bar X\bar Y}{\sqrt{(\Sigma X^2-n\bar X^2)(\Sigma Y^2-n\bar Y^2)}}=\frac{214.8}{\sqrt{942.4\times63.6}}$$

$$r=\frac{214.8}{\sqrt{59916.64}}=\frac{214.8}{244.78}\approx \boxed{0.877}$$

Interpretation: $r=0.877$ shows a strong positive linear relationship. As humidity increases, moisture content also increases.


Part (ii): Regression Equation of Y on X

$$b_{YX}=\frac{\Sigma XY-n\bar X\bar Y}{\Sigma X^2-n\bar X^2}=\frac{214.8}{942.4}=0.2279\approx 0.228$$

$$a=\bar Y-b\bar X=11.2-0.228(44.6)=11.2-10.169=1.031$$

$$\boxed{\hat Y = 1.03 + 0.228X}$$


Part (iii): Estimate Y when X = 45

$$\hat Y = 1.03 + 0.228(45)=1.03+10.26=\boxed{11.29%}$$

When humidity is 45%, estimated moisture content ≈ 11.29%.


Part (iv): Interpretation of Regression Coefficient

$b=0.228$ means that for every 1 percentage point increase in relative humidity, the moisture content increases on average by about 0.228 percentage points. The positive sign confirms a direct relationship: higher storage humidity leads to higher moisture in the raw materials.

Open this answer on its own page →

Regression Analysis

2078 · 10 marks

Write the properties of correlation coefficient. The time it takes to transmit a file always depends on the file size. Suppose you transmitted 30 files, with the average size of 126 Kbytes and the standard deviation of 35 Kbytes. The average transmitted time was 0.04 seconds with the standard deviation 0.01 seconds. The correlation coefficient between the time and size was 0.86. Based on these data, fit a linear regression model and predict the time it take to transmit a 400Kbyte file.[10]

Let $X$ = file size (Kbytes), $Y$ = transmission time (seconds). Parameter X (size) Y (time) ------------------------------- Number of files $n = 30$ Mean $\bar{X} = 126$ $\bar{Y} = 0.04$ Std. deviation $SX = 35$ $SY = 0.01$ Correlation $r = 0.86$ Predict $Y$ when $X = 400$ Kbytes. --- 1. Range: ...

Open this answer on its own page →

2076 · 10 marks

Question

A study was done to study the effect of ambient temperature on the electric power consumed by a chemical plant. Following table gives the data which are collected from an experimental pilot plant.

Temperature (°F)2745725831603474
Electric Power (BTU)250285320295265298267321

a. Identify which one is response variable, and fit a simple regression line, assuming that the relationship between them is linear.

b. Interpret the regression coefficient with reference to your problem.

c. Obtain coefficient of determination, and interpret this.

d. Based on the fitted model in (a), predict the power consumption for an ambient temperature of $65°F$. [10+0]

x = Temp (°F) 27 45 72 58 31 60 34 74 --------------------------- y = Power (BTU) 250 285 320 295 265 298 267 321 $n = 8$ x y x² xy y² ------------------ 27 250 729 6750 62500 45 285 2025 12825 81225 72 320 5184 23040 102400 58 295 3364 17110 87025 31 265 961 8215 70225 60 298 3600 17880 88804 34...

Open this answer on its own page →

2075 · 10 marks

Regression Analysis: Normal Stress and Shear Resistance

There is a data inconsistency in the problem statement. The header row lists 9 pairs, but the intro table string lists 10 values for each variable. I will use the 9 clearly-tabulated pairs from the bracketed array: X (Normal stress) 26 25 28 23 27 23 24 28 26 :--:--:--:--:--:--:--:--:--:-- Y (She...

Open this answer on its own page →

Spearman's rank correlation

2078 · 5 marks

Calculate Spearman's rank correlation coefficient for the following ranks given by three judges in a music contest. Indicate which pair of judges has the nearest approaches to music.

$$\begin{array}{c|cccccccccc} \text{1}^{\text{st}}\text{ Judge} & 2 & 1 & 4 & 6 & 5 & 8 & 9 & 10 & 7 & 3 \ \text{2}^{\text{nd}}\text{ Judge} & 4 & 3 & 2 & 5 & 1 & 6 & 8 & 9 & 10 & 7 \ \text{3}^{\text{rd}}\text{ Judge} & 5 & 8 & 4 & 7 & 10 & 2 & 1 & 6 & 9 & 3 \ \end{array}$$

[5]

$n = 10$ competitors. Competitor 1st Judge ($R1$) 2nd Judge ($R2$) 3rd Judge ($R3$) :---::---::---::---: 1 2 4 5 2 1 3 8 3 4 2 4 4 6 5 7 5 5 1 10 6 8 6 2 7 9 8 1 8 10 9 6 9 7 10 9 10 3 7 3 Formula: $$rs = 1 - \frac{6\sum d^2}{n(n^2 - 1)}, \quad n(n^2-1) = 10 \times 99 = 990$$ Comp $R1$ $R2$ $R3$ ...

Open this answer on its own page →

2076 · 5 marks

Question

Following data represent the preference of 10 students studying B.Sc(CSIT) towards two brands of computer namely Lenovo and Acer. Apply appropriate statistical tool to measure whether the brand preference is correlated. Also interpret your result.

$$\begin{array}{|c|c|c|c|c|c|c|c|c|c|c|}\hline \text{Computer} & \text{Student Preference} & & & & & & & & & \ \hline \text{Lenovo} & 5 & 2 & 9 & 8 & 1 & 10 & 3 & 4 & 6 & 7 \ \text{Acer} & 10 & 5 & 1 & 3 & 8 & 6 & 2 & 7 & 9 & 4 \ \hline \end{array}$$

[5]

Note: The question mentions DELL and HP in the text but the table gives Lenovo and Acer. I use the table data (the actual numbers). Ranks by 10 students, $n = 10$: Student Lenovo ($R1$) Acer ($R2$) --------- 1 5 10 2 2 5 3 9 1 4 8 3 5 1 8 6 10 6 7 3 2 8 4 7 9 6 9 10 7 4 Both rows are permutations...

Open this answer on its own page →

2075 · 5 marks

Spearman's Rank Correlation Coefficient

As part of study of the psychological correlates of success in athletes, the following measurements are obtained from members of Nepal national football team. Calculate Spearman's rank correlation coefficient.

$$ \begin{array}{c|cccccccc} \text{Anger} & 6 & 7 & 5 & 21 & 13 & 5 & 13 & 14 \ \text{Vigor} & 30 & 23 & 29 & 22 & 19 & 19 & 28 & 19 \end{array} $$

[5]

Player Anger Vigor ---------------------- 1 6 30 2 7 23 3 5 29 4 21 22 5 13 19 6 5 19 7 13 28 8 14 19 $n = 8$ Anger: values sorted: 5, 5, 6, 7, 13, 13, 14, 21 - Two 5's occupy positions 1, 2 → rank $\frac{1+2}{2} = 1.5$ - 6 → rank 3 - 7 → rank 4 - Two 13's occupy positions 5, 6 → rank

Open this answer on its own page →