Find a course

Module 3: Inference and DiagnosticsLesson 6 of 1214 min

Inference for the Slope

Test whether a slope is real with a t-test, build a confidence interval, read regression output and tell prediction intervals from confidence intervals.

Step 1 of 14Learn

Would another sample tell the same story?

The house price analyst's slope of $150 per square foot came from 52 sales last spring. If she had collected a different set of 52 sales, the slope would have been different: maybe $138, maybe $171. Her slope is an estimate of a true underlying relationship, and it has sampling error just like a sample mean.

That raises the questions of statistical inference. Is there really a relationship between floor area and price in this market, or could a slope this large arise by chance from data with no relationship? And what range of true slopes is consistent with the data?

To answer them, statisticians imagine a population regression model:

y = β₀ + β₁x + ε

Here β₀ and β₁ (Greek beta) are the true intercept and slope for the whole population of houses, and ε (epsilon) is random error: the part of each house's price not explained by its size. The fitted values b₀ and b₁ are estimates of β₀ and β₁.

The tools are the same ones you may know from comparing means: a standard error, a t statistic, a p-value and a confidence interval. The difference is what they are about: here, the slope of a line. Every regression output from a spreadsheet, Python or R reports these numbers, so knowing how to read them is a core skill.

Step 2 of 14Learn

Standard error, t-test and confidence interval for the slope

The standard error of the slope measures how much b₁ would vary from sample to sample:

SE(b₁) = s_e / √Sxx

where s_e is the residual standard error and Sxx = Σ(x − x̄)². The slope is estimated more precisely when the points sit close to the line (small s_e), when there are many observations, and when the x-values are widely spread out (large Sxx). That last point is useful in study design: measuring houses from 800 to 4,000 square feet pins down the slope much better than measuring houses from 1,800 to 2,200.

To test whether there's any linear relationship, the null hypothesis is H₀: β₁ = 0. The test statistic is

t = b₁ / SE(b₁)

with n − 2 degrees of freedom. A large |t| means the slope is many standard errors away from zero, which would be unlikely if the true slope were zero.

A confidence interval for the true slope is

b₁ ± t* × SE(b₁)

where t* comes from the t distribution with n − 2 degrees of freedom; for 95% confidence and moderately large samples, t* is close to 2.

For the house data: b₁ = 150, SE = 30, n = 52. Then t = 150 / 30 = 5 with 50 degrees of freedom, so p < 0.0001. With t* ≈ 2.01, the 95% interval is 150 ± 60.3, about $90 to $210 per square foot.

Step 3 of 14Practice · Diagram

Testing whether the slope is zero

Which step tells you how many standard errors the slope is away from zero?

Tap the shape that answers the question, then press Check.

Testing whether the slope is zeroProcess diagram: Estimate b₁ → SE(b₁) = s_e / √Sxx → t = b₁ / SE(b₁) → p-value from t with n − 2 df → Decide and report.Estimate b₁SE(b₁) = s_e / √Sxxt = b₁ / SE(b₁)p-value from t with n− 2 dfDecide and report
Estimate b₁

From your one sample.

SE(b₁) = s_e / √Sxx

How much b₁ would wobble across samples.

t = b₁ / SE(b₁)

How many standard errors b₁ is from 0.

p-value from t with n − 2 df
Decide and report

Give the estimate and a confidence interval, not just "significant".

Step 4 of 14Practice · Work it out

A regression of 40 observations gives a slope of 2.4 with a standard error of 0.8. What is the t statistic for testing whether the true slope is zero?

Step 5 of 14Practice · Work it out

A slope is 150 with a standard error of 30, and the critical value for 95% confidence is 2.01. What is the lower end of the 95% confidence interval for the slope?

Step 6 of 14Learn

Reading a regression output table

Regression software summarizes the results in a table like this one for the house data:

EstimateStd. Errort valuep-value
Intercept40,00018,5002.160.036
sqft150305.00< 0.0001

Residual standard error: 52,000 on 50 degrees of freedom. R²: 0.33.

How to read it:

  • Estimate: the fitted coefficients b₀ and b₁. The line is predicted price = 40,000 + 150 × sqft.
  • Std. Error: the standard error of each estimate.
  • t value: estimate divided by standard error.
  • p-value: for the test that the true coefficient is zero. The p-value for the intercept is usually irrelevant, because whether the line crosses zero at 0 square feet is not an interesting question.
  • Residual standard error: typical prediction error, here $52,000, on n − 2 = 50 degrees of freedom, so n = 52.
  • R²: floor area explains 33% of the variation in price.

Notice the combination: a very strong slope (t = 5) with a modest R². The relationship is clearly real, but floor area leaves most of the variation in price unexplained. Location, condition and age matter too. Strong evidence for a relationship and strong predictive power are different things.

Step 7 of 14Practice · Diagram

The 95% interval for the house slope

Which marker lies outside the interval, which is why the slope is significant at 5%?

Tap the shape that answers the question, then press Check.

The 95% interval for the house slopeScale: No relationship (0), Lower end 89.7, Estimate 150, Upper end 210.3.95% confidence interval0501001502000 $ per sq ftNo relationship (0)89.7 $ per sq ftLower end 89.7150 $ per sq ftEstimate 150210 $ per sq ftUpper end 210.3
150 ± 2.01 × 30, using the numbers from the earlier practice question.
No relationship (0)

0 $ per sq ft

Lower end 89.7

89.7 $ per sq ft

Estimate 150

150 $ per sq ft

Upper end 210.3

210 $ per sq ft

Step 8 of 14Practice · Choose one

In a regression output, the slope for "years of experience" predicting salary has p = 0.002. What does this tell you?

Step 9 of 14Learn

Confidence intervals vs prediction intervals

Once you have a line, you can ask two different questions about a value of x, and they have very different uncertainty.

What is the average price of all 2,000-square-foot houses? This is about the mean response at x = 2,000. A confidence interval for the mean response answers it. Its uncertainty comes only from not knowing the true line exactly, and it shrinks toward zero as the sample grows.

What will this particular 2,000-square-foot house sell for? This is about one individual. A prediction interval answers it. It includes the uncertainty about the line plus the scatter of individual houses around the line, which doesn't shrink with more data. Prediction intervals are always wider, often much wider.

For the house model, the 95% confidence interval for the mean price at 2,000 square feet might be $325,000 to $355,000, while the 95% prediction interval for a single house is about $235,000 to $445,000, roughly ±2 residual standard errors.

Both intervals are narrowest at x̄ and widen as you move away from it, because errors in the slope matter more the farther you are from the center of the data. Far from x̄, and especially beyond the range of the data, intervals widen quickly, one more mathematical warning against extrapolation.

Step 10 of 14Compare

Confidence interval vs. prediction interval

AspectConfidence interval (mean)Prediction interval (individual)
QuestionAverage price of all 2,000 sq ft homes?Price of the next 2,000 sq ft home?
Uncertainty includedWhere the line isWhere the line is + one house's scatter
WidthNarrower; shrinks toward 0 as n growsWider; never narrower than about ±2 s_e
Use forPlanning across many unitsOne specific case

Step 11 of 14Note

Step 12 of 14Practice · True or false

For the same value of x, a 95% prediction interval for an individual observation is always wider than a 95% confidence interval for the mean response.

Step 13 of 14Practice · Spot the mistake

A student summarizes this regression output: slope for study hours = 4.5, SE = 1.5, p = 0.004, R² = 0.18, n = 60. Click the two statements that are wrong.

Step 14 of 14Practice · What would you do?

What would you do?

A model predicts the price of used cars from mileage, fit on 400 cars with 10,000 to 150,000 miles. A customer asks: "What will my car, with 60,000 miles, sell for?" Which interval should you give?