Time series tests

Durbin-Watson test

HypothesisTests.DurbinWatsonTestType
DurbinWatsonTest(X::AbstractArray, e::AbstractVector; p_compute::Symbol = :ndep)

Compute the Durbin-Watson test for serial correlation in the residuals of a regression model.

X is the matrix of regressors from the original regression model and e the vector of residuals. Note that the Durbin-Watson test is not valid if X includes a lagged dependent variable. The test statistic is computed as

\[DW = \frac{\sum_{t=2}^n (e_t - e_{t-1})^2}{\sum_{t=1}^n e_t^2}\]

where n is the number of observations.

By default, the choice of approach to compute p-values depends on the sample size (p_compute=:ndep). For small samples (n<100), Pan's algorithm (Farebrother, 1980) is employed. For larger samples, a normal approximation is used (Durbin and Watson, 1950). To always use Pan's algorithm, set p_compute=:exact. p_compute=:approx will always use the normal approximation.

Default is a two-sided p-value for the alternative hypothesis of positive or negative serial correlation. One-sided p-values can be requested by calling pvalue(x::DurbinWatsonTest; tail=) with the options :left (negative serial correlation) and :right (positive serial correlation).

References

  • J. Durbin and G. S. Watson, 1951, "Testing for Serial Correlation in Least Squares Regression: II", Biometrika, Vol. 38, No. 1/2, pp. 159-177, http://www.jstor.org/stable/2332325.
  • J. Durbin and G. S. Watson, 1950, "Testing for Serial Correlation in Least Squares Regression: I", Biometrika, Vol. 37, No. 3/4, pp. 409-428, http://www.jstor.org/stable/2332391.
  • R. W. Farebrother, 1980, "Algorithm AS 153: Pan's Procedure for the Tail Probabilities of the Durbin-Watson Statistic", Journal of the Royal Statistical Society, Series C (Applied Statistics), Vol. 29, No. 2, pp. 224-227, http://www.jstor.org/stable/2986316.

External links

source

Box-Pierce and Ljung-Box tests

HypothesisTests.BoxPierceTestType
BoxPierceTest(y, lag, dof=0)

Compute the Box-Pierce Q statistic to test the null hypothesis of independence in a time series y.

lag specifies the number of lags used in the construction of Q. When testing the residuals of an estimated model, dof has to be set to the number of estimated parameters. E.g., when testing the residuals of an ARIMA(p,0,q) model, set dof=p+q.

External links

source
HypothesisTests.LjungBoxTestType
LjungBoxTest(y, lag, dof=0)

Compute the Ljung-Box Q statistic to test the null hypothesis of independence in a time series y.

lag specifies the number of lags used in the construction of Q. When testing the residuals of an estimated model, dof has to be set to the number of estimated parameters. E.g., when testing the residuals of an ARIMA(p,0,q) model, set dof=p+q.

External links

source

Breusch-Godfrey test

HypothesisTests.BreuschGodfreyTestType
BreuschGodfreyTest(X, e, lag, start0 = true)

Compute the Breusch-Godfrey test for serial correlation in the residuals of a regression model.

X is the matrix of regressors from the original model and e the vector of residuals. lag determines the number of lagged residuals included in the auxiliary regression. Set start0 to specify how the starting values for the lagged residuals are handled. start0 = true (default) sets them to zero (as in Godfrey, 1978); start0 = false uses the first lag residuals as starting values, i.e. shortening the sample by lag.

External links

source

Jarque-Bera test

HypothesisTests.JarqueBeraTestType
JarqueBeraTest(y::AbstractVector; adjusted::Bool=false)

When adjusted is false, compute the Jarque-Bera statistic to test the null hypothesis that a real-valued vector y is normally distributed.

Note that the approximation by the Chi-squared distribution does not work well and the speed of convergence is slow. In small samples, the test tends to be over-sized for nominal levels up to about 3% and under-sized for larger nominal levels (Mantalos, 2010).

When adjusted is true, compute the Adjusted Lagrangian Multiplier statistic to test the null hypothesis that a real-valued vector y is normally distributed.

Note that the use of Adjusted Lagrangian Multiplier is preferred over Jarque-Bera for small and medium sample sizes and it is a modification to the Jarque-Bera test (Urzua, 1996).

References

  • Panagiotis Mantalos, 2011, "The three different measures of the sample skewness and kurtosis and the effects to the Jarque-Bera test for normality", International Journal of Computational Economics and Econometrics, Vol. 2, No. 1, link.

  • Carlos M. Urzúa, "On the correct use of omnibus tests for normality", Economics Letters, Volume 53, Issue 3, link.

External links

source

Augmented Dickey-Fuller test

HypothesisTests.ADFTestType
ADFTest(y::AbstractVector{T}, deterministic::Symbol, lag::Int) where T<:Real

Compute the augmented Dickey-Fuller unit root test.

y is the time series to be tested, deterministic determines the deterministic terms (options: :none, :constant, :trend, :squared_trend) and lag the number of lagged first-differences included in the test regression, respectively.

Critical values and asymptotic p-values are computed based on response surface regressions following MacKinnon (2010) and MacKinnon (1994), respectively. These may differ slightly from those reported in other regression packages as different algorithms might be used.

References

  • James G. MacKinnon, 2010, "Critical values for cointegration tests," QED Working Paper No. 1227, 2010, link.
  • James G. MacKinnon, 1994, "Approximate Asymptotic Distribution Functions for Unit-Root and Cointegration Tests", Journal of Business & Economic Statistics, Vol. 12, No. 2, pp. 167-176, link.

External links

source

Clark-West test

HypothesisTests.ClarkWestTestType
ClarkWestTest(e1::AbstractVector{<:Real}, e2::AbstractVector{<:Real}, lookahead::Integer=1)

Perform the Clark-West test of equal performance of two nested prediction models, in terms of the out-of-sample mean squared prediction errors.

e1 is a vector of forecasts from the smaller (nested) model, e2 is a vector of forecast errors from the larger model, and lookahead is the number of steps ahead of the forecast. Typically, the null hypothesis is that the two models perform equally well (a two-sided test), but sometimes we test whether the larger model performs better, which is indicated by a positive test statistic, for instance, above 1.645 for the 5% significance level (right tail test).

Implements: pvalue

References

  • Clark, T. E., West, K. D. 2006, Using out-of-sample mean squared prediction errors to test the martingale difference hypothesis. Journal of Econometrics, 135(1): 155–186.
  • Clark, T. E., West, K. D. 2007, Approximately normal tests for equal predictive accuracy in nested models. Journal of Econometrics, 138(1): 291–311.
source

Diebold-Mariano test

HypothesisTests.DieboldMarianoTestType
DieboldMarianoTest(e1::AbstractVector{<:Real}, e2::AbstractVector{<:Real}; loss=abs2, lookahead=1)

Perform the modified Diebold-Mariano test proposed by Harvey, Leybourne and Newbold of the null hypothesis that the two methods have the same forecast accuracy. loss is the loss function described in Diebold, F.X. and Mariano, R.S. (1995) Comparing predictive accuracy. Journal of Business and Economic Statistics, 13, 253-263. and lookahead is the number of steps ahead of the forecast.

References

  • Diebold, F.X. and Mariano, R.S. (1995) Comparing predictive accuracy. Journal of Business and Economic Statistics, 13, 253-263.

  • Harvey, D., Leybourne, S., & Newbold, P. (1997). Testing the equality of prediction mean squared errors. International Journal of forecasting, 13(2), 281-291.

source

White test

HypothesisTests.WhiteTestType
WhiteTest(X, e; type = :White)

Compute White's (or Breusch-Pagan's) test for heteroskedasticity.

X is a matrix of regressors and e is the vector of residuals from the original model. The keyword argument type is either :linear for the Breusch-Pagan/Koenker test, :linear_and_squares for White's test with linear and squared terms only (no cross-products), or :White (the default) for the full White's test (linear, squared and cross-product terms). X should include a constant and at least one more regressor, with observations in rows and regressors in columns. In some applications, X is a subset of the regressors in the original model, or just the fitted values. This saves degrees of freedom and may give a more powerful test. The lm (Lagrange multiplier) test statistic is T*R2 where R2 is from the regression of e^2 on the terms mentioned above. Under the null hypothesis it is distributed as Chisq(dof) where dof is the number of independent terms (not counting the constant), so the null is rejected when the test statistic is large enough.

Implements: pvalue

References

  • H. White, (1980): A heteroskedasticity-consistent covariance matrix estimator and a direct test for heteroskedasticity, Econometrica, 48, 817-838.
  • T.S. Breusch & A.R. Pagan (1979), A simple test for heteroscedasticity and random coefficient variation, Econometrica, 47, 1287-1294
  • R. Koenker (1981), A note on studentizing a test for heteroscedasticity, Journal of Econometrics, 17, 107-112

External links

source
HypothesisTests.BreuschPaganTestFunction
BreuschPaganTest(X, e)

Compute Breusch-Pagan's test for heteroskedasticity.

X is a matrix of regressors from the original model and e the vector of residuals. This is equivalent to WhiteTest(X, e, type = :linear). See WhiteTest for further details.

source