Abstract A method is given for evaluating p values in O(n) operations for a general class of invariant test statistics that can be expressed as the ratio of quadratic forms in time series regression residuals. The best known of these is the Durbin-Watson statistic, although several others have been discussed in the literature. The method is numerically exact in the sense that the user specifies the error tolerance at the outset. As with existing exact methods, the problem is reexpressed in terms of the distribution function of a single quadratic form in independent normals, which is evaluated by numerically inverting its characteristic function. Existing methods, however, calculate the characteristic function by reducing the matrix defining the quadratic form to either eigenvalue or tridiagonal form, each of which requires O(n 3) operations for sample size n, whereas the new method uses a modification of the Kalman filter to do it in O(n) operations. Moreover, the new method has minimal storage requirements, which are independent of n, whereas eigenvalue and tridiagonal methods have storage requirements increasing as n 2. The method extends to bivariate problems, where the Kalman filter algorithm has even greater computational advantages over the eigenvalue approach. The computational properties of the new method are illustrated for the Durbin-Watson statistic and a bivariate example.