Paired data · ordinary least squares · residual audit
Linear Regression Calculator
Fit a straight line to three through eight paired observations, predict at a selected x, inspect r and R², and review every fitted value and residual. The scatter view keeps the model attached to the actual data rather than reducing it to one equation.
Enter paired observations
Fit dashboard
Observation-by-observation audit
| Pair | x | y | Fitted ŷ | Residual y−ŷ | Squared residual |
|---|---|---|---|---|---|
| 1 | 1.0000 | 2.0000 | 2.8000 | −0.8000 | 0.6400 |
| 2 | 2.0000 | 4.0000 | 3.4000 | 0.6000 | 0.3600 |
| 3 | 3.0000 | 5.0000 | 4.0000 | 1.0000 | 1.0000 |
| 4 | 4.0000 | 4.0000 | 4.6000 | −0.6000 | 0.3600 |
| 5 | 5.0000 | 5.0000 | 5.2000 | −0.2000 | 0.0400 |
| 6 | |||||
| 7 | |||||
| 8 |
The fitted association is positive. The line explains 60.00% of the sample variation in y. Prediction x = 6 lies outside the observed x range, so it is an extrapolation.
What simple linear regression estimates
Simple ordinary least squares regression finds the straight line that minimizes the sum of squared vertical residuals. A residual is observed y minus fitted ŷ at the same x. Squaring prevents positive and negative residuals from canceling and gives larger misses more influence. The fitted equation has an intercept b₀ and a slope b₁.
The slope estimates the average change in fitted y for a one-unit increase in x within the data’s range. The intercept is the fitted y when x equals zero. An intercept can be mathematically necessary even when x = 0 is outside the observed range or has no practical meaning. Interpret it only when zero is a relevant and supported reference.
b₁ = Σ(xᵢ−x̄)(yᵢ−ȳ) / Σ(xᵢ−x̄)²
b₀ = ȳ − b₁x̄ · ŷᵢ = b₀ + b₁xᵢ · eᵢ = yᵢ − ŷᵢ
Worked five-point fit
The default observations are (1,2), (2,4), (3,5), (4,4), and (5,5). Their x mean is 3 and y mean is 4. The centered x sum of squares Sxx is 10, the centered y sum of squares Syy is 6, and the cross-product sum Sxy is 6. Therefore the slope is 6/10 = 0.6 and the intercept is 4 − 0.6 × 3 = 2.2.
The fitted line is ŷ = 2.2 + 0.6x. At x values 1 through 5, the fitted values are 2.8, 3.4, 4.0, 4.6, and 5.2. Subtracting those from the observations yields residuals −0.8, 0.6, 1.0, −0.6, and −0.2. They sum to zero apart from floating-point rounding, as expected for an ordinary least-squares line with an intercept. Their squared values sum to SSE = 2.4.
With n − 2 = 3 residual degrees of freedom, the residual standard error is √(2.4/3) ≈ 0.8944 y units. Correlation r = Sxy/√(SxxSyy) ≈ 0.7746, and R² = r² = 0.6000. The prediction at x = 6 is 5.8, but six lies beyond the observed range 1 through 5. The arithmetic is valid; its interpretation is extrapolation.
Read slope, r, and R² separately
Slope preserves units. If x is hours and y is dollars, 0.6 means 0.6 dollars of fitted change per additional hour. Correlation is unitless and describes the direction and strength of linear association in the sample, from −1 to 1. Rescaling dollars to cents changes the slope but not r.
R² is the proportion of sample variation in y accounted for by the fitted line relative to a model that always predicts ȳ. Here, 0.60 means a 60% reduction in squared error on these observations. It does not mean 60% of each outcome is caused by x, that 60% of future predictions will be correct, or that the model has a 60% probability of being true.
A large |r| does not guarantee an appropriate line. One influential point can create a strong correlation, and a curved relationship can have a weak linear correlation despite a systematic pattern. Always inspect the scatter and residuals. The visual graph here rescales both axes to the entered points; perceived slope angle depends on that display scaling, while the numeric slope retains the real units.
Assumptions for inference
Linearity
The conditional mean of y is represented adequately by a straight line over the x range of interest. Curved residual patterns argue against this form.
Independent errors
Residuals should not be correlated across time, household, classroom, patient, or other clusters unless the model handles that structure.
Constant variance
The residual spread should be reasonably stable across fitted values for conventional ordinary-least-squares standard errors.
Distribution for small-sample tests
Normal-error assumptions support familiar t and F inference in small samples. The fitted coefficients themselves can still be computed without normality.
This calculator supplies descriptive coefficients, a residual standard error, and a slope t ratio. It does not calculate a p-value or interval, because robust, clustered, weighted, or design-based inference may require a different standard error and degrees of freedom. Use statistical software and a prespecified model for consequential inference.
Prediction is not the same as causation
A regression line describes association conditional on the entered pairs. It cannot by itself establish that changing x will change y. Confounders, reverse causation, selection, measurement error, and missing data can all produce or distort an association. Random assignment or a credible causal design supplies evidence beyond the fitted line.
A point prediction ŷ estimates the conditional mean under the linear model. An individual future observation usually varies around that mean, so its prediction interval is wider than a confidence interval for the mean response. This calculator intentionally does not display a false sense of certainty from only three to eight points.
Extrapolation is especially risky. The line can cross impossible values, while real systems saturate, change policy regimes, or bend. If x = 6 is outside a sample ending at 5, label the estimate and seek data near 6.
Residual audit workflow
- Check sign and size. Positive residuals sit above the line; negative residuals sit below it. Values close to zero fit closely in y units.
- Look for shape. A run of negative, then positive, then negative residuals can indicate curvature. Alternating or time-ordered patterns may indicate dependence.
- Look for changing spread. A funnel shape suggests nonconstant variance and may call for transformation, weighted least squares, or robust standard errors.
- Inspect unusual x-values. A point far from the x mean can have high leverage. It may strongly affect slope even when its vertical residual is not the largest.
- Verify data entry. An outlier may be real, but misplaced decimals, swapped columns, and unit mismatches should be ruled out before modeling.
Do not delete a point solely because it weakens R². Removal needs a documented data-quality or design reason, and sensitivity results should be reported. A model that only looks strong after discretionary exclusions may not generalize.
Algebraic checks for the fitted line
A least-squares line with an intercept passes through the coordinate (x̄, ȳ). Substituting x̄ into b₀ + b₁x should therefore return ȳ. The residuals should sum to approximately zero, and their cross-product with x should also be approximately zero. These normal-equation identities provide stronger checks than merely reproducing a rounded slope.
The total centered variation in y splits into explained and residual pieces: SST = SSR + SSE. Consequently, R² can be calculated as SSR/SST or 1 − SSE/SST. For simple regression with an intercept and nonconstant y, it also equals r². If independently calculated versions disagree beyond rounding, inspect the means, residual signs, and whether an intercept was included.
Changing units has predictable effects. Adding a constant to every x changes the intercept but not the slope, residuals, r, or R². Multiplying every x by 100 divides the slope by 100. Adding a constant to y shifts the intercept; multiplying y rescales slope, intercept, and residual standard error. Correlation and R² remain unchanged under positive linear rescaling.
Data preparation and units
Each active row must contain a finite x and y. Duplicate x-values are allowed; they represent repeated observations at the same predictor level and can help reveal response variability. However, all x-values cannot be identical because Sxx would be zero and no slope could be estimated.
Rows should represent the unit of analysis. Repeated measurements from one person are not automatically independent persons, and monthly observations may be serially correlated. Aggregating data changes the question and can change correlation. Keep a record of how the pairs were selected and whether exclusions occurred.
Centering x can make the intercept more meaningful without changing slope or fitted values. For example, using age minus 50 makes the intercept the fitted outcome at age 50. Log transformations change interpretation: a regression of log y on x estimates multiplicative patterns, not the same additive change shown here.
Sample-size boundary: Eight rows are suitable for learning and quick auditing, not for replacing a full statistical workflow. Important analyses need all observations, diagnostics, uncertainty estimates, and design-aware methods.
Frequently asked questions
Why do residuals sum to zero?
For ordinary least squares with an intercept, the normal equations make the unweighted sample residuals sum to zero apart from rounding.
Can R² be negative here?
Not for a standard least-squares line with a fitted intercept evaluated on the same data. Other definitions or out-of-sample evaluations can be negative.
What if all x-values are equal?
Sxx is zero, so the slope is undefined. Add variation in x or use a different summary question.
Does a significant slope prove x causes y?
No. Statistical association and causal identification are separate issues.
Are duplicate x-values allowed?
Yes. They are useful replicates, provided the observations and errors are handled according to the study design.
Why is prediction outside the x range flagged?
It extends the fitted line into an unobserved region where the relationship may change, so the estimate is extrapolation.
If residuals reveal systematic curvature or proportional growth, compare the straight-line fit with the exponential regression calculator.
References
NIST/SEMATECH e-Handbook — linear least squares regression
NIST/SEMATECH e-Handbook — least-squares criterion
NIST Statistical Reference Datasets — linear least-squares background