Simple Linear Regression and Prediction Guide
Simple linear regression estimates y = a + bx from paired data. The fitted equation can produce a point prediction, but predictions outside the observed X range should be identified as extrapolation.
Method
- Enter paired X and Y values.
- Calculate slope and intercept from the observed pairs.
- Inspect r and r² as association and fit summaries.
- Optionally enter an X value, substitute it into the fitted line and check whether that X is inside the observed range.
Worked example
X = 1, 2, 3 and Y = 2, 4, 6 produces y = 2x.
Entering X = 4 predicts Y = 8, but 4 is beyond the observed X range and is therefore extrapolation.
Notes
- A slope cannot be estimated when every X value is identical.
- Extrapolation can be much less reliable than interpolation.
- A predicted value and r² do not prove a causal model.
Reproduce a small least-squares regression by hand
Take four illustrative paired measurements, X = [1, 2, 3, 4] and Y = [2, 4, 3, 5]. The means are X̄ = 2.5 and Ȳ = 3.5. The sum of products of centered deviations is 4 and the sum of squared X deviations is 5. With an intercept in the model, the ordinary least-squares slope is 4 ÷ 5 = 0.80, and the intercept is 3.5 − (0.80 × 2.5) = 1.50. The fitted equation is predicted Y = 1.50 + 0.80 × X.
The fitted values for the four observed X values are 2.30, 3.10, 3.90 and 4.70. Their errors, actual minus fitted, are −0.30, 0.90, −0.90 and 0.30. Squaring and summing produces residual sum of squares 1.80. The total sum of squares around the observed Y mean is 5.00, so the sample R-squared is 1 − (1.80 ÷ 5.00) = 0.64. This is consistent with the paired-data Pearson correlation of 0.80, whose square is also 0.64 in a simple linear regression with an intercept.
A hypothetical prediction at X = 5 would be 5.50, but this lies beyond the observed X range of 1 to 4. It is extrapolation, not an observed result or a reliable forecast. Four observations also cannot establish that a linear model is suitable for a wider population; examine a scatterplot, residuals, unusual observations and the domain process before drawing conclusions.
- Illustrative observations: (1,2), (2,4), (3,3), (4,5).
- Slope = 0.80; intercept = 1.50; fitted equation: Y = 1.50 + 0.80 × X.
- Residual sum of squares = 1.80; total sum of squares = 5.00; R-squared = 0.64.
Interpret the line in the units of the variables
A simple least-squares regression estimates an intercept and slope for predicting Y from X. The slope describes the expected change in predicted Y for a one-unit increase in X under the fitted linear model. The intercept is the predicted Y when X equals zero, which may or may not be meaningful in the observed range.
R-squared describes the fraction of variation in Y accounted for by the fitted linear relationship in this dataset. It does not measure causation or guarantee accurate individual predictions.
Check residual patterns and avoid careless extrapolation
A straight-line fit can be misleading when residuals show curvature, changing spread or influential points. Inspect the data and residual behavior rather than relying only on the fitted equation.
Predictions far outside the observed X range are extrapolations. The linear relationship may not continue there, so label those predictions as more uncertain instead of presenting them with the same confidence as interpolation.
Editorial review and limitations
Continue with the related tools
Use the linked tools for your own inputs and scenarios.
- Pearson Correlation & Covariance Calculator — Calculate Pearson r, r squared, sample covariance and population covariance from two paired numeric data sets.
- Mean Median Mode Calculator — Calculate mean, median, mode, minimum and maximum from a list of numeric values.
- Standard Deviation Calculator — Calculate population and sample variance and standard deviation from a numeric data set.