Skip to content

Perform McLeod-Li test

Source: man/performMcLeodLiTest.Rd · Help: ?performMcLeodLiTest

Applies the Ljung-Box test to squared residuals.

Usage

performMcLeodLiTest(model, data = NULL, lags = 10)

Arguments

model
an object of class lm.
data
optional data frame the model was fitted to. When NULL, the default, the model frame of model is used. The statistic is computed from the residuals of model, so data does not change the result; it is accepted so that every test takes (model, data, ...). Before 0.15.0 the second argument was lags: a number passed there by position is still read as lags, with a warning that shows the new call; that form stops working in 1.0.0.
lags
number of lags for the Ljung-Box test.

Value

An object of class htest containing the test statistic, p-value and degrees of freedom.

Details

Serial correlation in \(e_t^2\) indicates conditional heteroscedasticity. The Ljung-Box statistic is compared to a chi-square distribution with the chosen number of lags.

Supported models

It accepts an lm and a glm with the Gaussian family and the identity link, unweighted or with positive weights, a fitWLS() fit and, since 0.16.0, a rank-deficient fit, which it tests on the estimable part of its design: it gives the value of the same model fitted without the aliased columns. It refuses a glm of another family or link, a survey::svyglm() fit, a fit with a zero weight, a coefficient that is not finite for another reason, and data that lack rows or variables of the fit. Since 0.16.0 it is built on the model context, and also refuses a multivariate lm ("needs a model with one response"), a fit whose coefficients, residuals or weights were changed after the fit, and a fit with model = FALSE whose model frame, rebuilt from the data it was fitted to, no longer holds its response, because those data changed after the fit, with or without data. A fit with model = FALSE whose data are gone is tested on data that give its response and fitted values, and refused without them. The test reads nothing from data, and since 0.16.0 matches it to the observations of the fit as every test does: data with row names of their own in any order, data that number their rows (a tibble, a data.table) in the order of the fit; other numbered data, rows in front of those of the fit and repeated row names are refused, where it gave the value of the fit. Which model each test accepts, and why, is set out in test_results, under Supported models.

References

McLeod, A. I., & Li, W. K. (1983). Diagnostic checking ARMA time series models using squared-residual autocorrelations. Journal of Time Series Analysis, 4(4), 269–273.

Examples

 data(mtcars)
 m <- lm(mpg ~ wt + qsec, data = mtcars)
 performMcLeodLiTest(m, lags = 10)