Why Plot a Prediction Grid?
A fitted polynomial equation can be difficult to interpret by looking at its coefficients alone. A plot of its predicted mean across the predictor values actually observed makes the model’s shape easier to see: where the curve rises or falls, how its slope changes, and whether a turning point lies within the data range. The key is to calculate predictions at a deliberate set of predictor values rather than draw a curve from a few arbitrary points.
A prediction grid is a set of selected values of the predictor at which the fitted model’s mean response is calculated. Connecting these predictions in order gives a visual representation of the fitted mean function. The grid helps display the model; it does not create new observations or add information to the data.
The Model and the Plotting Target
For a quadratic regression, the model for observation \(i\) is
For a cubic regression, a cubic term is added:
Here \(Y_i\) is the response, \(x_i\) is the predictor, the \(\beta\) terms are model coefficients, and \(\varepsilon_i\) is the error. For interpreting a fitted mean curve, the central assumption is that the conditional mean response follows the stated polynomial form: \(E(Y_i\mid x_i)\) equals the polynomial part of the model. The errors have mean zero conditional on the predictor. The observations should be independent for the usual regression analysis; constant error variance and normal errors are relevant to familiar standard-error and inference procedures, but are not required simply to calculate and plot fitted means.
Once a model has been fitted, its estimated coefficients are written with hats. The fitted mean at a predictor value \(x\) is denoted by \(\hat{y}(x)\). For example, in a quadratic fit, \(\hat{y}(x)=\hat{\beta}_0+\hat{\beta}_1x+\hat{\beta}_2x^2\). This is an estimated mean response, not a guarantee about any one observation.
The usual grid includes both observed endpoints. For \(m\) equal intervals, its values are \(x_j=x_{\min}+j(x_{\max}-x_{\min})/m\), for \(j=0,1,\ldots,m\). A larger \(m\) produces a denser visual curve, but does not change the fitted model. In practice, a handful of points can be useful in a table, while plotting software can evaluate the model at many closely spaced values to draw a smooth line.
Worked Example: A Quadratic Curve and Its Turning Point
Worked Example: A Quadratic Curve and Its Turning Point
Suppose hypothetical data on a response \(Y\), measured in points, were collected for predictor values \(x\) from 0 to 6 units. A fitted quadratic model is
Calculate fitted means at each integer value in the observed range. Substituting the grid values gives:
Plotting these points in order gives a downward-opening curve. Its local slope is the derivative \(\hat{y}'(x)=3-x\), and its curvature is described by the second derivative \(\hat{y}''(x)=-1\). The slope is positive below \(x=3\), zero at \(x=3\), and negative above \(x=3\). Thus the curve reaches its maximum at \(x=3\), where the fitted mean is 16.5 points. The curve is concave down throughout the range.
The fitted mean rises from 12 points at \(x=0\) to 16.5 points at \(x=3\), then falls to 12 points at \(x=6\). This describes the fitted average response, not the response that every individual with a given predictor value would have.
Reading Slopes and Curvature From the Curve
For a fitted quadratic \(\hat{y}(x)=\hat{\beta}_0+\hat{\beta}_1x+\hat{\beta}_2x^2\), the derivative is \(\hat{y}'(x)=\hat{\beta}_1+2\hat{\beta}_2x\). It gives the model’s instantaneous change in fitted mean per one-unit increase in \(x\), with units of response per predictor unit. The second derivative is \(\hat{y}''(x)=2\hat{\beta}_2\), so the quadratic’s curvature has the same direction everywhere: upward if \(\hat{\beta}_2>0\), downward if \(\hat{\beta}_2<0\).
For a cubic, \(\hat{y}(x)=\hat{\beta}_0+\hat{\beta}_1x+\hat{\beta}_2x^2+\hat{\beta}_3x^3\), the first and second derivatives are \(\hat{y}'(x)=\hat{\beta}_1+2\hat{\beta}_2x+3\hat{\beta}_3x^2\) and \(\hat{y}''(x)=2\hat{\beta}_2+6\hat{\beta}_3x\). The slope can change across the range, and the curvature can change direction. A grid plot helps show those changes, while selected derivative values can make them explicit.
A grid cannot replace the derivative when an exact local slope or turning point is needed. Instead, the plot and calculations complement each other: the graph communicates the overall fitted shape, and the derivative gives its slope at a specified predictor value. Turning points occur where the first derivative is zero, but a plotted curve should only be used to discuss their location in relation to the observed range.
Worked Example: Plotting a Cubic With Two Turning Points
Worked Example: Plotting a Cubic With Two Turning Points
Consider hypothetical measurements with \(x\) ranging from 0 to 6 units and a response measured in units of \(Y\). Suppose the fitted cubic is
Using the integer grid from 0 through 6, the fitted means are:
The first derivative is \(\hat{y}'(x)=4-2.4x+0.3x^2\). Setting it equal to zero gives \(0.3x^2-2.4x+4=0\), with solutions
Both stationary points lie inside the observed range. The grid suggests a rise to a local maximum between \(x=2\) and \(x=3\), followed by a decline to a local minimum between \(x=5\) and \(x=6\). The derivative confirms the approximate locations. For instance, \(\hat{y}'(1)=1.9\) response units per predictor unit, \(\hat{y}'(4)=-0.8\), and \(\hat{y}'(6)=0.4\). The curve rises at \(x=1\), falls at \(x=4\), and rises again at \(x=6\). The plotted values and slopes together make the cubic’s changing direction clearer than its coefficients alone.
Choosing Grid Values and Displaying the Curve
A useful grid starts with the minimum and maximum predictor values in the data and includes enough values between them to reveal the fitted shape. The spacing need not always be equal. Use a denser grid where the curve bends sharply or where a turning point needs to be shown clearly; use a simpler grid for a compact table. If the predictor was centered or rescaled when fitting, calculate predictions using the same representation used by the model, while labeling the horizontal axis in a form readers can understand.
For a quadratic, an evenly spaced grid often makes the constant curvature easy to see. For a cubic, more points may be helpful because the slope and curvature can vary across the range. A plot should use the grid values in increasing order and connect them as a curve, not as unrelated bars or categories. The response axis should include units, and the horizontal axis should identify the predictor and its units.
A short derivation explains why grid spacing affects how a curve appears. For a quadratic and equally spaced grid values separated by \(h\), the second difference of fitted means is constant:
The constant and linear terms cancel, leaving a value determined by the quadratic coefficient and grid spacing. This is the discrete counterpart of the quadratic’s constant second derivative \(2\hat{\beta}_2\). For a cubic, the second differences need not be constant, which is another reason to inspect the curve across the full range rather than infer its shape from a single interval.
Worked Example: A Centered Predictor and an Unevenly Informative Grid
Worked Example: A Centered Predictor and an Unevenly Informative Grid
Suppose a hypothetical fitted model uses \(u=x-16\), where \(x\) is a measurement in original units and the observed values range from 10 to 22. The fitted quadratic mean, in response units, is
Choose five equally spaced values of the original predictor: \(x=10,13,16,19,22\). These correspond to \(u=-6,-3,0,3,6\). The grid predictions are:
The derivative with respect to \(u\) is \(\hat{y}'(u)=2-0.2u\), and the second derivative is \(-0.2\). Across the observed range \(u=-6\) to \(u=6\), the slope decreases from 3.2 to 0.8 response units per predictor unit but stays positive. Therefore the curve rises throughout the observed range while bending downward. The turning point would be at \(u=10\), found by solving \(2-0.2u=0\), but that value is outside the grid and the observed range. The plotted fitted means communicate the rising, concave-down shape without suggesting a turning point within the data.
What the Plot Does—and Does Not—Show
A polynomial prediction plot displays the model’s estimated conditional mean. It does not display the observed responses unless those data are added separately, and it does not show the variation of individual responses around the mean. If observations are included, they should be visually distinguished from the fitted curve. A fitted mean at a grid point is not an individual-level prediction.
The range matters: the grid should be designed to describe fitted behavior where predictor values were observed. A curve can be calculated for values outside that range, but a calculated value alone does not make the model’s shape trustworthy there. Keep the plotted grid aligned with the data range when the purpose is to communicate how the fitted polynomial describes the observed predictors.
Grid density also does not measure certainty. Adding more grid points makes a line look smoother, but does not reduce uncertainty in the fitted coefficients or in the estimated mean. Any uncertainty display must come from an appropriate regression calculation, not from the number of points used to draw the curve.
Common Mistakes
- Using a few arbitrary points to suggest the whole shape. A sparse grid can conceal bends or turning points. Include enough ordered values across the observed range to show the curve’s behavior.
- Calling fitted means observed responses. The grid contains values calculated from the fitted equation, not new data. Label the line as a fitted mean curve.
- Inferring a slope from a coefficient alone. In a polynomial model, the slope generally depends on \(x\). Use the derivative at the predictor value of interest or describe changes over a stated interval.
- Reading a plotted bend as proof of a real pattern. The plot shows the fitted model’s shape. It does not establish that the model is appropriate or that the association is causal.
- Assuming a denser grid gives more evidence. More calculation points improve the visual rendering only; they do not increase the sample size or precision.
Check Your Understanding
Use the model and plotting principles in this tutorial to answer the following questions.
- A predictor ranges from 4 to 16. Write four equally spaced grid values that include both endpoints.
- For a fitted quadratic, what does the sign of the second derivative tell you about the direction of curvature?
- A fitted cubic rises, falls, and then rises again across the observed range. What does this suggest about how its derivative behaves?
- Why does evaluating a fitted model at 100 grid points not make its predictions more precise than evaluating it at 10?
- Explain the difference between a fitted mean at \(x=5\) and an individual response observed at \(x=5\).