Linear Regression Calculator With Prediction Intervals

You have pairs of numbers, such as distance and delivery time or a car’s age and its price, and you want to know what Y will be at an X you haven’t measured. Linear regression draws the straight line that leaves the smallest total of squared misses. It tells you how much Y changes per unit of X and how far a new value is likely to land from that line.

Paste your X and Y values and the calculator returns the equation, R² and r, a t-test and an interval for the slope, and predictions with both kinds of interval. It also shows a residual plot and a table that flags points pulling hard on the line. Four more models are on the menu (through the origin, exponential, logarithmic and power). Separate tabs fit a line from summary statistics alone and test whether two groups share the same slope. It opens on ten deliveries.

Linear Regression Calculator

Separate values with commas, spaces or new lines, in the same order in both boxes. You can also paste two columns (X and Y) into the X box and leave Y empty.

Linear regression –
Scatter plot
Step by step
    Residuals and influence (orange rows deserve a look)

    Reading the Output From Top to Bottom

    A courier logs ten deliveries: the distance in kilometres and the minutes from pickup to drop-off.

    Distance (km)23.5567.591112.51416
    Time (min)14172221272934364144

    The fitted line is ŷ = 9.7534 + 2.1672x. Each part has a plain meaning:

    • Slope b = 2.1672. Each extra kilometre adds about 2.17 minutes on average. The 95% interval for the slope runs from 2.001 to 2.3335, so a true rate much below 2 minutes per km doesn’t fit these data.
    • Intercept a = 9.7534. At 0 km the line gives about 9.75 minutes. That reads as fixed time per delivery (loading, parking, the walk to the door), but 0 km lies outside the data, so treat it as a rough figure rather than a measured one.
    • R² = 0.9912 and r = 0.9956. 99.12% of the variation in delivery times lines up with distance.
    • Standard error of estimate s = 1.0082. A typical delivery sits about one minute above or below the line. This number is in minutes, and it answers “how far off will I be?” better than R² does.
    • Slope test: t = 30.06, p = 1.628 × 10⁻⁹. If distance had no linear link to time, a slope this large would almost never appear by chance. The F test (F = 903.55, df 1 and 8) gives the same p, because with one predictor F is t².
    • Intercept test: t = 13.93. This checks whether the line could pass through zero. For deliveries it clearly can’t.

    Below the numbers, the scatter plot shows the line with two shaded bands, and a residual plot shows each point’s miss against its fitted value. The table lists every pair with its fitted value, residual, standardized residual, leverage and Cook’s distance.

    Working the Line by Hand

    Five sums are all you need: n = 10, Σx = 86.5, Σy = 285, Σx² = 943.75 and Σxy = 2,889. From them:

    QuantityFormulaDelivery data
    Meansx̄ = Σx ÷ n, ȳ = Σy ÷ n8.65 km, 28.5 min
    SxxΣx² − (Σx)² ÷ n943.75 − 748.225 = 195.525
    SxyΣxy − Σx·Σy ÷ n2,889 − 2,465.25 = 423.75
    Slopeb = Sxy ÷ Sxx423.75 ÷ 195.525 = 2.1672
    Intercepta = ȳ − b·x̄28.5 − 2.1672 × 8.65 = 9.7534
    Residual sum of squaresSSE = Σ(y − ŷ)²8.1312
    Standard errors = √(SSE ÷ (n − 2))√(8.1312 ÷ 8) = 1.0082
    SE of the slopes ÷ √Sxx0.0721

    The divisor in s is n − 2 because two numbers (a and b) were estimated from the data. This is also why a line needs at least three points before any test or interval means anything: two points always fit exactly, with nothing left over to measure the scatter.

    There is a quick check that catches a swapped slope and intercept. The least-squares line always passes through the point (x̄, ȳ). Here 9.7534 + 2.1672 × 8.65 = 28.5, which is ȳ. If the two numbers were swapped, you would get 2.1672 + 9.7534 × 8.65 = 86.53, nowhere near 28.5. Published examples do sometimes print the slope and intercept the wrong way round, so it is worth doing.

    Keep more decimals than you think you need when you copy the equation. Rounded to ŷ = 9.75 + 2.17x, the line gives 31.45 minutes at 10 km instead of 31.4258, a small gap. At 200 km it gives 443.75 instead of 443.20, because the rounding error in the slope is multiplied by X. The calculator’s “Round to” menu goes up to 6 places for this reason.

    In Excel or Google Sheets, =FORECAST.LINEAR(10, B2:B11, A2:A11) returns 31.4258 for a 10 km delivery and =STEYX(B2:B11, A2:A11) returns s = 1.0082. In both, the Y range comes before the X range. =LINEST(B2:B11, A2:A11, TRUE, TRUE) returns the full block of slope, intercept, their standard errors, R², s, F, the degrees of freedom and the sums of squares.

    One Delivery or the Average Delivery? Two Intervals

    Ask the calculator about a 10 km trip and it gives ŷ = 31.4258 minutes with two ranges:

    QuestionInterval (95%)Width
    What is the average time of all 10 km deliveries?30.66 to 32.19 min1.54 min
    How long will the next 10 km delivery take?28.98 to 33.87 min4.90 min

    The first is the confidence interval for the mean response. It reflects only the uncertainty in where the line sits, and it shrinks toward zero as you collect more deliveries. The second is the prediction interval. It adds the scatter of single deliveries around the line, the “1 +” inside s·√(1 + h), and so it never gets narrower than about ±t*·s, however much data you have. If a customer asks when the parcel will arrive, the second range is the honest answer. The Intervals menu changes the level for both: at 90% the next 10 km delivery falls between 29.45 and 33.40 minutes, at 99% between 27.86 and 34.99. A higher level buys more certainty with a wider range.

    Both widen as X moves away from x̄. The term h = 1/n + (x₀ − x̄)² ÷ Sxx is 0.1093 at 10 km, close to the middle of the data. At 25 km, far beyond the longest trip, the prediction interval grows to 60.28 to 67.59 minutes. That is the subject of the next section.

    Past the Edge of Your Data

    Ten example listings for one car model give these prices by age:

    Age (years)12345678910
    Price ($1,000s)26.022.519.416.214.112.010.48.67.56.3

    A straight line fits with R² = 0.9662: price = 26.16 − 2.1564 × age. Inside the data it is never far off. Push it outward and it falls apart. The line reaches $0 at 12.1 years and says a 14-year-old car is worth −$4,029.

    The warning was already in the residuals. In age order they run +2.0, +0.65, −0.29, −1.33, −1.28, −1.22, −0.67, −0.31, +0.75, +1.7: positive at both ends and negative in the middle. That U shape means the data bend and the line doesn’t.

    Cars lose a share of their value each year, not a fixed amount, which is an exponential pattern. Choose Exponential in the Model menu and the calculator fits ln(price) against age, then converts back. The result is price = 30.787 · e^(−0.1576 × age), or about 14.6% lost per year, with R² = 0.9994 on the original price scale. It gives a 14-year-old car about $3,389 instead of a negative number. Even so, no model checks itself beyond the ages it was fitted on. When a prediction falls outside the X values you entered, the calculator marks it “outside the data” and says so in a note.

    The menu covers these shapes:

    Pattern in the scatterModelFitted as
    Steady change per unitStraight liney on x
    Steady percentage change per unitExponentialln y on x
    Fast rise that levels offLogarithmicy on ln x
    Same percentage change per percentage change (scaling laws)Powerln y on ln x

    When a straight line is chosen, the calculator also tries the other shapes on your data. If one beats the line’s R² by 0.02 or more on the same Y scale, it says so.

    What the Residual Plot Is Telling You

    A residual is the observed Y minus the line’s prediction. Plotted against the fitted values, residuals from a suitable model look like a shapeless band around zero, as the delivery data do. The shapes worth spotting:

    • A curve (U or upside-down U): the relationship bends, as with the car prices. Try another model.
    • A funnel that widens to one side: the scatter grows with Y. The line itself can still be fine, but the p-values and intervals assume even scatter, so they will be too narrow at one end and too wide at the other.
    • One point far from the rest: check it before anything else.

    The table puts numbers on that last case. A standardized residual beyond ±2 marks a point the line misses badly. Leverage h measures how far a point’s X sits from the others. It is flagged above 4/n, twice its average value. Cook’s distance combines both into how much the whole line would move without that point, and the calculator flags values above 4/n. Flagged rows turn orange.

    Suppose the last delivery was typed as 61 km instead of 16. That one point has leverage 0.954 and Cook’s distance 82.45. It drags the slope from 2.17 to 0.42 minutes per km and drops R² to 0.506. The calculator names the point and shows what the slope would be without it. It does not delete anything, because a point that looks wrong can also be the most informative one you have.

    What the Tests Assume, and Which Output Checks Each

    The equation itself is just arithmetic and needs no assumptions. The p-values, the slope interval and both prediction intervals rest on four conditions, and each one has a place in the output where you can look:

    ConditionWhat breaks if it failsWhere to check
    The relationship is straightPredictions miss in a pattern; the slope averages two different trendsResidual plot (curve), the shape note
    Errors are independentp-values and intervals come out too optimisticHow the data were collected: repeated readings of one person, or values in time order, are not independent of each other
    Scatter is even across XIntervals are too narrow in one region and too wide in anotherResidual plot (funnel)
    Errors are roughly normalPrediction intervals for single values are off; the slope test leans on this less as the sample growsStandardized residuals: about 1 in 20 beyond ±2 is expected; several beyond ±3 is a warning

    Independence is the one no plot in the tool can confirm. If the ten deliveries were all made by one courier on one afternoon in heavy rain, the line describes that afternoon, not deliveries in general.

    Only Have r, the Means and the SDs?

    Textbook problems and published studies sometimes give only summary numbers, not the raw data. The Summary stats tab needs only n, the two means, the two SDs and r, because:

    b = r × s_y ÷ s_x and a = ȳ − b·x̄

    For 40 students, hours of study average 6.2 (SD 2.5) and test scores average 71 (SD 12), with r = 0.58:

    • b = 0.58 × 12 ÷ 2.5 = 2.784 points per hour, a = 71 − 2.784 × 6.2 = 53.7392.
    • R² = 0.58² = 0.3364, s = 9.9032, slope t = 4.389, p = 8.76 × 10⁻⁵.
    • At 9 hours: ŷ = 78.80, with a 95% prediction interval of 58.18 to 99.41. A single student can land almost anywhere in that range, even though the slope is clearly significant.

    The Find X for Y box reads the line backwards: for a score of 85, x = (85 − 53.7392) ÷ 2.784 = 11.23 hours. That is not the same as regressing hours on scores, which gives 6.2 + 0.58 × (2.5 ÷ 12) × (85 − 71) = 7.89 hours. The two regression lines only coincide when r is ±1. Use the backward reading when X was set or controlled, as in a calibration curve. Fit hours on scores when you want the typical X for students who reached a given Y.

    Forcing the Line Through Zero

    Some software offers a “zero intercept” option, and it can look attractive when Y should be 0 at X = 0. Through the origin, the delivery line becomes ŷ = 3.0612x. Its residual sum of squares is 205.22, 25 times the 8.1312 of the ordinary line. Yet it reports R² = 0.9773, which looks nearly as good.

    That R² is measured differently. Without an intercept, the total is Σy² instead of Σ(y − ȳ)², so a large R² comes easily. Measured the ordinary way, 1 − 205.22 ÷ 926.5, the same line scores only 0.7785. The calculator labels it “R² about the origin” and warns that it can’t be compared with an ordinary R². Use the zero intercept only when theory demands a zero intercept, the data reach close to X = 0 and the ordinary intercept’s interval includes 0. For deliveries the intercept test (t = 13.93) says the fixed time is real, and forcing it away pushes the slope up to 3.06 minutes per km.

    Do Two Groups Rise at the Same Rate?

    The Compare two lines tab fits a separate line to each group and tests whether the slopes differ. Take six city deliveries and six motorway deliveries at 2, 4, 6, 8, 10 and 12 km:

    • City: 12, 17, 21, 25, 31, 35 minutes → ŷ = 7.4 + 2.3x
    • Motorway: 13, 16, 18, 21, 23, 26 minutes → ŷ = 10.6 + 1.2714x

    The difference in slopes is 1.0286 minutes per km. The test pools the residual variance of both lines with df = n₁ + n₂ − 4 = 8, giving t = 13.86 and p = 7.1 × 10⁻⁷, with a 95% interval for the difference of 0.857 to 1.200. City kilometres cost about a minute more each. Equal slopes would only mean parallel lines. The motorway line starts higher (10.6 vs 7.4 minutes) even though it climbs more slowly. The test also assumes both groups scatter about equally, and the calculator warns when one group’s residual variance is more than four times the other’s.

    A High R² Is Not the Same as Accurate Predictions

    R² is the share of the variation in Y that the line accounts for. It is not the share of predictions that come out right, and it says little on its own about the size of the errors:

    • It depends on the spread of X. Keep only the deliveries between 5 and 9 km and R² falls from 0.9912 to 0.8665, while the slope stays close to 2.05 minutes per km. Nothing about the courier changed, only the range of trips in the sample.
    • A low R² can come with a real slope. With 500 pairs and r = 0.15, R² is 2.25%, yet the slope’s p-value is 0.00077. X matters, but it explains very little of Y.
    • A high R² can hide the wrong shape. The straight line through the car prices had R² = 0.9662 and still predicted negative prices.

    For “how close will my prediction be?”, read s and the prediction interval. For “is there a linear trend at all?”, read the slope’s p-value and interval. To see how strongly the two variables move together without fitting a line, use the correlation coefficient calculator, and for the slope’s p-value from a t and df you already have, the p-value calculator. The slope between just two points is what the slope calculator gives; regression finds the best single slope through many.

    Why It’s Called Regression: Galton’s Heights

    The name comes from Francis Galton’s 1886 paper “Regression towards Mediocrity in Hereditary Stature” in the Journal of the Anthropological Institute. He compared the heights of 928 adult children with the average height of their two parents (205 sets of parents, with women’s heights multiplied by 1.08 to put them on the male scale). Children of very tall parents were, on average, tall, but less far above the average than their parents. Children of short parents were short, but less so. Galton found that a child’s deviation from the average was about two-thirds of the parents’ deviation.

    The same thing happens in any regression where r is not ±1. In standard units the predicted Y is r times as far from its mean as X is from its own. In the study-hours example, a student 1 SD above average in hours is predicted to be only 0.58 SD above average in score. Regression to the mean explains why a team’s best season can be followed by a more ordinary one, why patients picked for their worst readings on day one can look better on day two without any treatment, and why a line fitted the other way round (X on Y) shows the same effect in reverse. No force pulls values back. Extreme results come partly from chance, and chance does not repeat on demand.