# Buggy code
def __init__(
    self,
    endog,
    exog=None,
    order=(0, 0, 0),
    seasonal_order=(0, 0, 0, 0),
    trend=None,
    enforce_stationarity=True,
    enforce_invertibility=True,
    concentrate_scale=False,
    dates=None,
    freq=None,
    missing="none",
):
    # Default for trend
    # 'c' if there is no integration and 'n' otherwise
    # TODO: if trend='c', then we could alternatively use `demean=True` in
    # the estimation methods rather than setting up `exog` and using GLS.
    # Not sure if it's worth the trouble though.
    integrated = order[1] > 0 or seasonal_order[1] > 0
    if trend is None and not integrated:
        trend = "c"
    elif trend is None:
        trend = "n"

    # Construct the specification
    # (don't pass specific values of enforce stationarity/invertibility,
    # because we don't actually want to restrict the estimators based on
    # this criteria. Instead, we'll just make sure that the parameter
    # estimates from those methods satisfy the criteria.)
    self._spec = SARIMAXSpecification(
        endog,
        exog=exog,
        order=order,
        seasonal_order=seasonal_order,
        trend=trend,
        enforce_stationarity=None,
        enforce_invertibility=None,
        concentrate_scale=concentrate_scale,
        dates=dates,
        freq=freq,
        missing=missing,
    )
    exog = self._spec._model.data.orig_exog

    # Initialize the base SARIMAX class
    super(ARIMA, self).__init__(
        endog,
        exog,
        order=order,
        seasonal_order=seasonal_order,
        enforce_stationarity=enforce_stationarity,
        enforce_invertibility=enforce_invertibility,
        concentrate_scale=concentrate_scale,
        dates=dates,
        freq=freq,
        missing=missing,
    )


# Traceback (IndexError)
c:\git\statsmodels\statsmodels\tsa\statespace\sarimax.py:914: RuntimeWarning: overflow encountered in square
params_variance = (residuals[k_params_ma:]**2).mean()
c:\git\statsmodels\statsmodels\tsa\statespace\sarimax.py:976: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.
warn('Non-stationary starting autoregressive parameters'
c:\git\statsmodels\statsmodels\tsa\statespace\tools.py:487: RuntimeWarning: invalid value encountered in double_scalars
y[k-1, i] = (y[k, i] - y[k, k]*y[k, k-i-1]) / (1 - y[k, k]**2)
c:\git\statsmodels\statsmodels\tsa\statespace\tools.py:489: RuntimeWarning: invalid value encountered in sqrt
x = r / ((1 - r**2)**0.5)
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-8-a7c5e4baeb4f>", line 10, in <module>
res = mod.fit()
File "c:\git\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 605, in fit
start_params = self.untransform_params(start_params)
File "c:\git\statsmodels\statsmodels\tsa\statespace\sarimax.py", line 1495, in untransform_params
unconstrained[start] = constrained[start]**0.5
IndexError: index 6 is out of bounds for axis 0 with size 4

# Fixed code
def __init__(
    self,
    endog,
    exog=None,
    order=(0, 0, 0),
    seasonal_order=(0, 0, 0, 0),
    trend=None,
    enforce_stationarity=True,
    enforce_invertibility=True,
    concentrate_scale=False,
    dates=None,
    freq=None,
    missing="none",
):
    # Default for trend
    # 'c' if there is no integration and 'n' otherwise
    # TODO: if trend='c', then we could alternatively use `demean=True` in
    # the estimation methods rather than setting up `exog` and using GLS.
    # Not sure if it's worth the trouble though.
    integrated = order[1] > 0 or seasonal_order[1] > 0
    if trend is None and not integrated:
        trend = "c"
    elif trend is None:
        trend = "n"

    # Construct the specification
    # (don't pass specific values of enforce stationarity/invertibility,
    # because we don't actually want to restrict the estimators based on
    # this criteria. Instead, we'll just make sure that the parameter
    # estimates from those methods satisfy the criteria.)
    self._spec_arima = SARIMAXSpecification(
        endog,
        exog=exog,
        order=order,
        seasonal_order=seasonal_order,
        trend=trend,
        enforce_stationarity=None,
        enforce_invertibility=None,
        concentrate_scale=concentrate_scale,
        dates=dates,
        freq=freq,
        missing=missing,
    )
    exog = self._spec_arima._model.data.orig_exog

    # Initialize the base SARIMAX class
    # Note: we don't pass in a trend value to the base class, since ARIMA
    # standardizes the trend to always be part of exog, while the base
    # SARIMAX class puts it in the transition equation.
    super(ARIMA, self).__init__(
        endog,
        exog,
        order=order,
        seasonal_order=seasonal_order,
        enforce_stationarity=enforce_stationarity,
        enforce_invertibility=enforce_invertibility,
        concentrate_scale=concentrate_scale,
        dates=dates,
        freq=freq,
        missing=missing,
    )