Tutorials › Regression Analysis (Undergraduate) › Showing Data Support Alongside a Nonlinear Fit

Choosing and Explaining Nonlinear Forms · Tutorial 490 of 991

Showing Data Support Alongside a Nonlinear Fit

Pair a nonlinear fit and its uncertainty band with observations or a predictor-density display to show where the data provide stronger or weaker support.

Advanced 11 min read

What You'll Learn

  • Explain why a curve and its uncertainty band do not show how predictor values are distributed.
  • Choose between plotting individual observations, a predictor rug, binned counts, or a density display.
  • Align a predictor-support display with a fitted curve using a shared predictor scale.
  • Calculate and interpret a histogram density from bin counts.
  • Distinguish a data-sparse region from a narrow or wide uncertainty band.
  • Identify display choices that can exaggerate apparent support or uncertainty.

Why Show the Data Behind a Curve?

A smooth fitted curve can look equally persuasive across its entire horizontal range. Yet the observations used to fit it may be concentrated in one region, sparse near an endpoint, or absent from an interval inside the range. A curve and its uncertainty band describe an estimated relationship and uncertainty under a model; on their own, they do not show where predictor values were observed.

Showing the observed predictor values alongside the fit helps readers judge which parts of the curve are closely surrounded by data and which parts depend more heavily on the model’s structure. The display does not replace uncertainty intervals, establish that a model is correct, or show that a relationship is causal. It supplies a different piece of information: the distribution of predictor values in the data used for the fit.

Definition: Data support along the predictor axis refers to how the observed predictor values are distributed across the range where a fitted relationship is displayed. A scatterplot, rug plot, histogram, or density display can show this distribution. It describes the observed data, not the certainty of the fitted curve by itself.

Model and Display Assumptions

Let \(Y_i\) be the outcome for observation \(i\), and let \(x_i\) be its predictor value, for \(i=1,\ldots,n\). A fitted nonlinear regression model represents the conditional mean of the outcome as a function of the predictor:

$$ Y_i=f(x_i;\boldsymbol{\theta})+\varepsilon_i, \qquad E(\varepsilon_i\mid x_i)=0. $$

Here, \(f\) is the chosen curve form, \(\boldsymbol{\theta}\) denotes its parameters, and \(\varepsilon_i\) is the error. The fitted curve estimates the conditional mean relationship. For the usual regression-based uncertainty calculations, observations must be independent, the mean function and error structure must be appropriate, and the variance assumptions used to calculate standard errors must be reasonable. A particular method may require additional assumptions; for example, the ordinary least-squares \(t\)-intervals used in the first worked example use normally distributed, constant-variance errors.

Before interpreting a plot, check that the curve and band come from a fitting and uncertainty procedure appropriate for the model. Then make clear what is being displayed: commonly, a pointwise confidence band for the conditional mean, rather than a prediction interval for a future individual outcome. The predictor-support display is a separate layer or panel. It does not repair a poor model or make an unsupported part of the curve reliable.

Key distinction: The uncertainty band summarizes uncertainty in the fitted mean under the stated model and method. The observations or predictor-density display show where predictor values occur in the analyzed data. Neither display should be used as a substitute for the other.

Choosing a Display for Predictor Support

When the outcome observations can be plotted without obscuring one another, a scatterplot with the fitted curve and band is often the most direct choice. Each point shows both the predictor and outcome, so readers can see the data’s location relative to the fitted relationship. With many observations or heavy overlap, points may hide one another. A transparent plotting symbol, small vertical jitter used only to separate marks, or a rug plot can make the predictor locations more visible.

A rug plot places a short mark along an axis at each observed predictor value. It shows locations without assigning an arbitrary bin to each observation, but a dense group of marks may merge visually. A histogram or density display summarizes the distribution instead. A histogram is affected by its chosen bin width and boundaries; a density curve smooths the distribution and depends on its smoothing choice. Neither should be presented as if it were the outcome curve.

For clarity, a useful design is to place a predictor histogram or density display below the fitted curve and band, with both panels sharing the same horizontal predictor scale. This makes it easy to align a dense region in the lower panel with the corresponding part of the curve above. If the support display is overlaid in the same panel, use a clearly identified second vertical axis only when it remains legible. Do not let different vertical scales suggest that predictor density and outcome have a common unit or meaning.

  • Label the predictor and outcome axes with their units.
  • State whether the band is pointwise or simultaneous and whether it describes the fitted mean or future outcomes.
  • Use a consistent predictor range across the fit and support panels, and show where the observations lie.
  • Describe a density as the distribution of observed predictor values, not as a measure of model fit or outcome probability.

Worked Example: Adding Observations to a Quadratic Fit

Suppose a hypothetical experiment records enzyme activity, in activity units, at 24 observed concentrations, measured in milligrams per litre. A quadratic regression model is fitted to these data. The plot will show all 24 outcome observations, the fitted curve, and a pointwise 95% confidence band for the conditional mean. The concentrations fall into the following intervals:

Concentration interval (mg/L)Number of observations
0 to less than 23
2 to less than 45
4 to less than 68
6 to less than 85
8 to 103

The counts sum to \(3+5+8+5+3=24\), as required. They show that more observations fall in the middle intervals than near the ends. In the scatterplot, the points themselves show the relationship between concentration and activity; the fitted curve should not conceal them.

For illustration, suppose the fitted mean is \(\hat{y}=12+4.8x-0.32x^2\), with \(x\) in mg/L and \(\hat{y}\) in activity units. At \(x=5\) mg/L, the fitted value is \(12+4.8(5)-0.32(5^2)=12+24-8=28\) activity units. Suppose the estimated standard error of the fitted mean there is 1.10 activity units. With 24 observations and three fitted coefficients, the residual degrees of freedom are \(df=24-3=21\). Using \(t^*=2.080\), the pointwise interval is \(28\pm2.080(1.10)=28\pm2.288\), or approximately 25.71 to 30.29 activity units.

This interval describes uncertainty in the conditional mean at 5 mg/L under the model and assumptions; it is not an interval for an individual future outcome. The plot’s observations and interval counts provide separate context: the concentration 5 mg/L is in the interval containing the largest number of the 24 observations. Readers can see both the estimated mean and where the data lie without treating the band as a display of data density.

Showing Predictor Density in an Aligned Panel

A histogram can make the concentration of predictor values easier to judge when plotting every observation would produce a crowded display. For bin \(j\), with count \(c_j\), sample size \(n\), and bin width \(w_j\), the histogram density height is \(c_j/(n w_j)\). Its units are the reciprocal of the predictor’s units. With equal-width bins, larger heights indicate more observations per unit of predictor range in that bin.

The normalization makes the area across all bins equal one: each bin’s area is \([c_j/(n w_j)]w_j=c_j/n\). Adding those areas gives \(\sum_j c_j/n=n/n=1\), provided the bins cover all observations. This is why a density histogram’s vertical axis is not a count axis. A count histogram instead reports \(c_j\) directly.

Worked Example: Calculating a Predictor-Density Display

Consider a second, hypothetical data set with 40 observations of a predictor \(x\), measured in concentration units. A histogram uses five bins, each 2 units wide. The bin counts are 2, 8, 14, 10, and 6, which sum to 40. The density heights are calculated as follows:

Predictor intervalCount \(c_j\)Density \(c_j/(40\times2)\)
0 to less than 220.025 per unit
2 to less than 480.100 per unit
4 to less than 6140.175 per unit
6 to less than 8100.125 per unit
8 to 1060.075 per unit

For example, the first height is \(2/(40\times2)=0.025\) per unit. The bin areas are \(0.050\), \(0.200\), \(0.350\), \(0.250\), and \(0.150\); these add to 1. The largest density height is in the 4-to-less-than-6 interval, so that interval has the greatest observed concentration of predictor values among these equal-width bins.

Suppose an accompanying quadratic fit is \(\hat{y}=12+4.8x-0.32x^2\), in outcome units, and at \(x=6\) the standard error of the fitted mean is 1.30 outcome units. Then \(\hat{y}=12+4.8(6)-0.32(6^2)=29.28\) outcome units. If the model has three fitted coefficients, \(df=40-3=37\). With \(t^*=2.026\), the pointwise interval is \(29.28\pm2.026(1.30)=29.28\pm2.634\), or approximately 26.65 to 31.91 outcome units.

Placing the histogram below the curve with a shared \(x\)-axis aligns its highest bar with the corresponding curve segment. The bar height does not determine the width of the confidence band. It only summarizes how the observed predictor values are distributed, using the stated binning choice.

When the Predictor Range Contains a Gap

The overall minimum and maximum of a predictor do not guarantee that observations are available throughout the interval between them. Two clusters can sit at opposite ends of the range, leaving a gap where a fitted curve is drawn but no observations occur. In that setting, a rug plot, scatterplot, or binned display can reveal a limitation that the numerical range alone hides.

A curve evaluated inside the minimum-to-maximum range may still have weak local data support. Its estimated value is determined by the model fitted to the available observations, and its uncertainty depends on the fitting method and assumptions. Showing a gap helps readers distinguish the curve’s numerical domain from regions where nearby observations directly inform the fit.

Worked Example: Revealing an Unsupported Interior Region

Suppose a hypothetical data set contains 18 observations of \(x\), measured in hours. Nine observations lie between 0 and 2 hours, and nine lie between 8 and 10 hours; none lie between 2 and 8 hours. A fitted curve is displayed across 0 to 10 hours. A rug plot or histogram below it makes the empty interior interval visible.

For illustration, the fitted mean at 5 hours is \(\hat{y}=28\) outcome units, with estimated standard error 2.00 units. Suppose the fit has three coefficients and uses ordinary least-squares \(t\)-inference. Then \(df=18-3=15\); using \(t^*=2.131\), the pointwise interval is \(28\pm2.131(2.00)=28\pm4.262\), or approximately 23.74 to 32.26 units.

This calculation gives the stated model-based interval, but the display also shows that there are no observations near 5 hours. The interval should therefore be read with that design feature in mind: the curve’s value at 5 hours is inferred from a fit to two separated groups, not from a concentration of nearby measurements. The band does not make those missing observations appear, and the empty region does not by itself prove that the fitted value is wrong.

Reading the Combined Display Carefully

A combined display is most useful when readers can identify which marks represent observations, which line represents the fitted mean, and which shaded area represents uncertainty. Include a legend where needed, use distinct visual styles, and avoid drawing a smooth support curve in a way that could be mistaken for another fitted outcome relationship. If the support display is in a separate panel, align its predictor limits and tick marks with the curve panel.

A histogram or density curve summarizes the marginal distribution of the predictor in the analyzed data. It does not show whether predictor coverage differs across groups, whether measurements were collected under a particular sampling design, or whether the model’s assumptions hold. If a density curve is used, state that it is an estimate based on smoothing; it can look nonzero in a region with few or no actual observations. Showing a rug or individual predictor marks as well can clarify that distinction.

Support is also not the same as precision. A confidence band may be wide in a region with many observations because outcomes are variable or the fitted form is difficult to estimate there. Conversely, a band may look narrow in a region with little local support because the model imposes a restrictive shape or because uncertainty is being assessed under assumptions that do not reflect the gap. The display lets readers inspect both pieces of information; it does not make them interchangeable.

Common pitfall: A reader sees a smooth curve and a narrow band across the full predictor range and concludes that the data support the relationship equally well everywhere. The correction is to inspect the observed predictor locations as well as the band. The band represents model-based uncertainty under its assumptions; a rug, scatterplot, or aligned density display shows where the analyzed predictor values actually occur.

Practical Checklist

1
Identify the fitted quantity.
State whether the curve estimates a conditional mean or another target, and identify what the band represents.
2
Choose a support display.
Use observations when the scatter is readable; use a rug, histogram, or density display when a summary of predictor locations is clearer.
3
Align and label the displays.
Use the same predictor scale, label units, and distinguish support marks from the fitted outcome curve and its band.
4
Describe limitations without overstating them.
Point out sparse regions or gaps, but do not treat support as proof of model correctness or a density display as a measure of uncertainty.

Check Your Understanding

Answer each question using the distinction between predictor support and fitted-curve uncertainty.

  1. What additional information does a rug plot provide that a confidence band does not?
  2. A histogram bin contains 12 of 60 observations and has width 3 predictor units. What is its density height, and what are its units?
  3. Why should a histogram below a fitted curve generally share the curve’s predictor-axis scale?
  4. A fitted curve is shown across the observed minimum and maximum, but a rug plot reveals a large gap in the middle. What does the plot establish, and what does it not establish?
  5. Why is a narrow confidence band not sufficient evidence that predictor values are densely observed in that region?