# Intervention Analysis Coding in R TSA Package

I am studying intervention analysis in time series with the Cryer and Chan book and am looking at trying to understand how to code the step response interventions. One question I had is how to differentiate between these two models: It appears the only difference is in (c) the value of $\delta$ is constrained to be 1. How can this constraint be added to the arimax function? I believe that (b) uses the coding

transfer = list(c(1,0))

Is there a way to constrain $\delta$ =1?

This is pretty straight forward if you use a tsoutlier package in R. This was not possible in $R$ until Thanks to @javlacalle created tsoutlier package. See the question that I posted earlier.

With regards to incorporating regressors like intervention analysis that you posted, you could use outlier.effects in the tsoutlier package to create regressors in ARIMAX model. See below for an example. This is similar to what you have asked. You could change the $\delta$ values in the temproary change to obtain desired shape of the curve. In the example below, I have left it to be default value for $\delta$ to be 0.7. You can consult package manual for further detail. tsoutlier package is great because it works with auto.arima and automatically identifies outliers and lets you code this arimax model.

In the example below I have shown you how to incorporate Level shift and Temporary change (which is what you are looking for). The outlier package identifies a level shift at 12 and temproary change at 20 which I both created as regressors using outliers.effects function. Temporary change has a decay effect which is nicely captured in this example.

library(tsoutliers)
library(expsmooth)
library(fma)

## Identify Outliers

outlier.chicken <- tsoutliers::tso(chicken,types = c("AO","LS","TC"),maxit.iloop=10)
outlier.chicken
plot(outlier.chicken)

n <- length(chicken)

## Create Outliers Regressors for ARIMAX
## Two type of outliers Level Shift (LS) and Temprory Change (TC)

mo.ls <- outliers("LS", 12)
ls <- outliers.effects(mo.ls, n)

mo.tc <- outliers("TC", 20)
tc <- outliers.effects(mo.tc, n)

xreg.outliers <- cbind(ls,tc)

## Create Arimax using Outliers as regressor variables.

arima.model <- auto.arima(chicken,xreg=xreg.outliers)
arima.model output from outlier detection

Series: chicken
ARIMA(0,1,0)

Coefficients:
LS12     TC20
37.1400  36.3763
s.e.  11.8641  10.9382

sigma^2 estimated as 140.8:  log likelihood=-264.19
AIC=534.38   AICc=534.75   BIC=541.08

Outliers:
type ind time coefhat tstat
1   LS  12 1935   37.14 3.130
2   TC  20 1943   36.38 3.326


output from auto.arima incorporating outliers as xreg

series: chicken
ARIMA(0,1,0) with drift

Coefficients:
drift     LS12     TC20
-2.7450  39.8850  36.3763
s.e.   1.3997  11.6267  10.6414

sigma^2 estimated as 133.2:  log likelihood=-262.32
AIC=532.64   AICc=533.26   BIC=541.58


Hope this helps

@forecaster gave a great answer using a package that I will be checking out. This is the answer to my question using the arimax function. The trick is to see that (assuming the event occurs at T=200): So, we can create the covariate as 0 for t < 200 and then 1,2,3....200 and use transfer=list(c(0,0))

We could also use this variable directly as a regressor via xreg.

• not quite sure, if r=0 and s=0, doesn't that translate to $\omega BS_{t}$ ? – stucash May 10 '19 at 17:59

use a fixed vector to fix delta = 1. fixed=c(NA,NA,1,NA) you need to figure out where the NA's should be located in the vector.See the docs for arima. I first estimate arimax() without the fixed vector to find the correct positions. Then add the fixed vector to the command and rerun.

• This approach would be appropriate to fix some of the coefficients of the ARIMA model (or of the external regressors). In this case, the parameter $\delta$ is not the coefficient of the regressor, it is a parameter to generate the values of the regressor (the intervention variable). The question may mislead you because it mentions constrain $\delta=1$. Nevertheless, I think it is usually more likely that we want to fix the coefficients of the ARIMA model rather than the external regressors. In the latter case we could simply fit a model for $y_t-\kappa x_t$, being $\kappa$ the fixed coeff. – javlacalle Jul 17 '14 at 15:15