statsmodels.stats.diagnostic.acorr_lm#

statsmodels.stats.diagnostic.acorr_lm(resid, nlags=None, store=False, *, period=None, ddof=0, cov_type='nonrobust', cov_kwds=None, use_namedtuple=None)[source]#

Lagrange Multiplier tests for autocorrelation

This is a generic Lagrange Multiplier test for autocorrelation. Returns Engle’s ARCH test if resid is the squared residual array. Breusch-Godfrey is a variation on this test with additional exogenous variables.

Parameters:
residarray_like

Time series to test.

nlagsint, default None

Highest lag to use.

storebool, default False

If true then the intermediate results are also returned.

periodint, default None

The period of a Seasonal time series. Used to compute the max lag for seasonal data which uses min(2*period, nobs // 5) if set. If None, then the default rule is used to set the number of lags. When set, must be >= 2.

ddofint, default 0

The number of degrees of freedom consumed by the model used to produce resid. The default value is 0.

cov_typestr, default “nonrobust”

Covariance type. The default is “nonrobust” which uses the classic OLS covariance estimator. Specify one of “HC0”, “HC1”, “HC2”, “HC3” to use White’s covariance estimator. All covariance types supported by OLS.fit are accepted.

cov_kwdsdict, default None

Dictionary of covariance options passed to OLS.fit. See OLS.fit for more details.

use_namedtuplebool, optional

Flag indicating whether to return the results as an LMTestResult NamedTuple instead of a plain tuple. When store=True the NamedTuple holds the same five elements as the legacy tuple, so it unpacks identically and is always returned, with no warning. When store=False the legacy four-element tuple is returned by default and a FutureWarning is issued.

Deprecated since version 0.15.0: In release 0.16.0 or after July 2027, whichever is later, the default will change to always return an LMTestResult. Set use_namedtuple=True to opt in now, or use_namedtuple=False to silence the warning and keep the current return type.

Returns:
LMTestResult

If use_namedtuple=True, a NamedTuple with fields lm, lmpval, fval, fpval, and res_store (res_store is None when not computed). See LMTestResult.

Otherwise (the deprecated default), a plain tuple made up of:
lmfloat

Lagrange multiplier test statistic.

lmpvalfloat

The p-value for Lagrange multiplier test.

fvalfloat

The f statistic of the F test, alternative version of the same test based on F test for the parameter restriction.

fpvalfloat

The pvalue of the F test.

res_storeResultsStore, optional

Intermediate results. Only returned if store=True.

See also

het_arch

Conditional heteroskedasticity testing.

acorr_breusch_godfrey

Breusch-Godfrey test for serial correlation.

acorr_ljungbox

Ljung-Box test for serial correlation.

Notes

The test statistic is computed as (nobs - ddof) * r2 where r2 is the R-squared from a regression on the residual on nlags lags of the residual.