Linear Regression & R-Squared in Excel
Learn all three ways to run ordinary least-squares (OLS) linear regression in Excel—dynamic cell formulas, scatter-plot trendlines, and the full Data Analysis ToolPak summary output.
=SLOPE(B2:B11, A2:A11) | =INTERCEPT(B2:B11, A2:A11) | =RSQ(B2:B11, A2:A11)
Method 1: Dynamic Cell Formulas (Best for Live Dashboards)
Assume your predictor variable X (e.g., Hours Studied) is in A2:A7 and your response variable Y (e.g., Exam Score) is in B2:B7. Notice that Excel requires Y first, then X in every regression function:
| Metric | Formula | Interpretation |
|---|---|---|
| Slope (m or b₁) | =SLOPE(B2:B7, A2:A7) |
Predicted change in Y for each +1 unit increase in X. |
| Y-Intercept (b or b₀) | =INTERCEPT(B2:B7, A2:A7) |
Predicted value of Y when X = 0. |
| Correlation (r) | =CORREL(A2:A7, B2:B7) |
Direction and strength of the linear relationship (−1 to +1). |
| R-Squared (R²) | =RSQ(B2:B7, A2:A7) |
Proportion of variation in Y explained by the linear relationship with X. |
| Prediction ŷ at x = 8 | =FORECAST.LINEAR(8, B2:B7, A2:A7) |
Directly plugs x = 8 into the fitted least-squares line. |
| Residual Std Error (sₑ) | =STEYX(B2:B7, A2:A7) |
Typical vertical prediction error between actual Y and predicted ŷ. |
Worked Spreadsheet Example
Sample Data: Hours Studied (A2:A6) = 2, 4, 5, 7, 9; Quiz Score (B2:B6) = 62, 70, 76, 84, 93.
=SLOPE(B2:B6, A2:A6)→ 4.452 (each extra hour studied predicts +4.45 points on the quiz).=INTERCEPT(B2:B6, A2:A6)→ 52.96 (baseline predicted score at 0 study hours).=CORREL(A2:A6, B2:B6)→ 0.9985 (very strong positive linear association).=RSQ(B2:B6, A2:A6)→ 0.9970 (99.7% of the variation in quiz scores is explained by hours studied).=FORECAST.LINEAR(6, B2:B6, A2:A6)→ 79.67 predicted score for 6 hours of study.
Method 2: Scatter Plot Trendline (Best for Quick Visual Checks)
- Select both columns (X on the left, Y on the right) and click Insert → Charts → Scatter (X, Y).
- Click the chart, press the + icon (Chart Elements), hover over Trendline, and pick More Options.
- Choose Linear and check both Display Equation on chart and Display R-squared value on chart.
- Inspect the scatter plot visually before trusting R²: if points curve in an arc (U-shape or exponential), a linear model is inappropriate even if R² looks high!
Method 3: Reading Data Analysis ToolPak Regression Output
When a college statistics or econometrics course asks for p-values, standard errors of slope, or multiple regression, enable the ToolPak (File → Options → Add-ins → Analysis ToolPak) and run Data → Data Analysis → Regression:
| Output Field | What It Means in Plain English |
|---|---|
| Multiple R | Absolute value of correlation |r| in simple regression (always positive; check slope sign for direction!). |
| R Square | Same as =RSQ(); percentage of Y variance explained by the predictor(s). |
| Adjusted R Square | Penalizes adding useless predictors—always report Adjusted R² for multiple regression. |
| Standard Error | Same as =STEYX(); typical prediction error in Y’s original units. |
| Coefficients & P-value | The slope row’s P-value tests H₀: β₁ = 0 (no linear relationship). A P-value < 0.05 indicates a statistically significant slope. |
known_x’s before known_y’s in SLOPE, INTERCEPT, or STEYX silently regresses X on Y instead of Y on X—giving the wrong equation. (2) Never use a Line Chart instead of an XY Scatter Chart—Line charts treat X values as evenly spaced categories (1, 2, 3...) and compute completely wrong trendline slopes!
Frequently Asked Questions
Why is Multiple R positive in Excel Regression output when my slope is negative?
Excel’s Regression ToolPak reports Multiple R as √(R²), which is always non-negative. If your slope coefficient is negative, the true Pearson correlation r is −Multiple R (confirmed by =CORREL()).
Does high R-squared prove X causes Y?
No. R² measures linear association only. Without a randomized controlled experiment, a third confounding variable could drive both X and Y.
How do I get residuals in Excel to check linear regression assumptions?
Either check the Residuals and Residual Plots boxes in the Data Analysis ToolPak dialog, or add a column =B2 - ($E$1*A2 + $E$2) where E1 holds slope and E2 holds intercept, then plot residuals against X. Random scatter around 0 confirms linearity.