Skip to content

Linear Regression Calculator

Fit a straight line through paired x and y data to describe and predict how y changes with x.

What this answers

This calculator answers "what straight-line relationship best describes how y changes with x, and how much can I trust a prediction from it?" It fits the line that minimizes the total squared vertical distance between the line and every data point (ordinary least squares), then reports how much of y's variation the line explains, whether the slope is statistically distinguishable from 0, and how precise a prediction from the line actually is.

When to use it, and when not to

Use this for a genuinely linear relationship between one predictor and one outcome. If a scatter plot of your data shows an obvious curve, a straight line will systematically misfit it, no matter how the numbers otherwise look; consider the Polynomial Regression engine or a variable transformation instead. This model also assumes one predictor; for more than one, use Multiple Linear Regression.

How it is calculated

The slope and intercept come from closed-form ordinary least squares formulas, no iterative fitting required for one predictor. R-squared is the proportion of y's total variation explained by the fitted line. The slope's confidence interval and p-value use a t distribution with n minus 2 degrees of freedom. Prediction at a specific x value comes in two forms: a mean-response interval (how precisely you know the average y at that x) and a wider individual-prediction interval (how precisely you can predict one new observation at that x), which are never the same width and should not be substituted for each other.

Worked example

For x equal to 0 through 4 and y exactly equal to 2 plus 3 times x with no noise: the fitted intercept is exactly 2, the fitted slope is exactly 3, and R-squared is exactly 1, since every point sits perfectly on the line. Real data will never fit this perfectly; the default example data above shows a more realistic near-linear pattern with small deviations from the line.

Assumption audit

Calculated from your data: sample size, whether x has any variation to fit a slope against, and whether a requested prediction point falls outside your observed x range (flagged as extrapolation).
Evidence to review: the shape of the residuals (actual y minus predicted y). A curved pattern in the residuals suggests the straight-line model is misspecified even if R-squared looks reasonable; a residual plot makes this visible in a way the summary numbers alone do not.
You must verify: that x was measured or set independently of y, that the observations are independent of one another, and that predicting from this model within (or especially outside) your data's range is actually appropriate for your question.

What this result does not mean

A significant slope and a high R-squared describe how well a straight line fits your observed data. Neither establishes that x causes y to change; a fitted association is always conditional on the model and data you gave it, not proof of a causal mechanism. Extrapolating a prediction to an x value far outside your observed range assumes the same linear pattern continues there, an assumption the data itself cannot confirm.

Limitations

This model will fit a straight line even to clearly nonlinear data, since it does not check its own assumptions for you. Always look at a scatter plot and the residuals, not R-squared alone, before trusting a linear fit.