Why Test Sensitivity to Input Changes?
A prediction is produced from recorded inputs, but those inputs may not be exact. A customer’s annual distance driven may be rounded, a health measurement may vary slightly between readings, or a data-entry correction may change a recorded value. Sensitivity analysis asks a focused question: if this individual’s inputs changed slightly in a plausible way, how much would the model’s prediction change?
The model is held fixed during this test. We change the inputs for one case, pass the altered values through the same prediction process, and compare the result with the baseline prediction. This is different from refitting a model on a different sample, and it does not measure the uncertainty of an individual outcome. It diagnoses how dependent a particular prediction is on the values supplied to the model.
A perturbation should represent a plausible variation in the input, not an arbitrary alteration. Its size and direction should be justified by the input’s units, recording precision, or a realistic case correction. Categorical inputs need valid alternative categories; changing a category code to a number between two codes is generally not a meaningful perturbation. For related inputs, changes may also need to respect constraints—for example, a total should remain consistent with its component amounts.
Measures and Interpretation
Start with the signed change, \(f(x')-f(x)\), which shows both the direction and size of the response in the prediction’s units. The absolute change, \(|f(x')-f(x)|\), measures magnitude without direction. If the baseline prediction is not zero, a relative change can also be reported as a percentage of the baseline. For a probability prediction, it is important to distinguish a change in percentage points from a relative percentage change.
Relative change can be misleading when the baseline is close to zero, and it is undefined when the baseline is zero. In those cases, report the absolute change and its units. For a probability, for instance, a change from 0.50 to 0.52 is an increase of 0.02, or 2 percentage points; relative to 0.50, it is a 4% increase. These are both correct descriptions but answer different questions.
A useful test changes one input at a time to show which small changes matter locally, then considers a combined perturbation when several inputs could change together. One-at-a-time results do not automatically predict the effect of a joint change: the model may have interactions, nonlinearities, or thresholds. Always identify the specific case, baseline, alternative inputs, and prediction scale in the report.
Worked Example: A Smooth Cost Prediction
Method. Use direct scenario comparisons for a fixed linear prediction model. A hypothetical model predicts annual cost in dollars as \(f(a,m)=250+15a+60m\), where \(a\) is age in years and \(m\) is annual travel distance in thousands of kilometres. For one case, age is 40 and annual distance is 10.0 thousand kilometres. Assess an increase of one year in age, an increase of 0.5 thousand kilometres in distance, and both changes together.
Baseline. Substituting \(a=40\) and \(m=10.0\), \(f(40,10.0)=250+15(40)+60(10.0)=250+600+600=\$1{,}450\).
Age change alone. At age 41 and the original distance, \(f(41,10.0)=250+15(41)+60(10.0)=250+615+600=\$1{,}465\). The prediction increases by \(\$1{,}465-\$1{,}450=\$15\).
Distance change alone. At age 40 and distance 10.5 thousand kilometres, \(f(40,10.5)=250+15(40)+60(10.5)=250+600+630=\$1{,}480\). The prediction increases by \(\$30\).
Both changes. At age 41 and distance 10.5 thousand kilometres, \(f(41,10.5)=250+615+630=\$1{,}495\). The joint increase is \(\$1{,}495-\$1{,}450=\$45\), or \((45/1{,}450)\times100=3.1034\ldots\%\). To the nearest cent, the baseline and perturbed predictions are \(\$1{,}450.00\), \(\$1{,}465.00\), \(\$1{,}480.00\), and \(\$1{,}495.00\); the relative increase rounded to two decimal places is 3.10%.
The combined change equals the sum of the two separate changes because this model is additive and linear in these inputs. The common mistake is to multiply the distance change of 0.5 by 60 as though \(m\) were measured in individual kilometres. The stated unit is thousands of kilometres, so the correct contribution is \(60(0.5)=\$30\). This example illustrates sensitivity to the specified inputs, not whether those inputs or the model are appropriate.
Why Local Slopes Describe Small Changes
For a differentiable prediction function, local derivatives provide a compact description of how small changes in the inputs affect the prediction. This result applies locally where the function is differentiable; it does not describe a jump across a tree split, and a local approximation may be poor for a large change.
The justification comes from the first-order Taylor expansion. For a differentiable function, the change in the function equals its linear part plus a remainder that becomes small relative to the size of the perturbation as \(\Delta x\) approaches zero:
Subtracting \(f(x)\) gives the stated approximation: the leading change is the sum of each input change multiplied by the model’s local slope for that input. The approximation is most useful when changes are small, the function is smooth nearby, and the input units are understood. A derivative has units of prediction per unit of input, so its size cannot be interpreted without those units. For a practical assessment, calculate predictions at explicitly chosen plausible input values as well as, when useful, describing the local slope.
Worked Example: A Logistic Probability Near One Case
Method. Compare predictions from the fixed logistic model at the recorded age and at nearby ages. Suppose a hypothetical model predicts the probability of a specified event using \(\eta=-2+0.05a+1.0b\) and \(p=1/(1+\exp(-\eta))\), where \(a\) is age in years and \(b\) equals 1 if a prior event is recorded and 0 otherwise. A case has age 20 and \(b=1\). Examine plausible age changes to 19 and 21 while holding \(b\) fixed.
Baseline. The linear predictor is \(\eta=-2+0.05(20)+1.0(1)=-2+1+1=0\). Therefore \(p=1/(1+\exp(0))=0.5000\).
Age 19. Now \(\eta=-2+0.05(19)+1=-2+0.95+1=-0.05\). Thus \(p=1/(1+\exp(0.05))\approx0.4875\). The change from baseline is approximately \(-0.0125\), or \(-1.25\) percentage points.
Age 21. Now \(\eta=-2+0.05(21)+1=-2+1.05+1=0.05\). Thus \(p=1/(1+\exp(-0.05))\approx0.5125\). The change from baseline is approximately \(+0.0125\), or \(+1.25\) percentage points.
The age change of one year changes the linear predictor by 0.05, but the probability change is not 0.05: the logistic transformation maps the linear predictor to a probability. To four decimals, the probabilities are 0.4875, 0.5000, and 0.5125. The common mistake is to describe a 0.05 change in the linear predictor as a 5-percentage-point probability change. The calculation must be carried through the logistic function before reporting probability sensitivity.
Thresholds Can Make Small Changes Matter
A smooth model often changes gradually for small input changes, but a tree-based prediction can change abruptly at a split. If two otherwise similar inputs fall on opposite sides of a split, they may receive predictions from different leaves. Sensitivity analysis should therefore test plausible values around important thresholds rather than assume that a small input change produces a small prediction change.
Worked Example: Crossing a Tree Split
Method. Evaluate the fixed tree on both sides of its stated threshold. Consider a hypothetical tree that predicts annual cost in dollars as follows: if annual distance is less than 10.0 thousand kilometres, predict \(\$500\); if it is at least 10.0 thousand kilometres, predict \(\$900\). A case is recorded at 9.9 thousand kilometres. A plausible correction changes this value to 10.1 thousand kilometres, a difference of 0.2 thousand kilometres, or 200 kilometres.
Baseline prediction. Since \(9.9<10.0\), the case falls in the lower-distance leaf and receives a prediction of \(\$500\).
Perturbed prediction. Since \(10.1\ge10.0\), the corrected value falls in the other leaf and receives a prediction of \(\$900\).
Change. The signed and absolute change are both \(\$900-\$500=\$400\). Relative to the baseline, this is \((400/500)\times100=80\%\). The model produces an 80% higher prediction after the 200-kilometre input change.
The arithmetic is exact: the case crosses the stated threshold, and the two leaf predictions differ by \(\$400\). The common mistake is to infer that every 0.2-thousand-kilometre change produces an 80% increase. It does not: that result depends on crossing this particular split. The test identifies a potentially brittle prediction, but deciding whether the change is practically acceptable requires context about the cost and use of the prediction.
Design and Report a Useful Perturbation Test
Record the case’s input values, the fixed model, the prediction scale, and the baseline prediction.
Use justified changes based on measurement precision, likely correction sizes, or realistic case variation. Keep categorical values valid and respect relationships among inputs.
Use the same fitted model and the same preprocessing and prediction pipeline for baseline and perturbed inputs. Change only what the test specifies.
Report the signed and absolute change, and a relative change only when its denominator is meaningful. Explain why the perturbation is plausible and whether the response matters for the intended use.
For a useful review, one-at-a-time tests can reveal which inputs have a notable local effect, while joint scenarios can show whether combined changes behave differently. The result is case-specific: another individual may sit in a different region of the model and have different sensitivity. A single perturbation test is not evidence that the model is generally reliable or unreliable. It is a diagnostic about the chosen case and specified changes.
A common reporting trap is to compare predictions but omit the size of the input change. “The prediction rose by 20%” is difficult to interpret without stating which input changed, from what value to what value, and whether the change was plausible. Another is to change the model pipeline inadvertently—for example, by applying different preprocessing to the perturbed case. Such a comparison no longer isolates sensitivity to the input change.
Check Your Understanding
For each problem, calculate or identify the requested sensitivity result. Treat the model as fixed unless the question says otherwise.
- A hypothetical linear model predicts annual cost as \(f(a,h)=100+8a+25h\), where \(a\) is age in years and \(h\) is annual service visits. For a case with \(a=30\) and \(h=4\), calculate the baseline and the prediction when age rises by one year and visits rise by 0.4. Give the absolute and relative change. (Answer: baseline \(\$440\); perturbed prediction \(\$458\); increase \(\$18\), or 4.09%.)
- A fixed logistic model has \(\eta=-1+0.1x\) and \(p=1/(1+\exp(-\eta))\). For \(x=10\), calculate the baseline probability and the probability at \(x=11\), then report the change in percentage points to two decimals. (Answer: baseline 0.5000; at \(x=11\), 0.5250; increase 2.50 percentage points.)
- A fixed tree predicts \(\$300\) if a measurement is below 5.0 and \(\$450\) if it is at least 5.0. A case’s measurement is 4.95; a plausible correction changes it to 5.02. Calculate the signed change and relative change from baseline. (Answer: increase \(\$150\), or 50%.)
- For a differentiable prediction function, the local partial derivative with respect to \(x_1\) at a case is 12 prediction units per unit of \(x_1\). Use the first-order approximation for a small change \(\Delta x_1=-0.2\), with all other inputs unchanged. (Answer: approximate prediction change \(-2.4\) units.)
- A case’s baseline probability prediction is 0.02 and a plausible input correction changes it to 0.03. Give the absolute change in percentage points and the relative change; explain why both should be labelled. (Answer: increase 1 percentage point and 50% relative to baseline; the figures describe different scales.)