Let’s consider a simple example of linear regression using some sample data. Suppose we have data on the number of hours studied (X) and the corresponding exam scores (Y) for a group of students. We want to use linear regression to model the relationship between the number of hours studied and exam scores and make predictions for future students.

Here is the sample data:

Hours Studied (X) | Exam Score (Y) |
---|---|

2 | 70 |

3 | 85 |

5 | 95 |

7 | 80 |

8 | 90 |

Step 1: Calculate the Mean

First, we calculate the mean of both X and Y:

Mean of X (X̄) = (2 + 3 + 5 + 7 + 8) / 5 = 5

Mean of Y (Ȳ) = (70 + 85 + 95 + 80 + 90) / 5 = 84

Step 2: Calculate the Deviations

Next, we calculate the deviations of each data point from the mean:

Deviation of X (X – X̄):

(2 – 5) = -3

(3 – 5) = -2

(5 – 5) = 0

(7 – 5) = 2

(8 – 5) = 3

Deviation of Y (Y – Ȳ):

(70 – 84) = -14

(85 – 84) = 1

(95 – 84) = 11

(80 – 84) = -4

(90 – 84) = 6

Step 3: Calculate the Covariance

Now, we calculate the covariance between X and Y:

Cov(X, Y) = (∑((X – X̄) * (Y – Ȳ))) / (n – 1)

Cov(X, Y) = ((-3 * -14) + (-2 * 1) + (0 * 11) + (2 * -4) + (3 * 6)) / (5 – 1)

Cov(X, Y) = (-42 + (-2) + 0 + (-8) + 18) / 4

Cov(X, Y) = -34 / 4

Cov(X, Y) = -8.5

Step 4: Calculate the Variance of X

Next, we calculate the variance of X:

Var(X) = (∑((X – X̄)^2)) / (n – 1)

Var(X) = ((-3)^2 + (-2)^2 + (0)^2 + (2)^2 + (3)^2) / (5 – 1)

Var(X) = (9 + 4 + 0 + 4 + 9) / 4

Var(X) = 26 / 4

Var(X) = 6.5

Step 5: Calculate the Regression Coefficients

Finally, we calculate the regression coefficients:

β1 = Cov(X, Y) / Var(X)

β1 = -8.5 / 6.5

β1 = -1.31 (approximately)

β0 = Ȳ – (β1 * X̄)

β0 = 84 – (-1.31 * 5)

β0 = 84 + 6.55

β0 = 90.55 (approximately)

So, the regression equation is: Y = 90.55 – 1.31X

Step 6: Make Predictions

Using the regression equation, we can make predictions for exam scores based on the number of hours studied. For example, if a student studies 6 hours, the predicted exam score would be:

Y = 90.55 – 1.31 * 6

Y = 90.55 – 7.86

Y = 82.69 (approximately)

So, based on the linear regression model, a student who studies 6 hours is predicted to score approximately 82.69 in the exam.

FacebookGoogleTwitterMicrosoft