Tutorials › Regression Analysis (Undergraduate) › A Worked Mean Absolute Error Calculation

Prediction Metrics and Calibration · Tutorial 769 of 991

A Worked Mean Absolute Error Calculation

Work through small prediction sets to calculate MAE, check each case’s contribution, and describe what the resulting average error means in context.

Intermediate 9 min read

What You'll Learn

  • Match each observed outcome to its prediction for the same case.
  • Calculate each case’s absolute prediction error.
  • Add the absolute errors and divide by the number of cases.
  • Interpret MAE in the outcome’s units without overstating what it says.
  • Check common arithmetic and interpretation mistakes.

From Individual Predictions to One Error Summary

A prediction metric condenses a set of case-by-case comparisons into a number. To make that number useful, the calculation must preserve the link between each observed outcome and the prediction made for that same case. Mean absolute error, abbreviated MAE, does this by measuring the size of each prediction error without letting its direction change that size, then averaging those magnitudes.

This tutorial focuses on carrying out and interpreting that calculation. The examples use small, hypothetical sets of predictions so that every contribution to the final average can be checked. In an applied analysis, the cases should be ones appropriate for the question being asked. For example, to summarize performance on new cases, predictions should be evaluated on cases whose outcomes were not used to fit the model or choose its settings. The arithmetic of MAE is the same regardless of how the predictions were produced.

Definition: For \(n\) paired cases, let \(y_i\) be the observed outcome and \(\hat{y}_i\) the prediction for case \(i\). The absolute error for that case is \(|y_i-\hat{y}_i|\). The mean absolute error is the arithmetic mean of those absolute errors:
$$ \mathrm{MAE}=\frac{1}{n}\sum_{i=1}^{n}|y_i-\hat{y}_i| $$

The observed value and prediction must refer to the same case, and they must be expressed on the same outcome scale and in the same units. There must be at least one complete observed-predicted pair. MAE itself requires no assumption that errors are normally distributed or that a regression relationship is linear: it is a descriptive calculation on the supplied pairs. However, a summary intended to describe future prediction performance is only as relevant as the cases and prediction process it summarizes.

Worked Example: Predicting Clinic Wait Times

Worked Example: Predicting Clinic Wait Times

Suppose a hypothetical clinic has five evaluation cases. For each case, a model predicted the wait time, and the wait time was then observed. Calculate MAE and describe it in context.

CaseObserved wait (minutes)Predicted wait (minutes)Absolute error (minutes)
118202
224213
331354
427252
540364

First calculate the observed-minus-predicted difference for each case and take its absolute value. For example, case 1 has difference \(18-20=-2\) minutes, so its absolute error is \(|-2|=2\) minutes. The five absolute errors are \(2, 3, 4, 2,\) and \(4\) minutes. Add them and divide by the five cases:

$$ \mathrm{MAE}=\frac{2+3+4+2+4}{5} =\frac{15}{5} =3\text{ minutes} $$

For these five hypothetical evaluation cases, the predictions were off by an average of 3 minutes in absolute terms. This does not mean every prediction missed by exactly 3 minutes: the individual errors ranged from 2 to 4 minutes. Nor does it establish how well the model will perform on every future clinic case. It summarizes the average absolute error in this particular set.

Why Take Absolute Values Before Averaging?

Let \(e_i=y_i-\hat{y}_i\) denote the signed error for case \(i\), using observed minus predicted as the convention. A positive \(e_i\) means the observation exceeded the prediction; a negative \(e_i\) means the prediction exceeded the observation. But MAE is intended to summarize the size of the errors, not their direction. Taking \(|e_i|\) makes each contribution nonnegative before the contributions are averaged.

The absolute value is defined as \( |e_i|=e_i\) when \(e_i\geq 0\), and \( |e_i|=-e_i\) when \(e_i<0\). Thus the contribution is always a distance from prediction to observation on the outcome scale. For instance, errors of \(3\) minutes and \(-3\) minutes each contribute \(3\) minutes to MAE.

The calculation follows directly from the definition. If the absolute errors are \(a_1,\ldots,a_n\), where \(a_i=|y_i-\hat{y}_i|\), their arithmetic mean is their total divided by the number of values. Therefore:

$$ a_1+\cdots+a_n =\sum_{i=1}^{n}|y_i-\hat{y}_i|, \qquad \text{average absolute error} =\frac{a_1+\cdots+a_n}{n} =\mathrm{MAE}. $$

This also explains the units. Subtracting an outcome from a prediction expressed in the same units produces an error in those units; taking an absolute value does not change the units; and averaging values in a common unit keeps that unit. MAE is therefore reported in the units of the outcome, such as minutes, grams, or dollars. It is not a percentage unless it has been separately transformed into a percentage-based quantity.

Worked Example: Predicting Blood Glucose

Worked Example: Predicting Blood Glucose

Consider four hypothetical evaluation cases with blood glucose outcomes and predictions, all recorded in milligrams per deciliter (mg/dL). Calculate the absolute error for each case and then the MAE.

CaseObserved (mg/dL)Predicted (mg/dL)Absolute error (mg/dL)
1100928
21041106
31311265
41431518

For case 1, \(|100-92|=8\) mg/dL. For case 2, \(|104-110|=|-6|=6\) mg/dL. Similarly, cases 3 and 4 contribute \(|131-126|=5\) mg/dL and \(|143-151|=8\) mg/dL. The calculation is:

$$ \mathrm{MAE}=\frac{8+6+5+8}{4} =\frac{27}{4} =6.75\text{ mg/dL} $$

The mean absolute prediction error for these four hypothetical cases is 6.75 mg/dL. This is an average magnitude, not a claim that each prediction differs from its observed value by 6.75 mg/dL. The four case-level magnitudes were 8, 6, 5, and 8 mg/dL. The result describes prediction discrepancies in this set; by itself, it does not establish whether any particular discrepancy is medically important.

Worked Example: Converting the Result to Another Unit

Worked Example: Predicting Delivery Times

A hypothetical service compares predicted and observed delivery times for four evaluation cases, with all times recorded in hours. Calculate MAE in hours and express the same average in minutes.

CaseObserved time (hours)Predicted time (hours)Absolute error (hours)
12.02.50.5
23.52.51.0
34.04.50.5
45.56.00.5

The case-level calculations are \(|2.0-2.5|=0.5\), \(|3.5-2.5|=1.0\), \(|4.0-4.5|=0.5\), and \(|5.5-6.0|=0.5\) hours. Their sum is 2.5 hours, so:

$$ \mathrm{MAE}=\frac{0.5+1.0+0.5+0.5}{4} =\frac{2.5}{4} =0.625\text{ hours} $$

Since one hour is 60 minutes, \(0.625\times 60=37.5\) minutes. The MAE is therefore 0.625 hours, or equivalently 37.5 minutes. The unit conversion changes the way the same average is expressed; it does not change which cases were included or their relative contributions. In plain language, the average absolute discrepancy for these four hypothetical delivery predictions was 37.5 minutes.

Reading and Checking an MAE Calculation

A useful calculation is easy to audit. Keep the observed outcome, prediction, and absolute error together for each case, either in a table or in an explicitly ordered list. Then check the following:

  • Pairing: each prediction is matched with the observation for the same case.
  • Scale: the observed value and prediction use the same outcome scale and units before subtraction.
  • Magnitude: each contribution is nonnegative because it is an absolute value.
  • Count: the denominator is the number of complete pairs included in the sum.
  • Context: the reported unit matches the outcome, and the interpretation says this is an average over the cases evaluated.

As a quick arithmetic check, MAE must be at least zero. It is zero only if every prediction exactly matches its observed outcome, since a sum of nonnegative absolute errors can equal zero only when each term is zero. MAE cannot exceed the largest absolute error in the set: the average of values all between zero and that maximum must also lie between those limits. These checks can flag an incorrect total or an implausible final value, although they do not replace checking each case.

Common Mistakes

  • Using signed differences in the average. A difference can be negative, but MAE uses its absolute value. For example, an observed value of 104 and prediction of 110 contribute 6 units, not \(-6\) units.
  • Dividing by the wrong number. MAE is the mean of the case-level absolute errors, so divide by the number of paired cases used in the sum. Do not use \(n-1\); that divisor belongs to certain sample-variance calculations, not this arithmetic mean.
  • Changing units partway through. Do not subtract minutes from hours or combine errors expressed on different scales. Put all pairs in consistent units first.
  • Describing the average as a typical error for every case. MAE is the average magnitude across the set. Individual errors can be smaller or larger, as the tables show.
  • Overgeneralizing from the cases evaluated. A calculated MAE describes the supplied pairs. A claim about future performance also depends on whether the evaluation cases and prediction process are relevant to the intended use.
Key takeaway: Match each prediction to its observed outcome, calculate \(|y_i-\hat{y}_i|\) for every case, add those magnitudes, and divide by the number of cases. Report the result in the outcome’s units and describe it as an average over the evaluation set.

Check Your Understanding

For each question, show enough work to make the case-level contributions clear.

  1. Three hypothetical observed outcomes are 12, 18, and 25 minutes, and their predictions are 10, 20, and 24 minutes. Calculate each absolute error and the MAE.
  2. In one case, the observed outcome is 42 units and the prediction is 37 units. What is that case’s contribution to MAE, and why is it not negative?
  3. A set of six paired cases has absolute errors whose sum is 30 grams. Calculate and interpret the MAE with units.
  4. Can MAE for a set of cases be negative? Explain using its definition.
  5. A model has an MAE of 4.2 minutes on a particular evaluation set. State one correct interpretation and one conclusion that this number alone does not justify.