When conducting an intervention analysis with time series data (aka Interrupted Time series) as discussed here for example one requirement I have is to estimate the total gain (or loss) due to the intervention - i.e. number of units gained or lost (the Y variable).
Not entirely understanding how to estimate the intervention function using a filter function within R, I went about it in a brute force manner, hoping this is general enough to work in any situation.
Lets say that given the data
cds<- structure(c(2580L, 2263L, 3679L, 3461L, 3645L, 3716L, 3955L,
3362L, 2637L, 2524L, 2084L, 2031L, 2256L, 2401L, 3253L, 2881L,
2555L, 2585L, 3015L, 2608L, 3676L, 5763L, 4626L, 3848L, 4523L,
4186L, 4070L, 4000L, 3498L), .Dim = c(29L, 1L), .Dimnames = list(
NULL, "CD"), .Tsp = c(2012, 2014.33333333333, 12), class = "ts")
we decide that the best fitting model is as follows, with the intervention function as
$m_t= \frac{\omega_0}{(1-\delta B)}X_t$ where $X_t$ is a pulse at October 2013.
fit4 <- arimax(log(cds), order = c(1,1,0),include.mean=FALSE,
xtransf = data.frame(Oct13 = 1*(seq_along(cds)==22)),
transfer = list(c(1,0))
,xreg=1*(seq_along(cds)==3))
fit4
# ARIMA(1,1,0)
# Coefficients:
# ar1 xreg Oct13-AR1 Oct13-MA0
# -0.0184 0.2718 0.4295 0.4392
# s.e. 0.2124 0.1072 0.3589 0.1485
# sigma^2 estimated as 0.02176: log likelihood=13.85
# AIC=-19.71 AICc=-16.98 BIC=-13.05
I have two questions:
Even though we have differenced the ARIMA errors , to assess the intervention function which was then technically fit using the differenced series $\bigtriangledown X_t $ is there anything we need to do in order to "change back" the estimate of $\omega_0$ or $\delta$ from using $\bigtriangledown X_t $ to $ X_t $?
Is this correct: In order to determine the gain of the intervention, I constructed the intervention $m_t$ from the parameters. Once I have $m_t$ then I compare the fitted values from the model fit4 (exp() to reverse the log) to exp( fitted values minus $m_t$ ) and determine that over the observed period, the intervention resulted in 3342.37 extra units.
Is this process the correct one to determine the gain generally from an intervention analysis?
int_vect1<-1*(seq_along(cds)==22)
wo<- 0.4392
delta<-0.4295
mt<-rep(0,length(int_vect1))
for (i in 1:length(int_vect1))
{
if (i>1)
{
mt[i]<-wo*int_vect1[i]+delta*mt[i-1]
}
}
mt
sum(exp(fitted(fit4)) - (exp(fitted(fit4) - mt)))