Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

checkresiduals

Check that residuals from a time series model look like white noise


Description

If plot=TRUE, produces a time plot of the residuals, the corresponding ACF, and a histogram. If the degrees of freedom for the model can be determined and test is not FALSE, the output from either a Ljung-Box test or Breusch-Godfrey test is printed.

Usage

checkresiduals(object, lag, df = NULL, test, plot = TRUE, ...)

Arguments

object

Either a time series model, a forecast object, or a time series (assumed to be residuals).

lag

Number of lags to use in the Ljung-Box or Breusch-Godfrey test. If missing, it is set to min(10,n/5) for non-seasonal data, and min(2m, n/5) for seasonal data, where n is the length of the series, and m is the seasonal period of the data. It is further constrained to be at least df+3 where df is the degrees of freedom of the model. This ensures there are at least 3 degrees of freedom used in the chi-squared test.

df

Number of degrees of freedom for fitted model, required for the Ljung-Box or Breusch-Godfrey test. Ignored if the degrees of freedom can be extracted from object.

test

Test to use for serial correlation. By default, if object is of class lm, then test="BG". Otherwise, test="LB". Setting test=FALSE will prevent the test results being printed.

plot

Logical. If TRUE, will produce the plot.

...

Other arguments are passed to ggtsdisplay.

Value

None

Author(s)

Rob J Hyndman

See Also

Examples

fit <- ets(WWWusage)
checkresiduals(fit)

forecast

Forecasting Functions for Time Series and Linear Models

v8.14
GPL-3
Authors
Rob Hyndman [aut, cre, cph] (<https://orcid.org/0000-0002-2140-5352>), George Athanasopoulos [aut], Christoph Bergmeir [aut] (<https://orcid.org/0000-0002-3665-9021>), Gabriel Caceres [aut], Leanne Chhay [aut], Mitchell O'Hara-Wild [aut] (<https://orcid.org/0000-0001-6729-7695>), Fotios Petropoulos [aut] (<https://orcid.org/0000-0003-3039-4955>), Slava Razbash [aut], Earo Wang [aut], Farah Yasmeen [aut] (<https://orcid.org/0000-0002-1479-5401>), R Core Team [ctb, cph], Ross Ihaka [ctb, cph], Daniel Reid [ctb], David Shaub [ctb], Yuan Tang [ctb] (<https://orcid.org/0000-0001-5243-233X>), Zhenyu Zhou [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.