How to do linear regression in Google Sheets

Find the regression line, R², the p-value of the slope and a prediction with built-in functions, then add the trendline to a chart. Worked example with 20 students.

Updated 2026-09-28·3 min read
Quick answer

With x in A2:A21 and y in B2:B21: =SLOPE(B2:B21, A2:A21) gives the slope, =INTERCEPT(B2:B21, A2:A21) the intercept and =RSQ(B2:B21, A2:A21) the R². For standard errors, F and the sums of squares in one go, use =LINEST(B2:B21, A2:A21, TRUE, TRUE). Note that y always comes first.

The example data

Twenty students reported how many hours they studied (column A, x) and their exam score (column B, y). We want to know whether hours predict the score and by how much.

Hours2351467385
Score61607052667771608569
Hours29647101853
Score63807361799053796766

Step 1: the regression line

ValueFormulaResult
Slope (b)=SLOPE(B2:B21, A2:A21)3.6863
Intercept (a)=INTERCEPT(B2:B21, A2:A21)50.8526
R²=RSQ(B2:B21, A2:A21)0.9052
Standard error of the estimate=STEYX(B2:B21, A2:A21)3.2414

The equation is Score = 50.85 + 3.69 × Hours. Each extra hour of study goes with about 3.7 more points, and the model explains 90.5% of the variation in scores.

Step 2: the full output with LINEST

Type this in an empty cell with room for a 5 × 2 block below and to the right:

=LINEST(B2:B21, A2:A21, TRUE, TRUE)
RowColumn 1Column 2Meaning
13.686350.8526Slope, intercept
20.28111.5690Standard error of the slope, of the intercept
30.90523.2414R², standard error of the estimate
4171.9518F statistic, residual degrees of freedom
51806.68189.12Regression sum of squares, residual sum of squares

Step 3: is the slope significant?

LINEST gives no p-values, but you can get them from t = coefficient ÷ standard error:

=T.DIST.2T(ABS(3.6863/0.2811), 18)

t = 13.11 and p = 1.2 × 10−10, so p < .001: hours studied is a significant predictor. In simple regression, the F test gives the same p-value (=F.DIST.RT(171.95, 1, 18)).

The 95% confidence interval of the slope is 3.6863 ± T.INV.2T(0.05, 18) × 0.2811 = [3.10, 4.28].

Step 4: make a prediction

=FORECAST(6, B2:B21, A2:A21)

A student who studies 6 hours is predicted to score 72.97. Avoid predicting far outside the range of your data (here, 1 to 10 hours): the line may not hold there.

Do it in one click with ExplainStats

Select your data, click Run: full results table, assumption checks, a plain-language interpretation and an APA line, free in Google Sheets.

Get ExplainStats free

Step 5: draw it

  1. Select A1:B21 and choose Insert › Chart. Pick Scatter chart as the chart type.
  2. In Customize › Series, tick Trendline.
  3. Set Label to Use equation and tick Show R².

Check the assumptions

  • Linearity: the scatter plot should look like a straight band, not a curve.
  • Independence: one row per person, no repeated measurements.
  • Constant spread: plot the residuals (observed − predicted) against x. They should form an even cloud around 0, not a funnel.
  • Normal residuals: here a Shapiro-Wilk test on the residuals gives p = .47, which is fine.

A strong relationship does not prove that one variable causes the other. Students who study more may also sleep better or attend more classes.

How to report it (APA style)

A simple linear regression showed that hours of study significantly predicted exam scores, b = 3.69, 95% CI [3.10, 4.28], t(18) = 13.11, p < .001. The model explained 90.5% of the variance in scores, R² = .91, F(1, 18) = 171.95, p < .001.

Frequently asked questions

How do I get the p-value of a regression in Google Sheets?

Divide the slope by its standard error (both come from LINEST with verbose set to TRUE) to get t, then use =T.DIST.2T(ABS(t), n-2) for a simple regression.

What is the difference between R² and adjusted R²?

R² is the share of the variation in y explained by the model. Adjusted R² corrects it for the number of predictors: 1 - (1 - R²) × (n - 1) / (n - k - 1). It matters mostly in multiple regression.

Can Google Sheets do multiple regression?

Yes. Give LINEST several adjacent x columns, for example =LINEST(C2:C21, A2:B21, TRUE, TRUE). The coefficients come back in reverse order: last x column first, intercept last.

How do I show the regression equation on a chart?

Insert a scatter chart, then in the chart editor open Customize, Series, tick Trendline and set the label to Use equation. You can also tick Show R².

Do it in one click with ExplainStats

Select your data, click Run: full results table, assumption checks, a plain-language interpretation and an APA line, free in Google Sheets.

Get ExplainStats free