Residual plots can be used to assess whether a linear regression model is appropriate for the data {1-2}: if the points in a residual plot are randomly dispersed around the horizontal axis, a linear regression model is appropriate for the data; otherwise, a non-linear model is more appropriate. Is there any standard metric to quantify how randomly dispersed the points are around the horizontal axis in a residual plot?

Examples of residual plots:

The first plot shows a random pattern, indicating a good fit for a linear model:

enter image description here

The patterns in the following plot are non-random (U-shaped), suggesting a better fit for a non-linear model.

enter image description here


  • 1
    $\begingroup$ Possible translation of question: "what are some goodness-of-fit tests for linear regression models?" $\endgroup$
    – whuber
    Dec 9, 2016 at 14:52
  • 1
    $\begingroup$ @whuber Do goodness-of-fit tests measure how randomly dispersed the points are around the horizontal axis in a residual plot? E.g., the coefficient of determination doesn't do so I believe. $\endgroup$ Dec 9, 2016 at 14:57
  • 1
    $\begingroup$ That proves the coefficient of determination is not a goodness-of-fit statistic! Yes, GoF statistics--practically by definition--test for various kinds of deviations between the residual behavior and ideal residual behavior. There exist many GoF tests and you can readily construct even more for special purposes: simply posit a more complex alternative model and test it for significance. E.g., add quadratic terms in the regressors as a crude way of testing nonlinearity. $\endgroup$
    – whuber
    Dec 9, 2016 at 15:11

1 Answer 1


The whole reason for plotting residuals is so as to use your eye rather than to rely on a numerical metric. There many different ways in which residuals can fail to be random. Metrics can only be written for particular different types of failure, whereas your eye and your marvelous pattern recognizing brain can respond to anything unexpected.

If you are fitting a simple linear regression and your only aim is to check whether a nonlinear relationship would be better, then you can try a non-parametric curve. In R, the code might go like this:

    fit.linear <- lm(y~x)
    NS <- ns(x,df=3)
    fit.nonlinear <- lm(y~NS)
    anova(fit.linear, fit.nonlinear)

The above code fits a cubic regression spline with (in effect) 3 parameters and then uses an anova to test whether the nonlinear curve is a significant improvement over the linear. The ns function constructs a matrix of natural basis vectors for the regression spline.

Alternatively you could fit a polynomial trend, but splines tend to be more flexible and stable.

Here's an example run. The metric here is the p-value, which is 6.5e-9.

    > x <- 1:40
    > y <- rnorm(40)+((x-20)/10)^2
    > plot(x,y)
    > fit.linear <- lm(y~x)
    > library(splines) # import ns() function
    > NS <- ns(x,df=3)
    > fit.nonlinear <- lm(y~NS)
    > anova(fit.linear, fit.nonlinear)
    Analysis of Variance Table

    Model 1: y ~ x
    Model 2: y ~ NS
      Res.Df    RSS Df Sum of Sq      F    Pr(>F)    
    1     38 90.309                                  
    2     36 31.698  2    58.611 33.283 6.537e-09 ***
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

    > lines(x,fitted(fit.linear))
    > lines(x,fitted(fit.nonlinear),col="red")

Plot showing linear and spline trends

  • 1
    $\begingroup$ Thanks, true, we are good at it, but human time is more expensive than CPU time :) $\endgroup$ Dec 9, 2016 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.