Home / Forecasting and Analytics / Linear Regression Forecast Calculator
Forecasting and Analytics
Linear Regression Forecast Calculator (Least-Squares Trend, R2, and Prediction Band)
Fit a straight trend line to a run of past demand and project it forward, with an honest band around the forecast instead of a bare point. Paste your demand series, one value per period, and the tool fits the least-squares line, reports the slope and intercept, and gives you the next-period forecast along with the numbers that say whether to trust it: R2, the correlation r, and the standard error of estimate Se. It also builds a prediction interval around the forecast, so you get a range for the actual future demand rather than a single number that pretends to be exact. On top of the numbers it draws the observed demand, the fitted trend line, and the projected points with a shaded band that fans out the further you extrapolate, so you can see where the line fits, where it strains, and how fast the projection loses certainty. Every value stays in your browser.
Linear regression, sometimes written regresion lineal in Spanish, fits one global straight line through the whole demand history by least squares, choosing the slope and intercept that make the squared gaps between the line and the actual points as small as possible. The slope b is the steady change in demand per period, and the intercept a is where the line crosses at the start, so the equation D = a + b t reads demand as a base level plus a per-period trend. Where a moving average or exponential smoothing carries a running estimate that reacts to each new point, regression commits to a single line for the entire span, which is the right shape when demand climbs or falls at a fairly steady rate and the wrong shape when it wanders, curves, or repeats on a season. This calculator makes both the fit and its limits visible. It gives you the next-period number, grades the fit with R2 and Se, states a plain verdict on whether the trend is real, and draws the prediction band so you can see the projection getting less certain as it runs. It is free, needs no sign-up, and runs entirely in your browser.
In short: linear regression fits demand D against a time index t = 1, 2, 3, …, n by least squares. The slope is b = [ n*sum(t*D) – sum(t)*sum(D) ] / [ n*sum(t^2) – (sum t)^2 ] and the intercept is a = mean(D) – b*mean(t), giving the trend line F(t) = a + b*t, which you project by evaluating at t = n+1, n+2, and so on. The fit is graded with R2 = 1 – SSE/SST, the fraction of demand variation the line explains, with r = sign(b)*sqrt(R2), and with the standard error of estimate Se = sqrt( SSE / (n – 2) ), the typical size of a one-period miss. The prediction interval for an actual future demand is F0 +/- t_crit * Se * sqrt( 1 + 1/n + (t0 – mean t)^2 / Sxx ). On the default rising series of 120, 135, 132, 150, 160, 155, 172, 180 over 8 periods, the fit gives slope b = 8.143 per period, intercept a = 113.86, equation D = 113.86 + 8.143 t, R2 = 0.942, r = 0.971, and Se = 5.34. The next period (t=9) forecasts 187.14, with a 95% prediction interval of 170.58 to 203.71, and the verdict is a significant upward trend (t_stat 9.88).
next-period forecast
187.14next-period forecast
- Trend equation
- D = 113.86 + 8.143 t
- Slope b (per period)
- 8.143
- Intercept a
- 113.86
- R2 (fit)
- 0.942
- Standard error (Se)
- 5.34
- 95% band (next period)
- 170.58 to 203.71
- Trend verdict
- Significant upward trend
Fitted on 8 periods. R2 = 94.2% of the demand variation is explained by the straight-line trend. The band is the prediction interval (fans out as you project further).
How the calculator works
The tool does the same work you would do by hand to fit a trend line and then check it, only faster and with the fit statistics and the prediction band attached. You give it a demand history, one value per period, and it lines the values up against a time index t = 1, 2, 3, and so on, one step per period. It then finds the least-squares line, the single straight line that makes the squared gaps between the line and the actual demand as small as they can be, and reports its slope and intercept. From that line it computes the forecast for the next period, grades how well the line fits with R2 and the standard error, and builds an interval around the forecast so you read a range rather than a lone number. You read the next-period forecast at the top, the trend equation and its slope and intercept just below, and the quality of the fit and the band under those.
The fit is a plain calculation on the sums of the series. Fit demand D against the evenly spaced time index t = 1, 2, 3, …, n. The slope is b = [ n*sum(t*D) – sum(t)*sum(D) ] / [ n*sum(t^2) – (sum t)^2 ], and the intercept is a = mean(D) – b*mean(t). The trend value for any period is F(t) = a + b*t, so you project the forecast forward by evaluating the line at t = n+1, n+2, and however many periods out you asked for. The slope b is the change in demand per period and the intercept a is the fitted level at t = 0; the tool labels both, because the notation flips between books, some writing the line as a + bx and school algebra writing it as ax + b. Here a is always the intercept and b is always the slope.
Grading the fit uses two sums of squares. SSE = sum( (D – F)^2 ) is the squared error left after the line, the part the line does not explain, and SST = sum( (D – mean D)^2 ) is the total squared variation in demand around its own average. From those, R2 = 1 – SSE/SST is the fraction of the demand variation the trend line explains, and r = sign(b)*sqrt(R2) is the correlation, which carries the sign of the slope. The standard error of estimate is Se = sqrt( SSE / (n – 2) ), dividing by n – 2 because two numbers, the slope and the intercept, were estimated from the data; Se is the typical size of a one-period miss, in the units of demand. This work sits inside the Forecasting and Analytics silo and feeds the wider Supply Chain hub, because a demand forecast is the number the rest of the planning chain runs on.
The sums table and the prediction band
Everything the line needs comes from a small table of sums, and the tool builds it for you. For a series over n periods you need sum(t), sum(D), sum(t*D), and sum(t^2). From the default series of 120, 135, 132, 150, 160, 155, 172, 180 with n = 8, those come out to sum(t) = 36, sum(D) = 1204, sum(t*D) = 5760, and sum(t^2) = 204, with mean(t) = 4.5 and mean(D) = 150.5. Define Sxx = sum(t^2) – (sum t)^2 / n, which measures how spread out the time index is; here Sxx = 204 – 36^2 / 8 = 42. Feeding the sums into the slope formula gives b = 8.143 and then a = 150.5 – 8.143 * 4.5 = 113.86, so the fitted line is D = 113.86 + 8.143 t.
The band around the forecast comes from Se, Sxx, and a Student-t value. Let t_crit be the Student-t value for n – 2 degrees of freedom at the confidence level you chose. There are two bands, and they answer two different questions. The prediction interval, for an actual future demand, is F0 +/- t_crit * Se * sqrt( 1 + 1/n + (t0 – mean t)^2 / Sxx ). The confidence interval, for the average trend level, is F0 +/- t_crit * Se * sqrt( 1/n + (t0 – mean t)^2 / Sxx ), the same expression without the leading 1. Both widen as t0 moves away from mean(t), because the term (t0 – mean t)^2 / Sxx grows, so a forecast far out into the future carries a wider band than one near the middle of the history. That is why the shaded band on the chart fans out as the projection runs, and why far extrapolation is less certain than a step or two ahead.
One more number turns the slope into a verdict. The slope significance is t_stat = b / (Se / sqrt(Sxx)). A large absolute t_stat, together with an R2 well above 0, means the trend is real and the line is worth projecting. A near-zero slope, a small t_stat, or a low R2 means there is no real trend, and a straight-line projection then just returns roughly the mean of the series. When that happens the honest move is a level method, a moving average calculator or an exponential smoothing calculator, rather than a trend line fitted to noise. The tool states the verdict for you so you do not have to read the t_stat yourself.
Least squares and the trend line
Least squares is the rule that picks the line. For any candidate straight line you could draw through the points, each actual demand sits some vertical distance above or below it, and that distance is the residual. Least squares squares each residual and adds them up, then chooses the slope and intercept that make that total, SSE, as small as possible. Squaring is what gives the method its character: it treats a miss of 4 as four times as costly as a miss of 2, not twice, so the line is pulled hard toward reducing the big gaps and a single far-off point can tilt the whole line. The result is one global line that balances the whole series rather than chasing the latest few points.
The slope and intercept fall straight out of the sums. The slope b = [ n*sum(t*D) – sum(t)*sum(D) ] / [ n*sum(t^2) – (sum t)^2 ] is the per-period change the line settles on, and the intercept a = mean(D) – b*mean(t) is fixed by forcing the line to pass through the point of averages, (mean t, mean D). That is a useful fact to hold onto: the least-squares line always goes through the average of the time index and the average of demand, so the intercept is not a free choice once the slope is set. Read the slope as units of demand gained or lost per period, and read the intercept as the fitted starting level, remembering it is an extrapolation back to t = 0 and not always a meaningful real quantity on its own.
Because the line is global, it behaves very differently from a smoothing method. A moving average or exponential smoothing keeps a running estimate that leans on recent periods and quietly forgets old ones, so it bends as demand bends. Regression does not bend; it commits to one slope for the entire span and reports how well that single slope describes the data. That is a strength when the trend really is steady, because the line uses every period at once and projects a clean, interpretable rate forward, and it is a weakness when the trend changes partway through, because the one line splits the difference and fits neither half well. The fit statistics are how you tell which case you are in.
Reading R2, r, and Se
R2 is the headline fit number, the fraction of the demand variation the trend line explains. It runs from 0 to 1: an R2 of 0 means the line explains none of the movement in demand and you may as well use the flat average, while an R2 near 1 means almost all the movement lines up with the straight trend. On the default series R2 = 0.942, so 94.2% of the variation in demand is explained by the line and only about 6% is left as scatter around it. Read R2 first, because it tells you whether the slope is worth reading at all: a slope of 8 units per period means something when R2 is 0.94 and means very little when R2 is 0.05.
The correlation r is the signed square root of R2, r = sign(b)*sqrt(R2), so it carries the direction of the trend that R2 alone drops. On the default series r = 0.971, positive because the slope is positive and demand is climbing; a declining series gives a negative r of the same size. R2 and r say the same thing about strength of fit, but r keeps the sign, which is why it is handy for a quick read of direction and magnitude together. A value of r near +1 or -1 is a tight straight-line relationship; a value near 0 is no linear relationship at all.
Se, the standard error of estimate, puts the fit back into the units of demand. Where R2 is a unitless fraction, Se = sqrt( SSE / (n – 2) ) is the typical size of a one-period miss in the same units as the series, so on the default data Se = 5.34 means the actual demand sits about 5.34 units off the trend line in a typical period. It divides by n – 2 rather than n because the slope and the intercept each cost a degree of freedom, and that correction matters most on short series. Se is the engine of the prediction band: the width of the interval is Se scaled by the t value and the spread factor, so a small Se gives a tight band and a large Se a loose one. Read R2 for how much of the pattern the line catches, r for direction, and Se for how far off a single period is likely to be.
Prediction interval against confidence interval
These two intervals get conflated constantly, and the difference is the single most useful thing this tool draws out. Both are centered on the same forecast F0, and both use Se, the t value, and the spread of the time index, but they answer different questions. The confidence interval is for the average trend level at a period: if you could rerun history many times, it is the band that would contain the true mean demand for that period. The prediction interval is for an actual future demand, a single real observation, which scatters around the trend by Se on top of the uncertainty in the line itself. That extra scatter is the leading 1 inside the square root, present for the prediction interval and absent for the confidence interval, and it makes the prediction interval always the wider of the two.
On the default series at t = 9 the gap is easy to see. The 95% prediction interval runs 170.58 to 203.71, while the 95% confidence interval for the mean trend runs 176.96 to 197.33, noticeably narrower because it drops the leading 1. Use the prediction interval when you are planning against what demand might actually be next period, which is almost always the case in operations, because you stock and staff against real demand, not against the average of a hypothetical rerun. Use the confidence interval only when the question is genuinely about the average trend line, such as reporting how fast demand is growing rather than what next month will bring. Quoting a confidence interval as if it covered actual demand understates the risk, because it is the tighter band by construction.
The confidence level scales both bands. A higher level buys more coverage at the cost of a wider interval. On the default series the 95% prediction interval of 170.58 to 203.71 tightens to 173.99 to 200.30 at 90%, where you accept a one-in-ten chance of falling outside, and widens to 162.05 to 212.24 at 99%, where you insist on near-certain coverage. There is no free lunch: a band you can be more sure of is a band that is wider and says less. Pick the level from how costly a miss is, using a higher level when being caught short is expensive and a lower one when a tight, actionable range matters more than airtight coverage.
The trend-significance verdict
A slope on its own does not tell you whether there is a real trend, because any series, even pure noise, produces some nonzero slope when you fit a line to it. The question is whether the slope is large relative to the scatter around the line, and that is what the t_stat measures: t_stat = b / (Se / sqrt(Sxx)). The denominator is the standard error of the slope itself, so the t_stat is the slope expressed in units of its own uncertainty. A t_stat far from 0, roughly above 2 in size for the sample sizes here, means the slope is too big to be an accident of noise, and the tool calls the trend significant. A t_stat near 0 means the slope is within the range you would get from noise alone, and the tool calls it no significant trend.
On the default series the t_stat is 9.88, comfortably large, which with an R2 of 0.942 makes the upward trend clearly real, and the tool prints a significant upward trend. Read the verdict alongside R2, because the two can disagree in instructive ways on short or noisy series, and when they agree you can trust the projection. The verdict is there so you do not have to compute the t value or look up a table; it turns the arithmetic into a plain yes or no on whether projecting the line makes sense.
When the verdict comes back as no significant trend, the straight-line forecast collapses toward the mean of the series, because a near-zero slope means the line is nearly flat. At that point regression is not adding anything a simple average would not, and the honest move is to switch tools. A level series with random wobble is the home ground of a moving average or exponential smoothing, both of which track a level without pretending to find a trend. The tool points you there in the verdict rather than letting you project a slope that is really just noise.
When regression is the wrong tool
Linear regression fits one global straight line, and that single assumption is also its limit. The first and most common break is seasonality. A series with a repeating calendar pattern, a weekly rhythm or a summer peak, has structure a straight line cannot represent, so the line runs through the middle of the swings, fits each one poorly, and leaves residuals that rise and fall in a regular shape rather than scattering randomly. Regression handles trend, not seasonality; if your demand has a repeating pattern, the right move is to deseasonalize it first, with a seasonal index, and fit the trend to the deseasonalized series. Seasonal Index is one of the sibling tools in this silo, and it is the right next stop when the residuals from a straight-line fit show a repeating shape.
The second break is curvature. If demand accelerates or levels off rather than moving at a steady rate, a straight line will systematically miss, running below the data at both ends and above it in the middle, or the reverse, again leaving structured residuals and a lower R2 than the eye expects. A low R2 with a residual pattern that is not random is the signal that a straight line is the wrong shape, whether the cause is a curve or a season. The third break is outliers: because least squares squares the errors, a single unusual period pulls the line toward itself and inflates Se, so a real one-off, a promotion or a data error, can tilt the whole trend and widen every band. Clean or flag such points before fitting rather than letting them bend the line.
The last break is too little data. With n below about five the fit is unstable and the intervals are wide, because n – 2 degrees of freedom leaves almost nothing to estimate the scatter from, and the t value for a tiny sample is large, so the band balloons. A short series can produce a confident-looking slope that shifts the moment one more period arrives. Reporting a point forecast with no band at all is a related mistake: the point is only the center, and without the interval you hide how uncertain it is. Feed the tool enough evenly spaced history, read the band as seriously as the point, and treat a very wide band far out as a warning not to extrapolate that far.
Preparing a clean demand series
The fit is only as good as the history you feed it, so a little care with the series pays off. Enter demand, not sales, if the two differ. Sales are capped by what you had in stock, so a period that sold out understates the demand that was really there, and a censored low point drags the fitted line down and flattens the slope. If you know a period was stocked out, estimate the true demand for that period rather than feeding the truncated sales figure. The tool takes one value per period, one per line, so you can paste a column straight from a spreadsheet.
Order and spacing matter. List the periods oldest first, so the most recent period is at the bottom, because the tool indexes them t = 1, 2, 3 from the top and forecasts the period after the last one. Keep the periods evenly spaced, one per week or one per month, and do not mix them, because the time index assumes each step is the same length of time with no gaps. A missing period breaks the even spacing, so decide whether a zero or an estimate is the honest value before you paste; a stray zero in an otherwise steady series is an outlier that will tilt the line and inflate Se.
Give the line enough history, and keep it linear. Aim for at least eight to twelve periods, more if you have them, because a short series gives wide, unstable intervals and a slope that moves when new demand arrives. Before you fit, glance at the shape: if demand clearly curves or repeats on a season, a straight line is the wrong model and no amount of clean data will fix that, so deseasonalize a seasonal series first and consider whether a curve is a better description. Watch for anomalies that are real but not part of the pattern, a one-off promotion or a data-entry error, and clean them first, because least squares cannot tell an outlier from a genuine jump and will let it bend the trend. Re-fit as new demand arrives, since the best line for a series can shift as its behavior changes.
Five worked examples
Example 1: the default series, full derivation with the sums table
This one shows every number so the forecast is transparent. The series is 120, 135, 132, 150, 160, 155, 172, 180 over 8 periods, indexed t = 1 through 8. Build the sums: n = 8, sum(t) = 36, sum(D) = 1204, sum(t*D) = 5760, sum(t^2) = 204, with mean(t) = 4.5 and mean(D) = 150.5, and Sxx = 204 – 36^2 / 8 = 42. The slope is b = [ 8*5760 – 36*1204 ] / [ 8*204 – 36^2 ] = [ 46080 – 43344 ] / [ 1632 – 1296 ] = 2736 / 336 = 8.143 per period, and the intercept is a = 150.5 – 8.143 * 4.5 = 113.86, so the line is D = 113.86 + 8.143 t. The fit comes out at R2 = 0.942, r = 0.971, and Se = 5.34, and the next period, t = 9, forecasts F(9) = 113.86 + 8.143 * 9 = 187.14. The lesson is that an R2 near 0.94 with a slope of about 8 units per period is a strong, usable trend, and showing the arithmetic keeps the forecast something you can check rather than take on faith.
Example 2: multi-period projection and the fanning band
This case keeps the default series and projects three periods out at 95%, so you can watch the band widen. The point forecasts step up by the slope each period: t = 9 forecasts 187.14 with a prediction interval of 170.58 to 203.71, t = 10 forecasts 195.29 with 177.53 to 213.04, and t = 11 forecasts 203.43 with 184.38 to 222.49. The centers are evenly spaced, each 8.143 above the last, because that is what a straight line does, but the intervals get wider as you go: the band is about 33 units wide at t = 9 and about 38 units wide at t = 11. The lesson is that the point forecast is the easy part, a clean per-period step, while the honest uncertainty grows the further out you project, which is exactly why long-range extrapolation from a trend line is risky and why the band matters more the further you push it.
Example 3: prediction interval against confidence interval, and the confidence level
This case stays on the default series at t = 9 and compares the two bands and the two levels the tool offers. The 95% prediction interval, for an actual future demand, is 170.58 to 203.71. The 95% confidence interval, for the mean trend level, is 176.96 to 197.33, narrower because it drops the leading 1 inside the square root and so leaves out the period-to-period scatter. Changing the confidence level moves the prediction interval too: at 90% it tightens to 173.99 to 200.30, and at 99% it widens to 162.05 to 212.24. The lesson is to match the interval to the question. Plan real stock and capacity against the prediction interval, since you face actual demand, not an average; read the confidence interval only when you genuinely mean the average trend line; and remember that a higher confidence level always buys coverage by giving up a wider, less specific band.
Example 4: a declining trend
This case shows regression handling a fall the same way it handles a climb. The series is 820, 780, 760, 705, 690, 640, 610 over 7 periods. The fit gives a slope of b = -35.0 per period and an intercept of a = 855.0, so demand drops a steady 35 units each period, and the next period, t = 8, forecasts 575.00 with a 95% prediction interval of 546.84 to 603.16. The fit is tight, R2 = 0.990 with Se = 8.37, meaning the decline is almost perfectly linear and only a little scatter is left around the line. The lesson is that a negative slope is read exactly like a positive one, as the per-period change, and nothing about the method assumes growth; an R2 near 0.99 says the fall is close to a straight line and the projection down is as trustworthy as any climb, within the widening band.
Example 5: a flat, no-trend series
This case shows what the verdict is for. The series is 100, 104, 98, 101, 99, 103, 97, 102 over 8 periods, demand that holds around 100 with only random wobble. The fit gives a slope of b = -0.095, an R2 of just 0.009, and a t_stat of -0.23, so the tool returns no significant trend: the slope is within what noise alone produces and the line explains under 1% of the movement. The next-period forecast is 100.07, essentially the mean of the series, sitting inside a wide band of 91.90 to 108.24. The lesson is the mirror of the trending cases. A low R2 and a near-zero slope mean the line explains almost nothing, so do not project a trend that is not there; a flat series is the home ground of the Moving Average or Exponential Smoothing tool, both of which track a level without inventing a slope.
Three expert tips
Read R2 and the trend verdict before you trust the slope
The slope is the number everyone reaches for, but it only means something when the line actually fits. A high R2 with a clearly non-zero slope, like the 0.942 and the slope of 8.143 on the default series, means the straight line describes the data and the projection is meaningful. A low R2 or a near-zero slope means the series is flat, seasonal, or curved, and the line is fitting noise or the wrong shape, so projecting it just extrapolates that noise forward. The tool states the verdict for you, significant or not, and points you to a moving average or exponential smoothing when the trend is not real. Read R2 and the verdict first, and let them decide whether the slope is worth quoting at all.
Forecast with the prediction interval, not a single number
The point forecast is only the center of a range, and reporting it alone hides how uncertain it is. The prediction interval is the honest band for an actual future demand, and it widens the further out you project, from 170.58 to 203.71 at t = 9 out to 184.38 to 222.49 at t = 11 on the default series. Quote the band, not just the point; plan safety stock against its upper edge when being caught short is costly; and treat a very wide band far out as a warning not to extrapolate that far rather than a number to plan around. A forecast with its interval tells you both the best estimate and how much to trust it, which is far more useful than a lone figure that looks exact and is not.
Keep the series linear, clean, and long enough
Regression fits one global straight line, so it captures a steady trend but not a season or a curve. Deseasonalize first if the data has a repeating pattern, and reconsider the model if demand clearly bends rather than running straight. It is also sensitive to outliers, because it squares the errors, so a single promotion or data-entry error can tilt the whole line and inflate Se; clean or flag those points before fitting. And give it enough history: a short series, fewer than about five periods, gives wide, unstable intervals and a slope that jumps when one more period arrives. Feed evenly spaced periods with no gaps, oldest first, enough of them to be stable, and re-fit as new demand comes in, because the best line can shift as the series changes.
Common mistakes to avoid
The first mistake is projecting a trend that is not there. When the verdict says no significant trend and R2 is near 0, the slope is noise and the straight-line forecast is just the mean dressed up as a trend; the answer is a level method, not a line. The second mistake is forcing a line on seasonal or curved demand. A repeating pattern or a bend leaves structured residuals and a low R2, and no amount of clean data fixes a wrong model, so deseasonalize a seasonal series first and rethink the shape when demand clearly curves.
A third mistake is reporting a point forecast with no band, which hides the uncertainty entirely and invites planning against a number that looks exact and is not. A fourth is extrapolating too far, treating a forecast twenty periods out with the same confidence as one period out, when the band has fanned out to say the opposite. A fifth is letting an outlier bend the line: because least squares squares the errors, one unusual period tilts the whole trend and inflates Se, so a real one-off should be cleaned or flagged before fitting. Read R2 and the verdict, quote the prediction interval, keep the series linear and clean, and do not push the projection past where the band stays useful, and the forecast will hold up.
Where this calculator fits
It suits anyone who has to turn a demand history into a next-period number and believes a steady trend, rather than a reaction to the latest point, describes the series. A demand planner can paste a series, read the slope and the forecast, and check R2, the verdict, and the prediction interval before committing the number to a plan. An operations or inventory analyst can use the forecast as the input to a reorder point or a safety stock calculation, with Se and the band feeding the variability those calculations need. A student or an analyst learning forecasting can see the full derivation from the sums, watch the band fan out as the projection runs, and read the difference between a prediction interval and a confidence interval that textbooks state but rarely draw.
Because a forecast is the number the rest of planning runs on, this tool hands off naturally to the rest of the work. The Moving Average Forecast Calculator and the Exponential Smoothing Calculator are the level-tracking alternatives: when there is no significant trend, or when recent points should weigh more than old ones, they track a level without fitting a global slope, and they are the right tools the moment the verdict here comes back flat. When your demand has a repeating calendar pattern, a Seasonal Index calculator models the season a straight line cannot carry, and when you want to grade a forecast from any method against actuals, a Forecast Error Metrics calculator takes MAD, RMSE, and MAPE further with a tracking signal, while an XYZ Demand Classification calculator groups items by how variable their demand is so you send steady items to a trend or level method and erratic items to a method built for them. The Forecasting and Analytics hub gathers the forecasting tools as they go live, and the Supply Chain hub carries the tools that turn a demand forecast into an inventory and replenishment plan.
Frequently asked questions
What does this linear regression forecast calculator do?
It fits a straight trend line to a demand history by least squares and projects it forward with a band around the forecast. You paste your demand, one value per period, and it returns the next-period forecast along with the trend equation D = a + b t, the slope b, the intercept a, R2, the correlation r, and the standard error of estimate Se. It builds a prediction interval, or a confidence interval, at the level you choose, states a plain verdict on whether the trend is real, and draws the observed demand, the fitted line, and the projected points with a band that fans out the further you extrapolate. On the default rising series of 120, 135, 132, 150, 160, 155, 172, 180, the fit gives slope 8.143, intercept 113.86, R2 0.942, and Se 5.34, with a next-period forecast of 187.14 inside a 95% prediction interval of 170.58 to 203.71. Every value stays in your browser.
How is the trend line calculated?
Demand D is fit against a time index t = 1, 2, 3, …, n, one step per period. The slope is b = [ n*sum(t*D) – sum(t)*sum(D) ] / [ n*sum(t^2) – (sum t)^2 ] and the intercept is a = mean(D) – b*mean(t), which forces the line through the point of averages. The trend value for any period is F(t) = a + b*t, and you project the forecast by evaluating the line at t = n+1, n+2, and so on. On the default series, n = 8, sum(t) = 36, sum(D) = 1204, sum(t*D) = 5760, and sum(t^2) = 204, so b = 2736 / 336 = 8.143 and a = 150.5 – 8.143 * 4.5 = 113.86, giving the line D = 113.86 + 8.143 t and a next-period forecast of 187.14 at t = 9. The slope is the per-period change and the intercept is the fitted level at t = 0.
What do slope b and intercept a mean?
The slope b is the steady change in demand per period, so a slope of 8.143 means demand rises about 8.143 units each period along the fitted line, and a negative slope means it falls. The intercept a is the fitted level where the line crosses at t = 0, the base the trend builds from; on the default series a = 113.86. Both are labeled explicitly because the notation flips between books: operations texts often write the line as a + b x while school algebra writes it as a x + b, which swaps which letter is the slope. In this tool a is always the intercept and b is always the slope, whatever the ordering. Read the slope for the rate of change and the intercept for the starting level, keeping in mind the intercept is an extrapolation back to t = 0 and not always a meaningful standalone quantity.
What is R2 and what counts as a good value?
R2 is the fraction of the demand variation the trend line explains, computed as R2 = 1 – SSE/SST, where SSE is the squared error left after the line and SST is the total squared variation around the mean. It runs from 0 to 1: near 0 the line explains almost nothing and a flat average would do as well, while near 1 almost all the movement lines up with the straight trend. On the default series R2 = 0.942, so 94.2% of the variation is explained and about 6% is scatter. There is no universal cutoff for good, because it depends on the series, but a high R2 with a clearly non-zero slope means the line fits and the projection is meaningful, while a low R2 is a warning that the series may be flat, seasonal, or curved and a straight line is the wrong model.
What is the correlation r, and how does it relate to R2?
The correlation r is the signed square root of R2, r = sign(b)*sqrt(R2), so it measures the same strength of straight-line fit that R2 does but keeps the direction of the trend. On the default series R2 = 0.942 and r = 0.971, positive because the slope is positive and demand is rising; a declining series with the same fit would give r = -0.971. A value of r near +1 is a tight upward line, near -1 a tight downward line, and near 0 no linear relationship. R2 is easier to read as a percentage of variation explained, while r is handy for stating strength and direction together in one number. They always agree on how well the line fits, since one is just the square of the other with a sign attached.
What is the standard error of estimate Se?
Se is the typical size of a one-period miss around the trend line, in the units of demand. It is computed as Se = sqrt( SSE / (n – 2) ), where SSE is the sum of the squared residuals and the division is by n – 2 rather than n because two quantities, the slope and the intercept, were estimated from the data. On the default series Se = 5.34, meaning actual demand sits about 5.34 units off the line in a typical period. Se is what drives the width of the prediction and confidence bands: the interval is Se scaled by a Student-t value and a spread factor, so a small Se gives a tight band and a large Se a loose one. Read R2 for the share of the pattern the line catches and Se for how far off any single period is likely to be.
What is the difference between a prediction interval and a confidence interval?
They answer different questions and the prediction interval is always the wider. The confidence interval is for the average trend level at a period, the band that would contain the true mean demand if you could rerun history. The prediction interval is for an actual future demand, a single real observation, which scatters around the trend by Se on top of the uncertainty in the line. That extra scatter is the leading 1 inside the square root: the prediction interval uses sqrt( 1 + 1/n + (t0 – mean t)^2 / Sxx ) and the confidence interval drops the 1. On the default series at t = 9, the 95% prediction interval is 170.58 to 203.71 and the 95% confidence interval is 176.96 to 197.33. Plan real stock and capacity against the prediction interval, since you face actual demand; use the confidence interval only when you truly mean the average trend line.
Why does the forecast band get wider the further out I project?
Because the term (t0 – mean t)^2 / Sxx inside the square root grows as the forecast period t0 moves away from the middle of the history, mean(t). Both the prediction and the confidence interval carry that term, so both fan out symmetrically: the band is tightest near the center of the observed data and widens in either direction, and it widens fastest far out in the future. On the default series the 95% prediction interval is about 33 units wide at t = 9 and about 38 units wide at t = 11. The reason is that the line is most pinned down where the data sits and least pinned down where it does not, so a projection far beyond the history is genuinely less certain. Treat a very wide band far out as a signal not to extrapolate that far rather than a number to plan around.
How does the confidence level change the band?
A higher confidence level buys more coverage at the cost of a wider, less specific band, by using a larger Student-t multiplier. On the default series at t = 9, the prediction interval is 173.99 to 200.30 at 90%, 170.58 to 203.71 at 95%, and 162.05 to 212.24 at 99%. At 90% you accept a one-in-ten chance the actual demand falls outside the band in exchange for a tighter range; at 99% you insist on near-certain coverage and pay for it with a much wider range that says less about where demand will land. There is no free lunch: more certainty always means a wider interval. Pick the level from how costly a miss is, using a higher level when being caught short is expensive and a lower one when a tight, actionable range matters more than airtight coverage.
How does the tool decide whether the trend is significant?
It computes the slope significance t_stat = b / (Se / sqrt(Sxx)), which expresses the slope in units of its own uncertainty, and reads it alongside R2. A large absolute t_stat, roughly above 2 for the sample sizes here, means the slope is too big to be an accident of noise, so the tool reports a significant trend, up or down with the sign of the slope. A t_stat near 0, a near-zero slope, or a low R2 means the movement is within what noise alone produces, and the tool reports no significant trend. On the default series the t_stat is 9.88 with R2 0.942, so the upward trend is clearly real. The verdict saves you computing the t value or reading a table, and when it comes back flat it is telling you a straight-line projection would just return the mean.
What should I do when there is no significant trend?
Switch to a level-tracking method, because a flat verdict means the slope is noise and the straight-line forecast collapses toward the mean of the series. On the example flat series of 100, 104, 98, 101, 99, 103, 97, 102 the slope is -0.095, R2 is 0.009, and the t_stat is -0.23, so the line explains under 1% of the movement and the next-period forecast of 100.07 is essentially the average. A series like that is the home ground of the Moving Average or Exponential Smoothing tool, both of which track a level and react to recent demand without inventing a trend. Regression is the right tool when demand climbs or falls at a fairly steady rate; when it only wobbles around a level, a smoothing method describes it better and does not pretend to find a slope that is not there.
Can linear regression handle seasonality?
No. A straight line carries only a level and a trend, so it has no way to represent a pattern that repeats on a calendar, a weekly rhythm or a summer peak. Fit a line to strongly seasonal demand and it will run through the middle of the swings, fit each one poorly, and leave residuals that rise and fall in a regular shape rather than scattering randomly, usually with a lower R2 than the pattern seems to deserve. The fix is to deseasonalize the series first, using a seasonal index that estimates how far each period of the cycle sits above or below the average, then fit the trend to the deseasonalized data and reapply the pattern. A Seasonal Index calculator is the sibling tool for that step. If your residuals show a repeating shape, that is the route, not a straight line on the raw seasonal series.
How does this compare to a moving average or exponential smoothing?
They differ in what they commit to. Linear regression fits one global straight line to the whole history and projects a fixed slope, which is the right shape when demand trends at a steady rate. A moving average averages a fixed window of recent periods, and exponential smoothing keeps a running estimate that fades older periods, so both track a level and react to recent demand rather than committing to a single slope. Regression is stronger when there is a clear, sustained trend and every period should count toward one line; the smoothing methods are stronger when there is no real trend, when the level shifts partway through, or when recent points should weigh more than old ones. When the verdict here comes back as no significant trend, the moving average and exponential smoothing tools are the natural alternatives, which is why they sit beside this one in the silo.
How much demand history do I need?
Aim for at least eight to twelve periods, more if you have them. The fit uses n – 2 degrees of freedom to estimate the scatter, so a short series leaves almost nothing to work with, gives wide and unstable intervals, and produces a slope that can jump the moment one more period arrives. The default series has eight periods, which is enough to read a clear trend with a tight band, but fewer than about five is genuinely shaky. List the periods oldest first so the most recent is at the bottom, keep them evenly spaced with no gaps, because the time index assumes equal steps, and re-fit as new demand arrives, since the best line can shift as the series changes. Enough clean, evenly spaced history is what makes both the slope and the band trustworthy.
What can throw off the fit?
Four things most often. Seasonality and curvature break the straight-line assumption, leaving structured residuals and a low R2, so a repeating pattern needs deseasonalizing first and a clear bend needs a different model. Outliers throw off the line because least squares squares the errors, so a single promotion or data-entry error tilts the whole trend and inflates Se; clean or flag such points before fitting. A short series makes everything unstable, since there is too little data to pin down the slope or the scatter. Censored sales are a quieter trap: a stocked-out period understates real demand and drags the line down, so enter demand rather than sales where they differ. Read R2 and the residuals for the first two, watch for lone extreme points for the third, and check the history for gaps and stockouts for the last.
Is the tool free, and does it work in my browser?
Yes to both. The linear regression forecast calculator is free with no sign-up, and every calculation runs in your browser, so the demand values you enter are never sent to a server, stored, or shared. You can download a PDF of the result, export a CSV, or share a summary on WhatsApp. It fits the least-squares line, reports the slope, intercept, R2, correlation r, and Se, builds a prediction or confidence interval at 90, 95, or 99 percent, states a plain trend verdict, and draws the observed demand, the fitted line, and the projected points with a band that fans out. It is a planning and analysis tool, so treat the forecast as a well-grounded estimate and read the fit statistics, the verdict, and the band to judge how much to trust it for your own series before you commit it to a plan.
More forecasting and analytics calculators
The Moving Average and Exponential Smoothing calculators are the level-tracking alternatives and are live. The other sibling tools below are on the way and are not yet live, so they are listed here for reference rather than linked.
The forecasting tools work as a set. This tool fits a fixed trend line, while the Moving Average and Exponential Smoothing calculators track a level and react to recent demand, so when the verdict here comes back flat they are the alternatives to reach for. When demand has a repeating calendar pattern, a Seasonal Index models the season a straight line cannot. When you want to grade a forecast from any method over time, Forecast Error Metrics takes MAD, RMSE, and MAPE further with a tracking signal. The Forecasting and Analytics hub gathers the forecasting tools as they go live, and the Supply Chain hub carries the tools that turn a demand forecast into an inventory and replenishment plan.
Sources, disclaimer, and editorial transparency
The relationships used here are standard forecasting and least-squares practice. Demand D is fit against a time index t = 1, 2, 3, …, n, with slope b = [ n*sum(t*D) – sum(t)*sum(D) ] / [ n*sum(t^2) – (sum t)^2 ] and intercept a = mean(D) – b*mean(t), giving the trend line F(t) = a + b*t. The fit statistics come from SSE = sum( (D – F)^2 ) and SST = sum( (D – mean D)^2 ): R2 = 1 – SSE/SST, r = sign(b)*sqrt(R2), and Se = sqrt( SSE / (n – 2) ). With Sxx = sum(t^2) – (sum t)^2 / n and t_crit the Student-t value for n – 2 degrees of freedom at the chosen confidence, the prediction interval for a future demand is F0 +/- t_crit * Se * sqrt( 1 + 1/n + (t0 – mean t)^2 / Sxx ) and the confidence interval for the mean trend is the same expression without the leading 1. The slope significance is t_stat = b / (Se / sqrt(Sxx)). The worked-example numbers are computed from the series shown: the default series of 120, 135, 132, 150, 160, 155, 172, 180 gives sum(t) = 36, sum(D) = 1204, sum(t*D) = 5760, sum(t^2) = 204, Sxx = 42, slope 8.143, intercept 113.86, R2 0.942, r 0.971, Se 5.34, and F(9) = 187.14 with a 95% prediction interval of 170.58 to 203.71 (176.96 to 197.33 for the mean, 173.99 to 200.30 at 90%, 162.05 to 212.24 at 99%); the projection continues 195.29 (177.53 to 213.04) and 203.43 (184.38 to 222.49); the declining series of 820, 780, 760, 705, 690, 640, 610 gives slope -35.0, intercept 855.0, R2 0.990, Se 8.37, and F(8) = 575.00 with a 95% prediction interval of 546.84 to 603.16; and the flat series of 100, 104, 98, 101, 99, 103, 97, 102 gives slope -0.095, R2 0.009, t_stat -0.23, and F(9) = 100.07 inside 91.90 to 108.24. This calculator and guide are built and reviewed by the OpsCalculators team; see our Editorial Policy for how each tool is researched, built, and tested.
Results are accurate for the formulas and the series above, and they are a planning and analysis estimate, not a guarantee of future demand. Linear regression fits one global straight line, so it describes a steady trend but not seasonality or curvature, it is sensitive to outliers because it squares the errors, and its intervals are wide and unstable on short series; the fit statistics grade only how well the line describes the history, not how the forecast will perform on demand it has not seen. Read R2, the verdict, and the prediction interval to judge whether the line suits your series, deseasonalize a seasonal series before fitting, and move to the Moving Average or Exponential Smoothing tool when there is no significant trend. See our full Disclaimer. OpsCalculators.com is operated by MAFHH INTERNATIONAL LTD. Your inputs are processed in your browser and are never stored; see our Privacy Policy.