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.
- nlags
int,defaultNone Highest lag to use.
- storebool,
defaultFalse If true then the intermediate results are also returned.
- period
int,defaultNone 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.
- ddof
int,default0 The number of degrees of freedom consumed by the model used to produce resid. The default value is 0.
- cov_type
str,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.fitare accepted.- cov_kwds
dict,defaultNone 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
LMTestResultNamedTuple instead of a plain tuple. Whenstore=Truethe NamedTuple holds the same five elements as the legacy tuple, so it unpacks identically and is always returned, with no warning. Whenstore=Falsethe legacy four-element tuple is returned by default and aFutureWarningis 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. Setuse_namedtuple=Trueto opt in now, oruse_namedtuple=Falseto silence the warning and keep the current return type.
- Returns:
LMTestResultIf
use_namedtuple=True, a NamedTuple with fieldslm,lmpval,fval,fpval, andres_store(res_storeisNonewhen not computed). SeeLMTestResult.Otherwise(thedeprecateddefault),aplaintuplemadeupof:- lm
float Lagrange multiplier test statistic.
- lmpval
float The p-value for Lagrange multiplier test.
- fval
float The f statistic of the F test, alternative version of the same test based on F test for the parameter restriction.
- fpval
float The pvalue of the F test.
- res_store
ResultsStore,optional Intermediate results. Only returned if store=True.
See also
het_archConditional heteroskedasticity testing.
acorr_breusch_godfreyBreusch-Godfrey test for serial correlation.
acorr_ljungboxLjung-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.