Sure! Let’s consider another example of linear regression with a different set of sample data. Suppose we have data on the number of years of work experience (X) and the corresponding salary (Y) for a group of employees. We want to use linear regression to model the relationship between work experience and salary and make predictions for future employees.
Here is the sample data:
Years of Work Experience (X) | Salary (Y) |
---|---|
2 | 50000 |
3 | 60000 |
5 | 75000 |
7 | 90000 |
8 | 95000 |
Step 1: Calculate the Mean
Mean of X (X̄) = (2 + 3 + 5 + 7 + 8) / 5 = 5
Mean of Y (Ȳ) = (50000 + 60000 + 75000 + 90000 + 95000) / 5 = 74000
Step 2: Calculate the Deviations
Deviation of X (X – X̄):
(2 – 5) = -3
(3 – 5) = -2
(5 – 5) = 0
(7 – 5) = 2
(8 – 5) = 3
Deviation of Y (Y – Ȳ):
(50000 – 74000) = -24000
(60000 – 74000) = -14000
(75000 – 74000) = 1000
(90000 – 74000) = 16000
(95000 – 74000) = 21000
Step 3: Calculate the Covariance
Cov(X, Y) = (∑((X – X̄) * (Y – Ȳ))) / (n – 1)
Cov(X, Y) = ((-3 * -24000) + (-2 * -14000) + (0 * 1000) + (2 * 16000) + (3 * 21000)) / (5 – 1)
Cov(X, Y) = (72000 + 28000 + 0 + 32000 + 63000) / 4
Cov(X, Y) = 195000 / 4
Cov(X, Y) = 48750
Step 4: 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
β1 = Cov(X, Y) / Var(X)
β1 = 48750 / 6.5
β1 = 7500 (approximately)
β0 = Ȳ – (β1 * X̄)
β0 = 74000 – (7500 * 5)
β0 = 74000 – 37500
β0 = 36500 (approximately)
So, the regression equation is: Y = 36500 + 7500X
Step 6: Make Predictions
Using the regression equation, we can make predictions for salaries based on the number of years of work experience. For example, if an employee has 6 years of work experience, the predicted salary would be:
Y = 36500 + 7500 * 6
Y = 36500 + 45000
Y = 81500 (approximately)
So, based on the linear regression model, an employee with 6 years of work experience is predicted to have a salary of approximately 81500.