QUANTITATIVE ANALYSIS · BEGINNER GUIDE

Simple Linear Regression by Hand: A Small Example

Calculate the slope and intercept for a tiny dataset, then check what the fitted line can and cannot tell you.

Worked example · linear regression by handUpdated October 31, 2026

Quick answer: In simple linear regression, the least-squares slope is the covariance of x and y divided by the variance of x. The intercept makes the line pass through the sample means. The fitted line summarizes a pattern; it does not prove cause.

Infographic for linear regression by hand: Compute the two sample means, then Find the least-squares slope, then Calculate the intercept, then Check residuals and prediction range.
Infographic: a practical sequenceKeep the question, design and assumptions in view from start to finish.
Toy study-hours example. 1 hour: 50 quiz points; 2 hours: 60 quiz points; 3 hours: 70 quiz points.
Toy study-hours exampleThese constructed points lie on ŷ=40+10x; real observations would vary.

What this method answers

The line is ŷ=b₀+b₁x. Least squares chooses b₀ and b₁ to minimize squared residuals. With few observations, one unusual point can strongly change the result.

Use the hand calculation to understand a basic two-variable fit. For real work, use software and inspect residuals, uncertainty, influential observations and the sampling design.

Before running a calculation, write down the population and the exact quantity you want to estimate. A method name alone does not define the question, the comparison or the assumptions.

Steps to follow

  1. Plot x against y and inspect whether a line is sensible.
  2. Calculate x̄ and ȳ from the training observations.
  3. Estimate slope and intercept using least squares.
  4. Check residuals and avoid unsupported extrapolation.

Keep a record of exclusions, recoding decisions and software settings. That makes the analysis easier to check and repeat.

Worked example

A tutor records study hours and a short quiz score for three learners. The values are invented for arithmetic practice.

Hours xScore y
150
260
370

The means are x̄=2 and ȳ=60. The slope is 10 points per hour in this straight toy sample. The intercept is b₀=ȳ−b₁x̄=60−20=40, so ŷ=40+10x.

Interpret the result carefully

At 2 hours, ŷ=60. The line matches all three constructed points exactly. That perfect fit is a feature of this tiny example, not proof that study time determines scores.

Limit to keep in mind: The arithmetic omits uncertainty, measurement error, nonlinear patterns and confounding. Predictions outside observed hours may be misleading.

When reporting an analysis, include the sample size, estimate, units and uncertainty. Explain why the method fits the sampling and measurement design. Separate planned tests from exploratory checks, and avoid saying that association proves a cause.

Frequently asked questions

Why is the intercept 40?

It is the predicted score at zero study hours; that may not be meaningful.

Does this prove each hour adds 10 points?

No. The example has three invented values and cannot establish cause.

What is a residual?

Observed y minus fitted prediction ŷ for a case.

Does a high R² guarantee good predictions?

No. Validate on representative held-out data.

Sources and next steps