Solved – Simple interrupted time series analysis

intervention-analysisrtime series

I have a weekly time series representing costs for a cohort. I want to tell whether an intervention on the cohort (we can assume it happened in a single week) has decreased costs for the cohort. I happen to know that the trend over this period for the population from which this cohort was taken was -120 per week per week.

My initial thought was simply to do a linear regression lm(Costs~Weeks,offset=-120*Weeks) but (obviously) the significance is not only a function of the effect of the intervention but also how far back I look (if I look back to $-\infty$ it will of course appear non-significant).

I looked at this website: http://www.r-bloggers.com/time-series-intervention-analysis-wih-r-and-sas/ and tried to replicate the R code with my data, but when I enter the arimax() command, I got the error message

Error in stats:::arima(x=x,order=order,seasonal=seasonal,fixed=par[1:narma], : wrong length for 'fixed'

Now, I'm not sure what to do. Can anyone give me some guidance?

Best Answer

here's the arima function in R.

http://svn.r-project.org/R/trunk/src/library/stats/R/arima.R

snippet you might be interested in:

if (is.null(fixed)) fixed <- rep(NA_real_, narma + ncxreg)
else if(length(fixed) != narma + ncxreg) stop("wrong length for 'fixed'")
mask <- is.na(fixed)
no.optim <- !any(mask)
if(no.optim) transform.pars <- FALSE
if(transform.pars) {
    ind <- arma[1L] + arma[2L] + seq_len(arma[3L])
    if (any(!mask[seq_len(arma[1L])]) || any(!mask[ind])) {
        warning("some AR parameters were fixed: setting transform.pars = FALSE")
        transform.pars <- FALSE
    }
}
Related Question