Written and maintained by CASRAI Editorial Board
Published
On this page
The slope of a linear regression is the number that tells you how much the predicted outcome (y) changes, on average, for each one-unit increase in the predictor (x). In the fitted line ŷ = a + bx, the slope is b. A slope of 3.89 means the line predicts 3.89 more units of y for every extra unit of x. This page gives the formula, a fully worked example with the arithmetic shown, reading guidance, reporting format and code for Excel, R and Python.
What is the slope of a linear regression line?
Simple linear regression fits a straight line to paired observations by least squares: the intercept and slope are chosen to minimise the sum of the squared vertical deviations between the data and the line (NIST/SEMATECH e-Handbook, section 4.1.4.1). In that notation the line is β0 + β1x, where β1 is the slope and β0 is the intercept. OpenStax Introductory Statistics describes the slope as how the dependent variable changes, on average, for every one-unit increase in the independent variable.
Three phrasings point to the same quantity: the linear regression slope, the slope in linear regression and the slope of a linear regression line. Textbooks also call it the regression coefficient, the slope coefficient, b, or β1. Two things distinguish it from the correlation coefficient r: the slope carries the units of y per unit of x, and it is not bounded between -1 and 1.
Linear regression slope formula
For n paired observations (xi, yi), OpenStax gives two equivalent forms of the least-squares slope:
- Deviation form: b = Σ(xi − x̄)(yi − ȳ) / Σ(xi − x̄)²
- Correlation form: b = r × (sy / sx)
The intercept follows from a = ȳ − b·x̄, which is why the fitted line always passes through the point (x̄, ȳ).
| Symbol | Meaning |
|---|---|
| b (or β1) | Estimated slope: predicted change in y per one-unit increase in x |
| a (or β0) | Estimated intercept: predicted y when x = 0 |
| x̄, ȳ | Sample means of x and y |
| r | Sample correlation coefficient between x and y |
| sx, sy | Sample standard deviations of x and y |
| ŷ | Predicted (fitted) value of y from the line |
The correlation form explains two properties at once. Because sx and sy are positive, the slope always has the same sign as r. And because it is r rescaled by sy/sx, changing the units of either variable changes the slope but leaves r unchanged.
Worked example with real numbers
Illustrative data, invented for teaching and not drawn from any study. Suppose eight students record weekly study hours (x) and a test score out of 100 (y): x = 1, 2, 3, 4, 5, 6, 7, 8 and y = 52, 55, 61, 60, 68, 71, 75, 79. The data table below the article lists each pair with its fitted value, residual and the products used here.
- Means. x̄ = 36 / 8 = 4.5 and ȳ = 521 / 8 = 65.125.
- Sum of squares of x. Σ(x − x̄)² = 12.25 + 6.25 + 2.25 + 0.25 + 0.25 + 2.25 + 6.25 + 12.25 = 42.
- Sum of cross-products. Σ(x − x̄)(y − ȳ) = 163.5.
- Slope. b = 163.5 / 42 = 3.8929, about 3.89.
- Intercept. a = 65.125 − 3.8929 × 4.5 = 47.607, about 47.61.
The fitted line is ŷ = 47.61 + 3.89x. Check with the correlation form: Σ(y − ȳ)² = 650.875, so r = 163.5 / √(42 × 650.875) = .989, sx = √(42/7) = 2.449 and sy = √(650.875/7) = 9.643. Then b = .989 × (9.643 / 2.449) = 3.89, the same value.
Standard error, t test and confidence interval for the slope
The slope from a sample is an estimate, so it has sampling error. The residual sum of squares for this fit is 14.393, giving a residual standard deviation s = √(14.393 / (8 − 2)) = 1.549. The standard error of the slope is SEb = s / √Σ(x − x̄)² = 1.549 / √42 = 0.239. (For the residual standard deviation itself, see our guide to the standard error of the regression.)
- t test of H0: slope = 0. t = 3.893 / 0.239 = 16.29 with 6 degrees of freedom, p < .001.
- 95% confidence interval. The two-sided critical value for 6 degrees of freedom is 2.447, so 3.893 ± 2.447 × 0.239 gives [3.31, 4.48].
- Coefficient of determination. R² = .989² = .978, so about 98% of the variation in these scores is accounted for by the line.
In words: each additional weekly study hour is associated with a predicted score about 3.9 points higher, and the interval suggests the population slope is plausibly between 3.3 and 4.5 points per hour.
How to interpret the slope of a linear regression
The slope is read in the units of the data. The table gives reading guidance for common situations.
| What you see | How to read it |
|---|---|
| Positive slope (b > 0) | Predicted y rises as x rises; r has the same positive sign. |
| Negative slope (b < 0) | Predicted y falls as x rises; r is negative. |
| Slope near 0 | The line is nearly flat, so x adds little to the prediction of y. Test it against zero rather than judging by eye; the t test above does this. |
| Large slope | Not automatically a strong relationship. The size depends on the units: measuring x in minutes instead of hours divides the slope by 60 without changing r. |
| Wide confidence interval | The sample pins the slope down poorly; report the interval, not just the point estimate. |
| Slope significant, R² small | A real average trend can coexist with a lot of scatter; use R² and residuals to judge predictive usefulness. See correlation coefficient vs coefficient of determination. |
A worked reading of the example: ŷ = 47.61 + 3.89x predicts a score of 47.61 for someone who studies zero hours and 3.89 more points for each added hour. The intercept is an extrapolation to x = 0, which lies outside the observed range of 1 to 8 hours.
Assumptions and common mistakes
- Extrapolating beyond the data. OpenStax warns against using a line outside the x range it was fitted on: in its exam example, with x values from 65 to 75, the line should not be used to predict for a score of 50. Here, predicting for 20 weekly hours would predict a score above 100.
- Reading slope as causation. The slope describes an average association in the sample. Whether x causes y depends on the study design, not the regression arithmetic.
- Confusing slope with correlation. The slope depends on units; r does not. Compare strength with r or R², not with b.
- Swapping x and y. The regression of y on x gives a different slope from the regression of x on y unless the correlation is perfect, because b = r × sy/sx is not symmetric.
- Ignoring the inference assumptions. SciPy’s documentation notes that the standard error of the slope assumes normally distributed residuals. Non-constant residual spread also undermines it; see what is homoscedasticity.
- Treating a straight line as given. Plot the data and the residuals first; a curved pattern means the single slope misdescribes the relationship.
How to report the slope in APA style
The APA Style numbers and statistics guide (APA 7th edition, 2024 handout) says to italicise Latin letters used as statistical symbols, set Greek letters in standard type, report t and similar inferential statistics to two decimals, give exact p values to two or three decimals, and write p < .001 for very small values. It also says to leave a space around operators and not to define standard symbols such as t, df and p, but to define less common abbreviations such as CI. That handout does not prescribe a specific symbol or layout for slope coefficients, so the sentence below applies its general rules.
Weekly study hours predicted test score, b = 3.89, 95% CI [3.31, 4.48], t(6) = 16.29, p < .001, R² = .98.
Pair the slope with its units in the prose (points per hour) and report the interval so readers can judge precision. If you report several coefficients, a table is clearer than a long sentence. For the surrounding results-section structure, see our guide to statistical analysis in Excel for the spreadsheet side of the workflow.
How to calculate the slope in Excel, R or Python
Excel
Microsoft’s SLOPE function takes the y values first, then the x values:
=SLOPE(B2:B9, A2:A9) // B = scores (y), A = hours (x); returns 3.892857
Reversing the arguments silently returns the slope of x on y. Per Microsoft’s documentation, text, logical values and empty cells inside the ranges are ignored, cells containing zero are included, empty ranges or ranges of unequal length return #N/A, and data in which every x value is identical returns #DIV/0!.
R
hours <- 1:8
score <- c(52, 55, 61, 60, 68, 71, 75, 79)
fit <- lm(score ~ hours)
coef(fit)
# (Intercept) hours
# 47.607143 3.892857
In the formula score ~ hours, the response goes on the left. coef() returns the named vector of coefficients; summary(fit) adds standard errors and p values.
Python
from scipy.stats import linregress
hours = [1, 2, 3, 4, 5, 6, 7, 8]
score = [52, 55, 61, 60, 68, 71, 75, 79]
res = linregress(hours, score)
print(res.slope, res.intercept, res.rvalue**2, res.stderr, res.pvalue)
# slope 3.892857, intercept 47.607143, R squared 0.977887, stderr 0.238986
Here x comes first. SciPy documents slope, intercept, rvalue (its square is the coefficient of determination), pvalue (a Wald test with a t-distribution, with the null hypothesis that the slope is zero) and stderr (the standard error of the slope, assuming normally distributed residuals).
Frequently asked questions
What is the slope in linear regression?
It is the coefficient b in ŷ = a + bx: the average change in predicted y for each one-unit increase in x. It is estimated by least squares as b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)².
How do you find the slope of a linear regression line?
Compute the means, the sum of squared deviations of x and the sum of cross-products, then divide the cross-products by the squared deviations. Or multiply r by sy/sx. Software such as Excel’s SLOPE, R’s lm() or SciPy’s linregress does this directly.
Can the regression slope be greater than 1?
Yes. Unlike r, the slope is not bounded; its size depends on the units of x and y. In the example above it is 3.89.
What does a slope of zero mean?
The fitted line is horizontal, so the predicted y is the same (the mean of y) for every x, and r is also zero. In a sample the slope is rarely exactly zero, so use the t test or confidence interval to judge whether it differs from zero.
Is the slope the same as the correlation coefficient?
No. They share a sign and are linked by b = r × sy/sx, but the slope has units and r is unitless.
Sources
- OpenStax, Introductory Statistics, section 12.3 The Regression Equation, https://openstax.org/books/introductory-statistics/pages/12-3-the-regression-equation (read 2026-11-12).
- NIST/SEMATECH e-Handbook of Statistical Methods, section 4.1.4.1 Linear Least Squares Regression, https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm (read 2026-11-12).
- Microsoft Support, SLOPE function, https://support.microsoft.com/en-us/office/slope-function-11fb8f97-3117-4813-98aa-61d7e01276b9 (read 2026-11-12).
- SciPy documentation, scipy.stats.linregress, https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html (read 2026-11-12).
- R documentation, lm: Fitting Linear Models, https://stat.ethz.ch/R-manual/R-devel/library/stats/html/lm.html (read 2026-11-12).
- APA Style, Numbers and Statistics Guide (APA 7th edition, 2024), https://apastyle.apa.org/instructional-aids/numbers-statistics-guide.pdf (read 2026-11-12).
Data: Worked example: study hours and test score, least-squares fit (n = 8)
Illustrative teaching data (invented, not from a study) for eight students with fitted values, residuals and the deviation products used to compute the least-squares slope 3.8929 and intercept 47.6071; computed by the page author using the formulas in OpenStax Introductory Statistics section 12.3.
| Observation | Weekly study hours (x) (hours) | Test score (y) (points) | Fitted score (points) | Residual (points) | (x - mean x)^2 | (x - mean x)(y - mean y) |
|---|---|---|---|---|---|---|
| Student 1 | 1 | 52 | 51.5 | 0.5 | 12.25 | 45.938 |
| Student 2 | 2 | 55 | 55.39 | -0.39 | 6.25 | 25.312 |
| Student 3 | 3 | 61 | 59.29 | 1.71 | 2.25 | 6.188 |
| Student 4 | 4 | 60 | 63.18 | -3.18 | 0.25 | 2.562 |
| Student 5 | 5 | 68 | 67.07 | 0.93 | 0.25 | 1.438 |
| Student 6 | 6 | 71 | 70.96 | 0.04 | 2.25 | 8.812 |
| Student 7 | 7 | 75 | 74.86 | 0.14 | 6.25 | 24.688 |
| Student 8 | 8 | 79 | 78.75 | 0.25 | 12.25 | 48.562 |
Sources
- OpenStax Introductory Statistics, 12.3 The Regression Equation (accessed 2026-11-12)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







