You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess it's called trend='n' for no trend; I think this must have been because in ARIMA, the choice is a constant trend or no trend, whereas in SARIMAX it is between no trend 'n', constant / intercept 'c', linear 't', linear + intercept 'ct', and generic (e.g. trend=(1,0,1) for a constant and a quadratic, but not a linear). It could easily be renamed to trend=nc to denote no trend.
SARIMAX allows constant in exog and reports regression constant in that case
We can eliminate this behavior, but again we'd have to choose how much to check for, since the trend is arbitrary (i.e. do we just check for constant in exog? or constant and linear trend? or constant, linear and quadratic? or ...)
stationarity? imposed or optional?
In SARIMAX, stationarity (of the autoregressive lag polynomial) and invertibility (of the moving average lag polynomial) are controlled via keyword args enforce_stationarity and enforce_invertibility.
SARIMAX allows constant in exog and reports regression constant in that case
We can eliminate this behavior, but again we'd have to choose how much to check for, since the trend is arbitrary (i.e. do we just check for constant in exog? or constant and linear trend? or constant, linear and quadratic? or ...)
Actually, there is another reason not to eliminate the ability to have constant regressors (although there's still a case for checking that both aren't specified), but I should document it more explicitly somewhere. It's related to the above point about const in ARIMA and intercept in SARIMAX.
Without exogenous regressors, the SARIMA model is (these equations come from the documentation to the SARIMAX model):
With exogenous regressors, the SARIMAX model is specified as regression with SARIMA errors, like so:
This means that a constant trend will yield the intercept of the time series, whereas a constant in exog will yield the mean of the time series. For example:
fromscipy.signalimportlfilter# Parametersnobs=1e3phi=0.2mean=4intercept=mean* (1-phi)
print'mean = %.2f, intercept = %.2f'% (mean, intercept)
# Generate datanp.random.seed(12345)
eps=np.random.normal(size=nobs)
endog=lfilter([1], [1, -phi], eps) +mean# Estimate the mean via exogmod1=sm.tsa.SARIMAX(endog, order=(1,0,0), exog=np.ones(nobs))
res1=mod1.fit()
print'exog method (mean) ', res1.params# Estimate the intercept via trendmod2=sm.tsa.SARIMAX(endog, order=(1,0,0), trend='c')
res2=mod2.fit()
print'trend method (intercept)', res2.params
although there's still a case for checking that both aren't specified
However, the model won't break here if you do include both (i.e. there won't be a perfect multicollinearity problem), it's just that the intercept versus mean parameter obviously aren't separately identified:
another issue:
trend='c' in level is redundant, if initial state in ARIMA(p, 1, q) can be non-zero. And I get a hessian/cov_params warning in this case.
E.g. estimating SARIMAX with trend='n', and without or with exog=np.ones(nobs) (const in exog)
in the differenced series (i.e. constant trend is actually drift)
subtracted from endog in the same way as exog, i.e. trend='c' means non-zero mean in levels but no drift.
AFAICS, I think that SARIMAX uses the first (drift), while ARIMA uses the second (const in level)
Yes, in the default representation, the trend keyword puts the given trend on the stationary "state", which is essentially the differenced endog variable.
The description if the Stata documentation mixes cases, but the explicit statements sound like constant is treated in the same way as exog, i.e.
z = y - x b
z ~ SARIMA
ie. like ARIMA and not like SARIMAX, AFAIU
Stata is more like SARIMAX, in that trend=c in SARIMAX is the same as what you get with e.g. arima cpi, arima(1,1,2).
If you wanted to get the same effect by using an exog (in either SARIMAX or Stata), for the d=1 case, you would need to put the time trend (so that the difference was a constant). e.g. The following are basically the same:
arima cpi, arima(1,1,2)
gen t = _n followed by arima cpi t, arima(1,1,2)
or:
mod = SARIMAX(cpi, order=(1, 1, 2), trend='c')
mod = SARIMAX(cpi, order=(1, 1, 2), exog=np.arange(len(cpi)) + 1)
However, the one wrinkle is that Stata reports the parameter in terms of the mean, while in SARIMAX it could be either the mean or the intercept. It is the mean if you use exog and it is the intercept if you use trend. So, to use SARIMAX to estimate the model as Stata does, one could do:
mod=sarimax.SARIMAX(endog, order=(1, 1, 2), trend='c')
stata_params= [.9281721822, -.8959349, 1.302477, .3024765, .8100338]
params=stata_params[:]
# Convert the mean parameter to intercept formparams[0] *= (1-params[1])
# Convert the standard deviation to a varianceparams[4] **=2res=mod.smooth(params)
print(res.llf)
or one could do:
mod=sarimax.SARIMAX(endog, order=(1, 1, 2), exog=np.arange(len(endog)) +1)
stata_params= [.9281721822, -.8959349, 1.302477, .3024765, .8100338]
params=stata_params[:]
# Convert the standard deviation to a varianceparams[4] **=2res=mod.smooth(params)
print(res.llf)
Either yields -245.4076, which is pretty close to Stata: -245.4078.
ARMA and the old ARIMA have been deprecated and will be removed after 0.12. Only the statespace implementation will persist, and so this issue has been mooted.
Activity
josef-pkt commentedon Jul 16, 2015
using pandas, names differ and cannot be correctly concatenated
using example from examples\incomplete\glsar.py
ChadFulton commentedon Jul 16, 2015
I guess it's called trend='n' for no trend; I think this must have been because in ARIMA, the choice is a constant trend or no trend, whereas in SARIMAX it is between no trend
'n', constant / intercept'c', linear't', linear + intercept'ct', and generic (e.g.trend=(1,0,1)for a constant and a quadratic, but not a linear). It could easily be renamed to trend=ncto denote no trend.We can eliminate this behavior, but again we'd have to choose how much to check for, since the trend is arbitrary (i.e. do we just check for constant in exog? or constant and linear trend? or constant, linear and quadratic? or ...)
In SARIMAX, stationarity (of the autoregressive lag polynomial) and invertibility (of the moving average lag polynomial) are controlled via keyword args
enforce_stationarityandenforce_invertibility.ChadFulton commentedon Jul 16, 2015
I don't see any reason why I couldn't change SARIMAX to be consistent with ARMA on the parameter names.
ChadFulton commentedon Jul 16, 2015
Although of course
constin ARIMA andinterceptin SARIMAX have different meanings, so maybe shouldn't have the same name.ChadFulton commentedon Jul 16, 2015
Actually, there is another reason not to eliminate the ability to have constant regressors (although there's still a case for checking that both aren't specified), but I should document it more explicitly somewhere. It's related to the above point about
constin ARIMA andinterceptin SARIMAX.Without exogenous regressors, the SARIMA model is (these equations come from the documentation to the SARIMAX model):
With exogenous regressors, the SARIMAX model is specified as regression with SARIMA errors, like so:
This means that a constant trend will yield the intercept of the time series, whereas a constant in exog will yield the mean of the time series. For example:
ChadFulton commentedon Jul 16, 2015
However, the model won't break here if you do include both (i.e. there won't be a perfect multicollinearity problem), it's just that the intercept versus mean parameter obviously aren't separately identified:
josef-pkt commentedon Jul 16, 2015
We don't necessarily have to adjust sarimax, i like the ability to use const in exog. Arma needs also refactoring to move trend to 'init'
josef-pkt commentedon Mar 31, 2018
Another question on trend: (I suspect but I'm not sure.)
In the differencing case, d=1, is the trend
AFAICS, I think that SARIMAX uses the first (drift), while ARIMA uses the second (const in level)
I'm trying to compare results for the #4412 testcase ARIMA(1, 1, 2) for CPI, which I haven't figured out yet.
josef-pkt commentedon Mar 31, 2018
The description if the Stata documentation mixes cases, but the explicit statements sound like constant is treated in the same way as exog, i.e.
z = y - x b
z ~ SARIMA
ie. like ARIMA and not like SARIMAX, AFAIU
josef-pkt commentedon Mar 31, 2018
another issue:
trend='c' in level is redundant, if initial state in ARIMA(p, 1, q) can be non-zero. And I get a hessian/cov_params warning in this case.
E.g. estimating SARIMAX with trend='n', and without or with exog=np.ones(nobs) (const in exog)
The redundant exog constant in the second case, with default OPG, causes
ChadFulton commentedon Apr 3, 2018
Yes, in the default representation, the
trendkeyword puts the given trend on the stationary "state", which is essentially the differencedendogvariable.I'm not sure about how ARIMA does it.
ChadFulton commentedon Apr 3, 2018
Stata is more like SARIMAX, in that
trend=cin SARIMAX is the same as what you get with e.g.arima cpi, arima(1,1,2).If you wanted to get the same effect by using an
exog(in either SARIMAX or Stata), for the d=1 case, you would need to put the time trend (so that the difference was a constant). e.g. The following are basically the same:arima cpi, arima(1,1,2)gen t = _nfollowed byarima cpi t, arima(1,1,2)or:
mod = SARIMAX(cpi, order=(1, 1, 2), trend='c')mod = SARIMAX(cpi, order=(1, 1, 2), exog=np.arange(len(cpi)) + 1)However, the one wrinkle is that Stata reports the parameter in terms of the mean, while in SARIMAX it could be either the mean or the intercept. It is the mean if you use
exogand it is the intercept if you usetrend. So, to use SARIMAX to estimate the model as Stata does, one could do:or one could do:
Either yields -245.4076, which is pretty close to Stata: -245.4078.
mmhernandm commentedon May 14, 2020
Which are the parameters that can determine sarimax or autoarima trend to predict more easily the low values than the higher peaks in a serie?
bashtage commentedon Aug 10, 2020
ARMA and the old ARIMA have been deprecated and will be removed after 0.12. Only the statespace implementation will persist, and so this issue has been mooted.