CalculatorForEver
MATH / CALCULATOR

Linear Regression Calculator

Calculate linear regression with explicit statistical conventions, probability limits and worked results.

For paired data, slope b = Σ(x − x̄)(y − ȳ)/Σ(x − x̄)² and intercept a = ȳ − bx̄. The fitted line is ŷ = a + bx. The x values must vary so the slope denominator is positive.

Your numbers

BROWSER-LOCAL INPUTS

Your inputs stay in this browser. No account needed.

RESULT

Your result

Enter your values and select Calculate.

Check the units and assumptions before using this result.

METHOD

How the linear regression calculator works

How to use this calculator

Enter observations or distribution parameters in the stated units. Calculate, then read the method and assumptions before drawing a statistical conclusion.

What the result means

An ordinary least-squares line predicts a numerical y from a numerical x by minimizing the sum of squared vertical residuals. Enter paired x and y lists in the same observation order. Calculator ForEver reports slope, intercept, fitted values and residuals, with a prediction at a supplied x. A fitted line describes the entered sample; extrapolating beyond its observed x range introduces assumptions that a good in-sample fit cannot verify.

The formula

Slope = Σ(x−x̄)(y−ȳ)/Σ(x−x̄)²; intercept = ȳ − slope×x̄

A worked example

The pairs (1,3),(2,5),(3,7) fit y=2x+1.

Assumptions & methodology

A numerical summary does not establish sampling validity, practical importance or causation. Check the model and input assumptions before interpreting a probability. Results are rounded for display; intermediate calculations retain precision. This tool is informational and does not replace institutional or professional guidance.

References

OpenStax: the regression equation · NIST: linear least squares regression

WORK THROUGH THE DETAILS

Using your linear regression result

Fit a small example with visible residuals

Use x values 1, 2 and 3 with y values 2, 3 and 5. The x mean is two and the y mean is 10/3. The cross-deviation sum is three and the x squared-deviation sum is two, giving slope 1.5. The intercept is 1/3. Fitted values are approximately 1.8333, 3.3333 and 4.8333. Residuals are approximately 0.1667, −0.3333 and 0.1667. At x = 4, the line predicts approximately 6.3333, beyond the observed x range.

Interpret R-squared within the fitted sample

For the example, the residual sum of squares is 1/6 and the total squared deviation of y is 14/3. Thus R² = 1 − (1/6)/(14/3) = 27/28, approximately 0.964286. This describes the share of centered y variation accounted for by the fitted line in that sample. It does not establish prediction accuracy on new data or prove a causal mechanism. A near-perfect fit from three observations can still be a weak basis for a forecast.

Recognize the boundary cases of a straight-line fit

If every x value is the same, the requested slope is undefined because there is no horizontal variation. If y is constant while x varies, a horizontal fitted line can exist even though Pearson correlation and the usual R-squared interpretation have a zero-variance denominator. The calculator should preserve that distinction rather than invent correlation. It also does not fit curved relationships, account for measurement error in x, calculate a prediction interval or correct dependent observations. A prediction shown here is a point on the fitted line, not a bound on an individual future measurement.

Keep the fitted intercept within its measurement context

The intercept is the fitted y value at x = 0. In the three-point example it is one third, even though the entered x values begin at one. A mathematical line needs an intercept, but the corresponding zero-input prediction may fall outside the observed domain or have no physical interpretation. Centering x at its sample mean changes the numerical intercept to the fitted mean response at that center while leaving predicted values for the original observations unchanged. Record which x definition you used before comparing intercepts between reports. A different intercept alone does not establish that the underlying relationship changed.

INTERPRETATION

Understanding linear regression results

Preserve the original pairing and units

The first x and first y must come from the same observation, followed by the next pair in matching order. Sorting one column alone changes the relationship. The slope has y-units per x-unit, while the intercept has y-units. Rescaling x changes the numerical slope even when the fitted relationship describes the same measurements. Do not mix meters and centimeters within one x list or compare coefficients without checking the measurement scale.

Read a fitted value and residual together

For an entered x, the line supplies a fitted y. A residual is observed y minus fitted y; positive residuals lie above the fitted line. Squaring residuals makes large departures influential in ordinary least squares. An unusual x value can also change the fitted slope even if its own residual appears small. Examine the observations rather than relying on one coefficient or on an attractive line through the chart.

RELATED GUIDES

Related questions and worked examples

Read a worked explanation before trying another calculation.

QUESTIONS

Linear Regression questions

Does swapping x and y give the inverse fitted line?+

Usually no. Ordinary least squares minimizes vertical residuals for the chosen response. Reversing the variables changes that optimization problem.

Does a high R-squared prove that x causes y?+

No. Confounding, shared trends or selected samples can produce a strong association. Causal claims need a design and assumptions outside this fit.