statsmodels.tsa.ar_model.AutoReg¶
-
class
statsmodels.tsa.ar_model.
AutoReg
(endog, lags, trend='c', seasonal=False, exog=None, hold_back=None, period=None, missing='none', *, deterministic=None, old_names=None)[source]¶ Autoregressive AR-X(p) model.
Estimate an AR-X model using Conditional Maximum Likelihood (OLS).
- Parameters
- endogarray_like
A 1-d endogenous response variable. The dependent variable.
- lags{
int
,list
[int
]} The number of lags to include in the model if an integer or the list of lag indices to include. For example, [1, 4] will only include lags 1 and 4 while lags=4 will include lags 1, 2, 3, and 4.
- trend{‘n’, ‘c’, ‘t’, ‘ct’}
The trend to include in the model:
‘n’ - No trend.
‘c’ - Constant only.
‘t’ - Time trend only.
‘ct’ - Constant and time trend.
- seasonalbool
Flag indicating whether to include seasonal dummies in the model. If seasonal is True and trend includes ‘c’, then the first period is excluded from the seasonal terms.
- exogarray_like,
optional
Exogenous variables to include in the model. Must have the same number of observations as endog and should be aligned so that endog[i] is regressed on exog[i].
- hold_back{
None
,int
} Initial observations to exclude from the estimation sample. If None, then hold_back is equal to the maximum lag in the model. Set to a non-zero value to produce comparable models with different lag length. For example, to compare the fit of a model with lags=3 and lags=1, set hold_back=3 which ensures that both models are estimated using observations 3,…,nobs. hold_back must be >= the maximum lag in the model.
- period{
None
,int
} The period of the data. Only used if seasonal is True. This parameter can be omitted if using a pandas object for endog that contains a recognized frequency.
- missing
str
Available options are ‘none’, ‘drop’, and ‘raise’. If ‘none’, no nan checking is done. If ‘drop’, any observations with nans are dropped. If ‘raise’, an error is raised. Default is ‘none’.
- deterministic
DeterministicProcess
A deterministic process. If provided, trend and seasonal are ignored. A warning is raised if trend is not “n” and seasonal is not False.
- old_namesbool
Flag indicating whether to use the v0.11 names or the v0.12+ names. After v0.12 is released, the default names will change to the new names.
See also
statsmodels.tsa.statespace.sarimax.SARIMAX
Estimation of SARIMAX models using exact likelihood and the Kalman Filter.
Examples
>>> import statsmodels.api as sm >>> from statsmodels.tsa.ar_model import AutoReg >>> data = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] >>> out = 'AIC: {0:0.3f}, HQIC: {1:0.3f}, BIC: {2:0.3f}'
Start by fitting an unrestricted Seasonal AR model
>>> res = AutoReg(data, lags = [1, 11, 12]).fit() >>> print(out.format(res.aic, res.hqic, res.bic)) AIC: 5.945, HQIC: 5.970, BIC: 6.007
An alternative used seasonal dummies
>>> res = AutoReg(data, lags=1, seasonal=True, period=11).fit() >>> print(out.format(res.aic, res.hqic, res.bic)) AIC: 6.017, HQIC: 6.080, BIC: 6.175
Finally, both the seasonal AR structure and dummies can be included
>>> res = AutoReg(data, lags=[1, 11, 12], seasonal=True, period=11).fit() >>> print(out.format(res.aic, res.hqic, res.bic)) AIC: 5.884, HQIC: 5.959, BIC: 6.071
- Attributes
ar_lags
The autoregressive lags included in the model
df_model
The model degrees of freedom.
endog_names
Names of endogenous variables.
exog_names
Names of exogenous variables included in model
hold_back
The number of initial obs.
seasonal
Flag indicating that the model contains a seasonal component.
Methods
fit
([cov_type, cov_kwds, use_t])Estimate the model parameters.
from_formula
(formula, data[, subset, drop_cols])Create a Model from a formula and dataframe.
hessian
(params)The Hessian matrix of the model.
information
(params)Fisher information matrix of model.
Initialize the model (no-op).
loglike
(params)Log-likelihood of model.
predict
(params[, start, end, dynamic, exog, …])In-sample prediction and out-of-sample forecasting.
score
(params)Score vector of model.
Methods
fit
([cov_type, cov_kwds, use_t])Estimate the model parameters.
from_formula
(formula, data[, subset, drop_cols])Create a Model from a formula and dataframe.
hessian
(params)The Hessian matrix of the model.
information
(params)Fisher information matrix of model.
Initialize the model (no-op).
loglike
(params)Log-likelihood of model.
predict
(params[, start, end, dynamic, exog, …])In-sample prediction and out-of-sample forecasting.
score
(params)Score vector of model.
Properties
The autoregressive lags included in the model
The model degrees of freedom.
Names of endogenous variables.
Names of exogenous variables included in model
The number of initial obs.
Flag indicating that the model contains a seasonal component.