I am fairly new to R. I have attempted to read up on time series analysis and have already finished

  1. Shumway and Stoffer's Time series analysis and its applications 3rd Edition,
  2. Hyndman's excellent Forecasting: principles and practice
  3. Avril Coghlan's Using R for Time Series Analysis
  4. A. Ian McLeod et al Time Series Analysis with R
  5. Dr. Marcel Dettling's Applied Time Series Analysis

Edit: I'm not sure how to handle this but I found a usefull resource outside of Cross Validated. I wanted to include it here in case anyone stumbles upon this question.

Segmented regression analysis of interrupted time series studies in medication use research

I have a univariate time series of the number of items consumed (count data) measured daily for 7 years. An intervention was applied to the study population at roughly the middle of the time series. This intervention is not expected to produce an immediate effect and the timing of the onset of effect is essentially unknowable.

Using Hyndman's forecast package I have fitted an ARIMA model to the pre-intervention data using auto.arima(). But I am unsure of how to use this fit to answer whether there has been a statistically significant change in trend and quantify the amount.

# for simplification I will aggregate to monthly counts
# I can later generalize any teachings the community supplies
count <- c(2464, 2683, 2426, 2258, 1950, 1548, 1108,  991, 1616, 1809, 1688, 2168, 2226, 2379, 2211, 1925, 1998, 1740, 1305,  924, 1487, 1792, 1485, 1701, 1962, 2896, 2862, 2051, 1776, 1358, 1110,  939, 1446, 1550, 1809, 2370, 2401, 2641, 2301, 1902, 2056, 1798, 1198,  994, 1507, 1604, 1761, 2080, 2069, 2279, 2290, 1758, 1850, 1598, 1032,  916, 1428, 1708, 2067, 2626, 2194, 2046, 1905, 1712, 1672, 1473, 1052,  874, 1358, 1694, 1875, 2220, 2141, 2129, 1920, 1595, 1445, 1308, 1039,  828, 1724, 2045, 1715, 1840)
# for explanatory purposes
# month <- rep(month.name, 7)
# year <- 1999:2005
ts <- ts(count, start(1999, 1))
train_month <- window(ts, start=c(1999,1), end = c(2001,1))
arima_train <- auto.arima(train_month)
fit_month <- Arima(train_month, order = c(2,0,0), seasonal = c(1,1,0), lambda = 0)
plot(forecast(fit_month, 36)); lines(ts, col="red")

Are there any resources specifically dealing with interrupted time series analysis in R? I have found this dealing with ITS in SPSS but I have not been able to translate this to R.

  • $\begingroup$ Do you want to do inference on whether the intervention had a statistically significant effect, or do you want to model the intervention to obtain better forecasts? And could you possibly make the data available? $\endgroup$ – Stephan Kolassa Dec 2 '15 at 20:08
  • $\begingroup$ @StephanKolassa Certainly! My aim is to do inference. I will provide dummy data in an Edit to better illustrate my point. $\endgroup$ – dais.johns Dec 2 '15 at 20:14
  • $\begingroup$ @StephanKolassa Data provided to the best of my abilities. $\endgroup$ – dais.johns Dec 2 '15 at 20:35
  • $\begingroup$ Previous research suggests the intervention affect to be on the scale of +/- 5% change. $\endgroup$ – dais.johns Dec 2 '15 at 20:37
  • $\begingroup$ @StephanKolassa Provided actual usable data $\endgroup$ – dais.johns Dec 2 '15 at 22:51

This is known as change-point analysis. The R package changepoint can do this for you: see the documentation here (including references to the literature): http://www.lancs.ac.uk/~killick/Pub/KillickEckley2011.pdf

  • $\begingroup$ Thank you. I am looking into this. As far as I can tell this would calculate possible change points in the series, but will not analyze the trend difference. I apologize if this assumption is incorrect I have not been able to review the package other than superficially. $\endgroup$ – dais.johns Dec 3 '15 at 13:22
  • $\begingroup$ After identifying the change point, you can split the data into two time series (before and after the change point) and estimate the parameters of the two time series separately. A couple more suggestions: as your data has strong seasonal trend, this should be removed prior to the change-point analysis; and if you are going to use an ARIMA model, then differencing should also be performed prior to the change-point analysis (or, alternatively, you'll need to use some more specialized procedure). $\endgroup$ – Brent Kerby Dec 3 '15 at 15:59
  • $\begingroup$ Thank you for your suggestions I will attempt to implement and will mark as "answered" if this solves the problem. $\endgroup$ – dais.johns Dec 3 '15 at 20:11

I would suggest a repeated measures hierarchical model. This method should provide robust results since each individual will act as his/her own control. Try checking out this link from UCLA.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.