By Grant D. McKenzie – Updated Aug 30, 2022

Linear regression is a foundational tool in engineering and scientific analysis, enabling you to model the relationship between two quantitative variables. By fitting the best‑fit line y = mx + b to your data, you can quantify how changes in the independent variable x influence the dependent variable y and calculate the correlation coefficient for further insight.
Separate the x and y values into two columns (e.g., in Excel or Google Sheets). Ensure that each x has a corresponding y; mismatched counts lead to incorrect results or errors.
Example set:
x = (6, 5, 11, 7, 5, 4, 4)y = (2, 3, 9, 1, 8, 7, 5)Calculate the average of each column:
x_avg = (6 + 5 + 11 + 7 + 5 + 4 + 4) ÷ 7 = 6y_avg = (2 + 3 + 9 + 1 + 8 + 7 + 5) ÷ 7 = 5Create centered values by subtracting the respective means:
x1 = (0, -1, 5, 1, -1, -2, -2)y1 = (-3, -2, 4, -4, 3, 2, 0)Compute the product for each pair:
x1y1 = (0, 2, 20, -4, -3, -4, 0)Square each x1 element:
x1^2 = (0, 1, 25, 1, 1, 4, 4)sum_x1y1 = 0 + 2 + 20 - 4 - 3 - 4 + 0 = 11sum_x1^2 = 0 + 1 + 25 + 1 + 1 + 4 + 4 = 36The slope m is calculated as:
m = sum_x1y1 ÷ sum_x1^2 = 11 ÷ 36 ≈ 0.306
For a quick manual calculation, use the formula: m = Σ[(xᵢ - x_avg)(yᵢ - y_avg)] / Σ[(xᵢ - x_avg)²]. In Excel, the SLOPE function accomplishes this in one step.
Linear regression functions are widely available in spreadsheets, and mastering the slope calculation enhances your analytical toolkit for engineering, data science, and research.