Regression - Diagnostic - Serial Correlation (Durbin-Watson) extension

From Q
Jump to: navigation, search

Performs a Durbin-Watson test of serial correlation (auto-correlation) on the residuals of a model.


The following table shows the output from running this diagnostic on an output from Regression - Ordered Logitordered logit.

Technical details

This test checks an aspect of the assumption of regression that residuals are independent. It works by testing to see if there is any positive or negative correlation between residuals, based on their order in the data. It tests for first order serial correlation (i.e., that a residual is correlated with the adjacent residuals). A permutation test is performed, which makes the test applicable to any model that has residuals (i.e., the implementation does not assume that the residuals are normal with a constant variance).

For Regression - Binary Logit, Regression - Ordered Logit, and Regression - Multinomial Logitbinary logit, ordered logit, and multinomial logit, the residuals used in the test are the difference between the observed category number (1, 2, ...) and the category with the highest probability of being predicted.

Consequences of serial correlation

  1. Serial correlation violates the statistical testing assumptions of regression models. This may mean that results are shown as being significant that should not be shown as significant.
  2. Serial correlation can arise when the model's assumptions about causality are incorrect. For example, when:
    • Linear effects are used in models and non-linear models are more appropriate.
    • Data is clustered, but this clustering has been ignored in the model.
    • There are lagged feedback mechanisms in time series models. E.g., sales today may be a function of advertising last month.

Remedies for serial correlation

There is no straightforward remedy for serial correlation. Where it exists, the only safe approach is to identify what has caused it, and then specify a model that takes this into account. When estimating time series models Newey West standard errors can be computed, which adjust for serial correlation.


Durbin, J., & Watson, G. S. (1950). Testing for serial correlation in least squares regression: I. Biometrika, 37(3/4), 409-428.

Bock, T. (2018, April 9). What is autocorrelation? [Blog post]. Accessed from


includeWeb("QScript R Output Functions");

var is_displayr = (!!Q.isOnTheWeb && Q.isOnTheWeb());
if (!is_displayr)
    if (Q.fileFormatVersion() >= 17.13)
        alert("Please update Q to use this feature from the extension button, or run it from the menu via Create > Regression > Diagnostic > Serial Correlation (Durbin-Watson).");

function main() {

    // The following 2 variables contain information specific to this diagnostic.
    var required_class = "Regression";
    var output_name_suffix = "serial.correlation";
    var item = checkSelectedItemClass(required_class);
    if (item == null)
        return false;
    var r_name = stringToRName(item.referenceName);

    // The following lines contain the R code to run
   var expression = "flipFormat::SignificanceTest(\n    flipRegression::DurbinWatson(" + r_name
        + "),\n    'Test of Residual Serial Correlation (Durbin-Watson)',\n    vars = NULL,\n = '"
        + + "',\n    reg.sample.description = " + r_name + "$sample.description)";

    return createROutput(item, expression, output_name_suffix);