Home
Try:
Enter at least two (x, y) pairs to fit a line. Up to 30 data points can be included. All values must be numeric; negative and decimal values are accepted. Predictions and standard errors require n ≥ 3.

What Is Simple Linear Regression?

Simple linear regression fits a straight line y = m·x + b through a set of (x, y) data points. The line is chosen to minimise the sum of squared vertical distances between the points and the line — a method known as ordinary least squares (OLS). The result is the "best-fitting" straight line for the data, in the sense that no other straight line gives a smaller sum of squared residuals.

Simple linear regression has a single predictor x and a single response y. When there are two or more predictors (x₁, x₂, …), the procedure generalises to multiple linear regression, which requires matrix algebra and is handled by a different calculator.

The Regression Equation

The fitted line is written in slope–intercept form:

ŷ = m·x + b

Here ŷ denotes the predicted value of y for a given x. The slope m is the expected change in y for a one-unit increase in x. The intercept b is the predicted value of y when x = 0.

Formulas Used by the Calculator

Let n be the number of data points and let x̄ = Σx/n and ȳ = Σy/n be the sample means. The least-squares slope and intercept are:

m = Sxy / Sxx
b = ȳ − m·x̄

where

Sxx = Σx² − (Σx)²/n = Σ(x − x̄)²
Sxy = Σxy − (Σx)(Σy)/n = Σ(x − x̄)(y − ȳ)
Syy = Σy² − (Σy)²/n = Σ(y − ȳ)²

The quantities Sxx, Sxy and Syy are called the corrected sums of squares (and cross-products). They are the fundamental building blocks of nearly every regression statistic.

Coefficient of determination (R²)

R² = Sxy² / (Sxx · Syy) = 1 − SSres / SStot

R² is the proportion of the total variation in y that is explained by the linear relationship with x. It ranges from 0 to 1. A value of 1 means the line passes through every data point; a value of 0 means the line explains none of the variability.

Correlation coefficient (r)

r = Sxy / √(Sxx · Syy)

r is the Pearson correlation coefficient. It ranges from −1 to +1 and carries the direction of the relationship. In simple linear regression, R² = r², so the two statistics convey the same information about the strength of the linear relationship — only the scale differs.

Standard errors (n ≥ 3)

The standard error of the estimate measures the typical size of the residuals:

Se = √((Syy − m·Sxy) / (n − 2))

The standard errors of the slope and intercept are:

SE(m) = Se / √Sxx
SE(b) = Se · √(1/n + x̄² / Sxx)

These are used to form t-statistics and confidence intervals for the slope and intercept. The calculator reports them whenever n ≥ 3.

Special Cases and Edge Conditions

  • n < 2: a line cannot be fitted; at least two points are required.
  • All x-values identical: Sxx = 0 and the slope is undefined. The fitted line would be vertical (x = constant) and cannot be written as y = mx + b.
  • All y-values identical: Syy = 0 and R² is undefined; r is also undefined. The fitted line is horizontal (y = ȳ).
  • Perfect linear relationship: R² = 1, r = ±1, and every residual is zero.
  • Outliers: a single extreme point can dramatically change the slope and intercept. Always plot the data before drawing conclusions from a regression line.

Where Simple Linear Regression Is Used

  • Trend lines: sales vs advertising spend, revenue vs time.
  • Calibration: converting instrument readings to physical units via a linear calibration curve.
  • Prediction: estimating a response for a new x-value based on historical data.
  • Hypothesis testing: testing whether a slope differs significantly from zero (i.e. whether x and y are linearly related).
  • Dose–response modelling: response as a function of dose in biology and pharmacology.
  • Engineering: stress–strain curves, load–deflection relationships, and similar linear calibrations.

How the Calculator Works

  • Parses the (x, y) pairs and validates them.
  • Computes the raw sums Σx, Σy, Σxy, Σx², Σy².
  • Computes the corrected sums Sxx, Sxy, Syy.
  • Calculates the slope m = Sxy/Sxx and intercept b = ȳ − m·x̄.
  • Calculates R², r and (for n ≥ 3) the standard errors Se, SE(m), SE(b).
  • Produces predicted values and residuals for each data point, and a summary table.
  • Renders an inline SVG scatter plot with the fitted line so you can visually inspect the fit.
  • Computes a prediction for any user-supplied x using the fitted equation.

Supported Input Format

InputMeaningResult
(1, 2), (2, 4), (3, 6)Perfect positive correlationy = 2x, R² = 1
(1, 10), (2, 8), (3, 6)Perfect negative correlationy = −2x + 12, R² = 1
(1, 2), (2, 4), (3, 5), (4, 4), (5, 5)Mild positivey ≈ 0.6x + 2.2, R² ≈ 0.6
(1, 5), (2, 3), (3, 8), (4, 2), (5, 7)Weak relationshipsmall R²
(0, 1), (1, 3), (2, 5), (3, 7), (4, 9)Known line y = 2x + 1y = 2x + 1, R² = 1
n = 2 pointsLine exactly through bothR² = 1 (standard errors not available)

Assumptions and Limitations

  • The fitted model is linear in both the parameters and in x. Curved patterns require a polynomial or non-linear model.
  • At least two data points with distinct x-values are required. Standard errors need n ≥ 3.
  • Up to 30 data points can be entered in one batch.
  • The calculator assumes the standard linear-regression assumptions (linearity, independent errors, constant variance, normally distributed errors). Inference based on the standard errors is only valid when these assumptions hold.
  • Results are rounded to the selected precision. Use a higher precision for intermediate calculations if needed.

❓ Simple Linear Regression FAQ

What is simple linear regression?

Simple linear regression is a statistical method that fits a straight line y = mx + b through a set of (x, y) data points by minimising the sum of squared vertical distances between the points and the line. It is used to model and predict the relationship between a single predictor x and a response y.

How do I calculate the slope and intercept by hand?

For n data points compute Σx, Σy, Σxy, Σx² and Σy². Then Sxx = Σx² − (Σx)²/n and Sxy = Σxy − (Σx)(Σy)/n. The slope is m = Sxy/Sxx and the intercept is b = ȳ − m·x̄. The regression line is y = mx + b.

What do the slope and intercept mean?

The slope m is the expected change in y for a one-unit increase in x. The intercept b is the predicted value of y when x = 0. A positive slope means y tends to increase as x increases; a negative slope means y tends to decrease as x increases.

What is R² and what does it tell me?

R² (the coefficient of determination) is the proportion of the variance in y explained by the linear relationship with x. It ranges from 0 to 1. R² = 1 means the line passes through every point; R² = 0 means the line explains none of the variation. In simple linear regression, R² = r².

What is the difference between R² and r?

r is the Pearson correlation coefficient; it ranges from −1 to +1 and carries the direction of the relationship. R² is the square of r and ranges from 0 to 1; it measures the fraction of variance explained. In simple linear regression r = ±√R², with the sign matching the slope.

What is the least-squares method?

The least-squares method chooses the slope and intercept that minimise the sum of squared residuals Σ(yᵢ − ŷᵢ)². Squaring prevents positive and negative errors from cancelling and penalises large deviations. The resulting line is the least-squares regression line and is unique as long as not all x-values are identical.

What if all my x-values are the same?

If every x-value is identical then Sxx = 0. The slope is undefined and the regression line is vertical (x = constant), which cannot be expressed in the form y = mx + b. The calculator reports an error in this case.

How many data points do I need?

At minimum you need two data points with different x-values to fit a line. To compute the standard error of the estimate and the standard errors of the slope and intercept you need at least three points (n ≥ 3). More points generally give more reliable estimates.

What is the standard error of the estimate?

The standard error of the estimate (Se) is the square root of the residual variance: Se = √(Σ(yᵢ − ŷᵢ)² / (n − 2)). It measures the typical size of the residuals — how far points typically sit from the fitted line. It is reported whenever n ≥ 3.

Can I use this calculator for multiple linear regression?

No — this tool fits simple linear regression with one predictor x. Multiple linear regression with two or more predictors requires matrix algebra and is handled by a different calculator.

How can I check my answer?

For each data point compute the predicted value ŷ = mx + b and the residual e = y − ŷ. The residuals should sum to zero (within rounding). Also check that the line passes through (x̄, ȳ). Both conditions follow from the least-squares normal equations.

What does a negative slope mean?

A negative slope means that as x increases, y tends to decrease. The correlation coefficient r will also be negative. The strength of the negative relationship is measured by the magnitude of r (or R²): r close to −1 indicates a strong negative linear relationship.