Interrupted time series with ARIMA in R - effect of the intervention - r

I am trying to estimate the effect of an intervention in a interrupted time series analysis. I used an ARIMA model with the package TSA and created a dummy variable for the pre and post-intervention time. Here is an example with the airmiles data included in the TSA package.
data(airmiles)
bin.int <- ts(c(rep(0,68),rep(1,45)))
air.m2=arimax(log(airmiles),order=c(0,1,1),seasonal=list(order=c(0,1,1),period=12),
xreg=data.frame(bin.int),
method='ML')
air.m2
coeftest(air.m2)
When I used the argument xreg, I understand I fit a coefficient for the effect of X. If X is a dummy variable (0 before and 1 after the intervention), this method estimates the effect as a level change. How may I estimate both a level change and/or a slope change with an ARIMA model ?
Do I have to use the transfer function with autoregressive and moving average parameters ?
Thank you.
François

Related

R libraries forecast::auto.arima vs fable:ARIMA what's the differences?

The online documentation indicates that the algorithm under the hood is the same to estimate the (s)Arima models. During some tests, with a Kaggle dataset, I had different models: ARIMA function show me a sArima, auto.arima only Arima model.
auto.arima(tsbble_item1_store1$sales)
give
Best model: ARIMA(5,1,2)
and
tsbble_item1_store1 %>%
model(arima = ARIMA(sales))
give
# A mable: 1 x 2
# Key: store [1]
store arima
<dbl> <model>
1 1 <ARIMA(1,1,3)(0,0,2)[7]>
I have very different models. By the way, Arima's fable function shows me a better model, because it controls seasonality respect auto.arima function that doesn't, and the data show evident seasonality.
Does someone know the main differences in default parameters when the two functions try to estimate the model, because I didn't understand from docs?
Sorry if I had some mistakes
thank's in advance
Have nice day
MC
forecast::auto.arima() requires a ts object. That is a vector with some time series attributes including the seasonal frequency. When you just pass a numeric vector, as you have here, it assumes the seasonal frequency is 1 (as for annual data) and will not fit a seasonal ARIMA model.
On the other hand, the tsibble object contains a time index (in this case it looks like it is a date variable) and ARIMA() will use that index to determine what type of seasonality (if any) is present. With a date variable, it will select seasonal frequency of 7 to correspond to a time of week seasonality.
To get the same thing with forecast::auto.arima(), use
auto.arima(ts(tsbble_item1_store1$sales, frequency=7))

ARIMA vs. ARMA of time series in first differences

I am working on GDP time series forcast. I have log transformed the time series which has significant stochastic trend. I have checked that the time series in first differences is stationary. Now (i believe) I have two options:
Fit an ARMA model on the differenced log transformed GDP time series
Fit an ARIMA model (p,1,q) on the log transformed GDP time series
QUESTION:
I have noticed that ARIMA does not have an intercept, while ARMA does. How is the intercept to be interpreted?
How should I decide which one to use?
I have noticed that ARIMA does not have an intercept, while ARMA does. How is the intercept to be interpreted?
The intercept interpretation depends on your model. It relates to your mean through your other parameter if the series is stationary. E.g., see the AR(1) example on wiki. An intercept in an order one differentiering ARIMA model implies a constant drift which is likely not what you want.
How should I decide which one to use?
A common choice is to use an information criteria like AIC or BIC. E.g., see this post.

Daily timeseries forecasting, with weekly and annual cycle

My aim is to forecast the daily number of registrations in two different channels.
Week seasonality is quite strong, especially the weekends and also observed annual effects. Moreover, I have a few special event days, which significantly differ from the others days.
First, I applied a TBATS model on these two channels.
x.msts <- msts(Channel1_reg,seasonal.periods=c(7,365.25))
# fit model
fit <- tbats(x.msts)
fit
plot(fit)
forecast_channel1 <- forecast(fit,h=30)
First channel:
TBATS(0, {2,3}, -, {<7,3>, <365.25,2>})
Call: tbats(y = x.msts)
Parameters
Lambda: 0
Alpha: 0.0001804516
Gamma-1 Values: -1.517954e-05 1.004701e-05
Gamma-2 Values: -3.059654e-06 -2.796211e-05
AR coefficients: 0.249944 0.544593
MA coefficients: 0.215696 -0.361379 -0.21082
Second channel:
BATS(0, {2,2}, 0.929, -)
Call: tbats(y = y.msts)
Parameters
Lambda: 0
Alpha: 0.1652762
Beta: -0.008057904
Damping Parameter: 0.928972
AR coefficients: -0.586163 -0.676921
MA coefficients: 0.924758 0.743675
If I forecast the second channel, I only get blank values instead of any forecasts.
Could you please help why is that so?
Do you have any suggestion how to build in the specific event days into this model?
Thank you all!
tbats and bats are occasionally unstable, and your second model is showing infinite forecasts. There are already some bug reports about similar issues.
In any case, as you want to use event information, you would be better building a harmonic regression model with ARMA errors.
For example, suppose your event information is recorded as a dummy variable event1. Then the model can be fitted as follows:
harmonics <- fourier(x.msts, K=c(2,2))
fit1 <- auto.arima(x.msts, lambda=0,
xreg=cbind(harmonics,event1), seasonal=FALSE)
f1 <- forecast(fit1,
xreg=cbind(fourierf(x.msts, K=c(2,2), h=200), rep(0,200)))
This assumes that the event will not occur in the next 200 days (hence the 200 0s). I have used harmonics of order 2 for both weeks and years. Adjust these to minimize the AICc of the model.
This model is actually very similar to the TBATS model you are fitting except that the lambda value has been specified rather than estimated, and the seasonality is fixed over time rather than being allowed to evolve. The advantage is that the harmonic regression model tends to be more stable, and allows covariates to be included.

How to build HoltWinters and Stepwise Autoregressive time series model with constant and linear trend in R package

I am trying to build four time series models in R
1) HoltWinters with constant trend,
2) HoltWinters with linear trend,
3) Stepwise autoregressive with constant trend,
2) Stepwise autoregressive with linear trend
In SAS I can do this using PROC Forecast and specifying method and trend option.
Could you please help me in doing this. Thanks.
For 1 and 2:
library(forecast)
fit1 <- ets(x, model="ANA", damped=FALSE)
fit2 <- ets(x, model="AAA", beta=0, damped=FALSE, lower=rep(0,4))
By default, ets does not allow constant components (such as a linear trend), but setting the lower limit to 0 allows it.
For 3 and 4, I am not sure what you mean by "stepwise autoregressive". Perhaps you mean a subset autoregression where the terms are chosen using a stepwise procedure. For that, see the FitAR package (http://www.jstatsoft.org/v28/i02/paper). However, I don't think it allows a deterministic trend.

R: Generate a Seasonal ARIMA time-series model using parameters of existing data

I have a count time series data which I'm able to use to determine the parameters of the underlying stochastic process. For example say I have a SARIMA (p,d,q)(P,D,Q)[S] seasonal ARIMA model.
How do I use this to generate a new count time series data set?
Being even more specific: a SARIMA(1,0,1)(1,0,0)[12] - how can I generate a time series for a 10 year period for each month? (i.e., 120 points to estimate the number of 'counts'.)
Use simulate.Arima() from the forecast package. It handles seasonal ARIMA models whereas arima.sim() does not.
However, ARIMA models are not suitable for count time series as they assume the process is defined on the whole real line.

Resources