ACCT 350 · Data Analytics for Accountants
Regression and Forecasting in Accounting
Fit a straight line to past data, use it to forecast, and learn how to judge when a prediction can be trusted.
Key takeaways
- Regression finds the straight line that best fits the points and gives a rule for predicting one measure from another.
- The slope says how much the predicted value changes for each extra unit of the input.
- A fit score called R² says how much of the ups and downs the line explains, from 0 to 1.
- Forecasts are best inside the range of data you have seen and risky far outside it.
- A good forecast comes with a range of error, and it gets checked against what actually happened.
Ravi runs an ice cream stand at a small lake. On hot days the line stretches around the corner. On cool days he sells a few cones and wonders why he opened. Every morning he faces the same decision: how much ice cream to prepare? Too little and he turns customers away. Too much and the leftovers melt into a very sticky loss.
Ravi has a notebook with five days of notes: the day's high temperature and the day's sales. He suspects there is a pattern, and he wants a way to turn tomorrow's weather forecast into a sales forecast. That is the job of regression: finding the rule that links one thing you know (temperature) to one thing you want to predict (sales).
This lesson builds on scatter plots, where you saw two measures rise together. Now we put a number on the link and use it carefully.
A line through the dots
Here is Ravi's notebook. Sales are in hundreds of dollars, so 2 means $200.
High temp (°F) 60 70 80 90 100
Sales ($100s) 2 3.5 4 5.5 6 Plot them and the dots climb from lower left to upper right. A regression line is the straight line that passes as close as possible to all the dots. "Close" is measured by the vertical gaps between each dot and the line, called residuals. The method squares each gap and picks the line with the smallest total, which is why it is called least squares. Squaring stops positive and negative gaps from canceling out and punishes big misses.
A straight line has two parts.
For Ravi: sales in hundreds of dollars = −3.8 + 0.1 × temperature.
Working out Ravi's line
You can do this by hand with five points. Follow each step.
Step 1: averages. Mean temperature: (60 + 70 + 80 + 90 + 100) ÷ 5 = 400 ÷ 5 = 80. Mean sales: (2 + 3.5 + 4 + 5.5 + 6) ÷ 5 = 21 ÷ 5 = 4.2.
Step 2: how far each day sits from the averages.
Temp Sales Temp−80 Sales−4.2 Product
60 2 −20 −2.2 44
70 3.5 −10 −0.7 7
80 4 0 −0.2 0
90 5.5 10 1.3 13
100 6 20 1.8 36 The products add to 44 + 7 + 0 + 13 + 36 = 100. The squared temperature gaps are 400, 100, 0, 100 and 400, which add to 1,000.
Step 3: the slope. Slope = 100 ÷ 1,000 = 0.1. Each extra degree adds 0.1 hundred dollars, which is $10 of sales.
Step 4: the intercept. The line always passes through the averages, so intercept = 4.2 − 0.1 × 80 = 4.2 − 8 = −3.8.
The line is: sales (in hundreds) = −3.8 + 0.1 × temperature. For a forecast, say tomorrow's high is 75°F. Then −3.8 + 0.1 × 75 = −3.8 + 7.5 = 3.7, so about $370 in sales.
How good is the line?
Check each residual, the actual value minus the line's value.
Temp Actual Line gives Residual
60 2 −3.8 + 6.0 = 2.2 −0.2
70 3.5 −3.8 + 7.0 = 3.2 +0.3
80 4 −3.8 + 8.0 = 4.2 −0.2
90 5.5 −3.8 + 9.0 = 5.2 +0.3
100 6 −3.8 + 10.0 = 6.2 −0.2 The residuals add to −0.2 + 0.3 − 0.2 + 0.3 − 0.2 = 0, as they always do for a least-squares line. Squared, they total 0.04 + 0.09 + 0.04 + 0.09 + 0.04 = 0.30.
The yardstick for fit is R² (read "R squared"). It compares two sums: the leftover misses and the total variation in sales around its average. Total variation is the sum of squared distances from 4.2: 4.84 + 0.49 + 0.04 + 1.69 + 3.24 = 10.30. Then
R² = 1 − (leftover ÷ total) = 1 − (0.30 ÷ 10.30) = 1 − 0.029 ≈ 0.97 So the line explains about 97% of the ups and downs in Ravi's five days. An R² near 1 means a tight fit and near 0 means the line explains almost nothing. But beware: five days is a very small notebook. A tidy fit on five points can be luck. Real analysis uses many observations, and software also reports how uncertain the slope is.
Cost behavior: regression's home in accounting
Accountants meet regression in cost estimation. Many costs are mixed: part fixed (like rent) and part variable (like materials). The line's intercept plays the role of the fixed cost and the slope plays the role of cost per unit.
A quick cousin of regression is the high-low method, which draws a line through only the lowest and highest points. Suppose a bakery's total cost was $5,200 at 1,000 loaves and $8,400 at 3,000 loaves.
Variable cost per loaf = (8,400 − 5,200) ÷ (3,000 − 1,000) = 3,200 ÷ 2,000 = 1.60
Fixed cost = 5,200 − 1.60 × 1,000 = 5,200 − 1,600 = 3,600
Check at 3,000 loaves: 3,600 + 1.60 × 3,000 = 3,600 + 4,800 = 8,400 ✓ It is fast but uses just two points, so one odd month can tilt it. Full regression uses every point and is steadier. Other uses include forecasting bad debts from sales, estimating warranty costs, and predicting cash needs.
Forecasting over time
Not every forecast uses a second measure. Often you only have a history, such as monthly sales, and want the next month. Simple tools include:
- Naive: next month equals this month. A surprisingly hard baseline to beat.
- Moving average: average the last few months. For sales of 10, 12, 11, 14, 13 and 16 thousand, the three-month average for July is (14 + 13 + 16) ÷ 3 = 43 ÷ 3 ≈ 14.3 thousand.
- Trend line: a regression of sales on the month number, which carries a rise or fall forward.
The moving average smooths bumps but lags behind a rising trend, since it forgets that sales are climbing. The trend line catches direction but can overshoot if growth slows. No method is always right.
The last step matters: forecasts improve only when you compare them with what really happened.
Giving a range, not a single number
Ravi's forecast for a 75°F day was $370. Would you bet your whole ice cream order on exactly $370? Of course not. Real days wander around the line. Look back at the residuals: they were all within $30 of the line (0.2 or 0.3 hundred). That tells Ravi something practical. On a day like those in his notebook, a forecast of $370 might reasonably miss by about $30 either way, so a sensible plan is to prepare for sales between roughly $340 and $400.
Statistics software turns this idea into a formal prediction interval, a range in which a new day will usually land. With only five days the interval is wide, and with hundreds of days it narrows. The lesson for any accountant: when you hand someone a forecast, hand over the range with it. A manager planning cash can decide how much cushion to hold when she sees "$370, probably between $340 and $400." A single number looks precise and invites false confidence.
More than one input
Sales rarely depend on one thing. Ravi might add weekends (more crowds) and the lake's school holidays. A regression with several inputs is called multiple regression. The idea is the same: each input gets its own slope, and the forecast adds them up.
The new risk is that inputs overlap. If hot days and weekends often come together, the math may struggle to say which one deserves the credit. A beginner's rule: add an input only when you have a business reason to believe it matters, and check that the forecasts do better on days the model has not seen. More inputs always make the fit on old data look better, even when the new input is pure noise, so a rising R² alone proves nothing.
What the output looks like in practice
Accountants usually do not compute these by hand. A spreadsheet or statistics tool prints a small table. You should recognize its main lines.
- Coefficients: the intercept and each slope, such as −3.8 and 0.1.
- R²: the fit score, here about 0.97.
- Standard error: a typical size of the misses, which sets the width of the range.
- p-value or confidence interval for each slope: a measure of whether the slope could be zero by chance. A small p-value, often below 0.05 by convention, suggests the link is unlikely to be luck, though it still does not prove cause.
Read the table in order: Does the sign of each slope make sense? (More ads should not reduce sales unless there is a story.) Is the fit decent? Is the sample large enough? Then look at the residuals for a pattern. If misses are all positive in summer and negative in winter, the model is missing a season. Doing these checks takes minutes, and skipping them is how confident but wrong forecasts reach the boardroom.
A common mistake: pushing the line too far
The biggest error is extrapolation: using the line far outside the data it came from. Ravi's data covers 60°F to 100°F. Ask the line about a 30°F day: −3.8 + 0.1 × 30 = −0.8, or negative $80 in sales. That is nonsense, because real sales cannot be negative, and at some low temperature the stand simply closes. The straight line was a good description of warm days and a poor rule for freezing ones.
A second mistake is confusing a link with a cause, which the scatter plot lesson raised. Temperature plausibly drives ice cream sales. But a regression could just as easily link ice cream sales to sunburn cases, with the sun driving both. The math cannot tell you which story is true; understanding the business can.
A third is forgetting that the future can break the pattern. A forecast built on calm years may fail when prices jump, a rival opens, or rules change. State the assumptions and the range: "About $370, give or take $50, if the weather forecast holds." Finally, tools are only as honest as their data, so apply the quality checks first. For forecasts that guide audits, see the audit lesson.
Words to know
Regression a method that fits a line to data to predict one measure from another.
Slope the change in the predicted value for each one-unit increase in the input.
Intercept the predicted value when the input equals zero.
Residual the actual value minus the value the line predicts.
R² a score from 0 to 1 for how much of the data's variation the line explains.
Extrapolation using a fitted line outside the range of the data it was built on.
Moving average the average of the most recent few periods, used to smooth and forecast.
Check yourself
- In Ravi's line, what does the slope of 0.1 mean in dollars?
- Use sales (hundreds) = −3.8 + 0.1 × temperature to forecast sales on a 90°F day, in dollars.
- Ravi's actual sales on a 70°F day were 3.5 (hundreds). The line gives 3.2. What is the residual?
- A bakery's cost was $5,200 at 1,000 loaves and $8,400 at 3,000 loaves. Find the variable cost per loaf and the fixed cost.
- Compute the three-month moving average for sales of 14, 13 and 16 thousand.
- Explain why using Ravi's line to forecast a 30°F day is a mistake.
Show the answers
- Each extra degree adds 0.1 hundred dollars, which is $10 of sales.
- −3.8 + 0.1 × 90 = −3.8 + 9 = 5.2 hundred, so about $520.
- Actual minus predicted: 3.5 − 3.2 = +0.3 hundred, or $30 above the line.
- Variable: (8,400 − 5,200) ÷ 2,000 = $1.60 per loaf; fixed: 5,200 − 1.60 × 1,000 = $3,600.
- (14 + 13 + 16) ÷ 3 = 43 ÷ 3 ≈ 14.3 thousand dollars.
- 30°F lies far outside the 60 to 100 range of the data, and the line would give negative sales (−0.8 hundred), which cannot happen.