Skip to main content

module statsforecast.arima


function arima_gradtrans

arima_gradtrans(x, arma)

function arima_undopars

arima_undopars(x, arma)

function ARIMA_invtrans

ARIMA_invtrans(x, arma)

function getQ0

getQ0(phi, theta)

function arima_transpar

arima_transpar(params_in, arma, trans)

function arima_css

arima_css(y, arma, phi, theta)

function make_arima

make_arima(phi, theta, delta, kappa=1000000.0, tol=2.220446049250313e-16)

function arima_like

arima_like(y, phi, theta, delta, a, P, Pn, up, use_resid)

function diff

diff(x, lag, differences)

function fixed_params_from_dict

fixed_params_from_dict(
    fixed_dict: dict,
    order: tuple,
    seasonal: dict,
    intercept: bool,
    n_ex: int
)
Transforms dict params to list. Args:
  • fixed_dict (dict): Dictionary of fixed parameters.
  • order (tuple): ARIMA order (p, d, q).
  • seasonal (dict): Seasonal parameters.
  • intercept (bool): Whether to include intercept.
  • n_ex (int): Number of external variables.
Returns:
  • list: List of parameter values.

function arima

arima(
    x: ndarray,
    order=(0, 0, 0),
    seasonal={'order': (0, 0, 0), 'period': 1},
    xreg=None,
    include_mean=True,
    transform_pars=True,
    fixed=None,
    init=None,
    method='CSS',
    SSinit='Gardner1980',
    optim_method='BFGS',
    kappa=1000000.0,
    tol=1e-08,
    optim_control={'maxiter': 100}
)

function kalman_forecast

kalman_forecast(n, Z, a, P, T, V, h)

function checkarima

checkarima(obj)

function predict_arima

predict_arima(model, n_ahead, newxreg=None, se_fit=True)

function convert_coef_name

convert_coef_name(name, inverse=False)

function change_drift_name

change_drift_name(model_coef, inverse=False)

function myarima

myarima(
    x,
    order=(0, 0, 0),
    seasonal={'order': (0, 0, 0), 'period': 1},
    constant=True,
    ic='aic',
    trace=False,
    approximation=False,
    offset=0,
    xreg=None,
    method=None,
    **kwargs
)

function search_arima

search_arima(
    x,
    d=0,
    D=0,
    max_p=5,
    max_q=5,
    max_P=2,
    max_Q=2,
    max_order=5,
    stationary=False,
    ic='aic',
    trace=False,
    approximation=False,
    xreg=None,
    offset=None,
    allow_drift=True,
    allow_mean=True,
    period=1,
    **kwargs
)

function arima2

arima2(x, model, xreg, method)

function Arima

Arima(
    x,
    order=(0, 0, 0),
    seasonal={'order': (0, 0, 0), 'period': 1},
    xreg=None,
    include_mean=True,
    include_drift=False,
    include_constant=None,
    blambda=None,
    biasadj=False,
    method='CSS',
    model=None,
    **kwargs
)

function arima_string

arima_string(model, padding=False)

function is_constant

is_constant(x)

function forecast_arima

forecast_arima(
    model,
    h=None,
    level=None,
    fan=False,
    xreg=None,
    blambda=None,
    bootstrap=False,
    npaths=5000,
    biasadj=None
)

function fitted_arima

fitted_arima(model, h=1)
Returns h-step forecasts for the data used in fitting the model. Args:
  • model: The fitted ARIMA model.
  • h (int): Number of steps ahead. Defaults to 1.
Returns: Fitted values or None if not available.

function seas_heuristic

seas_heuristic(x, period)

function nsdiffs

nsdiffs(x, test='seas', alpha=0.05, period=1, max_D=1, **kwargs)

function ndiffs

ndiffs(x, alpha=0.05, test='kpss', kind='level', max_d=2)

function newmodel

newmodel(p, d, q, P, D, Q, constant, results)

function auto_arima_f

auto_arima_f(
    x,
    d=None,
    D=None,
    max_p=5,
    max_q=5,
    max_P=2,
    max_Q=2,
    max_order=5,
    max_d=2,
    max_D=1,
    start_p=2,
    start_q=2,
    start_P=1,
    start_Q=1,
    stationary=False,
    seasonal=True,
    ic='aicc',
    stepwise=True,
    nmodels=94,
    trace=False,
    approximation=None,
    method=None,
    truncate=None,
    xreg=None,
    test='kpss',
    test_kwargs=None,
    seasonal_test='seas',
    seasonal_test_kwargs=None,
    allowdrift=True,
    allowmean=True,
    blambda=None,
    biasadj=False,
    period=1
)

function forward_arima

forward_arima(fitted_model, y, xreg=None, method='CSS-ML')

function print_statsforecast_ARIMA

print_statsforecast_ARIMA(model, digits=3, se=True)

class OptimResult

OptimResult(success, status, x, fun, hess_inv)

class ARIMASummary

ARIMA Summary.

method __init__

__init__(model)

method summary

summary()

class AutoARIMA

An AutoARIMA estimator. Returns best ARIMA model according to either AIC, AICc or BIC value. The function conducts a search over possible model within the order constraints provided. Args:
  • d (int, optional): Order of first-differencing. If missing, will choose a value based on test. Defaults to None.
  • D (int, optional): Order of seasonal-differencing. If missing, will choose a value based on season_test. Defaults to None.
  • max_p (int): Maximum value of p. Defaults to 5.
  • max_q (int): Maximum value of q. Defaults to 5.
  • max_P (int): Maximum value of P. Defaults to 2.
  • max_Q (int): Maximum value of Q. Defaults to 2.
  • max_order (int): Maximum value of p+q+P+Q if model selection is not stepwise. Defaults to 5.
  • max_d (int): Maximum number of non-seasonal differences. Defaults to 2.
  • max_D (int): Maximum number of seasonal differences. Defaults to 1.
  • start_p (int): Starting value of p in stepwise procedure. Defaults to 2.
  • start_q (int): Starting value of q in stepwise procedure. Defaults to 2.
  • start_P (int): Starting value of P in stepwise procedure. Defaults to 1.
  • start_Q (int): Starting value of Q in stepwise procedure. Defaults to 1.
  • stationary (bool): If True, restricts search to stationary models. Defaults to False.
  • seasonal (bool): If False, restricts search to non-seasonal models. Defaults to True.
  • ic (str): Information criterion to be used in model selection. Defaults to ‘aicc’.
  • stepwise (bool): If True, will do stepwise selection (faster). Otherwise, it searches over all models. Non-stepwise selection can be very slow, especially for seasonal models. Defaults to True.
  • nmodels (int): Maximum number of models considered in the stepwise search. Defaults to 94.
  • trace (bool): If True, the list of ARIMA models considered will be reported. Defaults to False.
  • approximation (bool, optional): If True, estimation is via conditional sums of squares and the information criteria used for model selection are approximated. The final model is still computed using maximum likelihood estimation. Approximation should be used for long time series or a high seasonal period to avoid excessive computation times. Defaults to None.
  • method (str, optional): fitting method: maximum likelihood or minimize conditional sum-of-squares. The default (unless there are missing values) is to use conditional-sum-of-squares to find starting values, then maximum likelihood. Can be abbreviated. Defaults to None.
  • truncate (bool, optional): An integer value indicating how many observations to use in model selection. The last truncate values of the series are used to select a model when truncate is not None and approximation=True. All observations are used if either truncate=None or approximation=False. Defaults to None.
  • test (str): Type of unit root test to use. See ndiffs for details. Defaults to ‘kpss’.
  • test_kwargs (str, optional): Additional arguments to be passed to the unit root test. Defaults to None.
  • seasonal_test (str): This determines which method is used to select the number of seasonal differences. The default method is to use a measure of seasonal strength computed from an STL decomposition. Other possibilities involve seasonal unit root tests. Defaults to ‘seas’.
  • seasonal_test_kwargs (dict, optional): Additional arguments to be passed to the seasonal unit root test. See nsdiffs for details. Defaults to None.
  • allowdrift (bool): If True, models with drift terms are considered. Defaults to True.
  • allowmean (bool): If True, models with a non-zero mean are considered. Defaults to True.
  • blambda (float, optional): Box-Cox transformation parameter. If lambda=“auto”, then a transformation is automatically selected using BoxCox.lambda. The transformation is ignored if None. Otherwise, data transformed before model is estimated. Defaults to None.
  • biasadj (bool): Use adjusted back-transformed mean for Box-Cox transformations. If transformed data is used to produce forecasts and fitted values, a regular back transformation will result in median forecasts. If biasadj is True, an adjustment will be made to produce mean forecasts and fitted values. Defaults to False.
  • period (int): Number of observations per unit of time. For example 24 for Hourly data. Defaults to 1.
Notes:

method __init__

__init__(
    d: Optional[int] = None,
    D: Optional[int] = None,
    max_p: int = 5,
    max_q: int = 5,
    max_P: int = 2,
    max_Q: int = 2,
    max_order: int = 5,
    max_d: int = 2,
    max_D: int = 1,
    start_p: int = 2,
    start_q: int = 2,
    start_P: int = 1,
    start_Q: int = 1,
    stationary: bool = False,
    seasonal: bool = True,
    ic: str = 'aicc',
    stepwise: bool = True,
    nmodels: int = 94,
    trace: bool = False,
    approximation: Optional[bool] = None,
    method: Optional[str] = None,
    truncate: Optional[bool] = None,
    test: str = 'kpss',
    test_kwargs: Optional[str] = None,
    seasonal_test: str = 'seas',
    seasonal_test_kwargs: Optional[Dict] = None,
    allowdrift: bool = True,
    allowmean: bool = True,
    blambda: Optional[float] = None,
    biasadj: bool = False,
    period: int = 1
)

method fit

fit(y: ndarray, X: Optional[ndarray] = None)
Fit the AutoARIMA estimator. Fit an AutoARIMA to a time series (numpy array) y and optionally exogenous variables (numpy array) X. Args:
  • y (np.ndarray): One-dimensional numpy array of floats without np.nan or np.inf values.
  • X (np.ndarray, optional): An optional 2-d numpy array of exogenous variables (float). Defaults to None.

method predict

predict(
    h: int,
    X: Optional[ndarray] = None,
    level: Optional[int, Tuple[int]] = None
)
Forecast future values using a fitted AutoArima. Args:
  • h (int): Number of periods for forecasting.
  • X (np.ndarray, optional): Future exogenous variables. Defaults to None.
  • level (int or tuple of int, optional): Confidence level for prediction intervals. Defaults to None.
Returns:
  • pd.DataFrame: The array of fitted values. The confidence intervals for the forecasts are returned if level is not None.

method predict_in_sample

predict_in_sample(level: Optional[int, Tuple[int]] = None)
Return fitted in sample values using a fitted AutoArima. Args:
  • level (int or tuple of int, optional): Confidence level for prediction intervals. Defaults to None.
Returns:
  • pd.DataFrame: The array of fitted values. The confidence intervals for the forecasts are returned if level is not None.

method summary

summary()