6
$\begingroup$

Today I have tried to play a little with CausalImpact R-package https://google.github.io/CausalImpact/CausalImpact.html (Brodersen et al. 2015) to explore the impact of some decissions in a sales data flow.

The documentation of the package says that it estimates the impact given a response time series and a set of control of time series (i.e two or more series are needed to get an estimation of the causal impact effect) by estimating a Bayesian Structural time-series model.

However I have used the package using only a single time-series (a single vector of data) and I have obtained an output (plot and model) that seems at prior reasonable.

My question is, in this case, with only one time series, what kind of model is the package estimating. Are the results obtained reliable? Is the package also useful in this case where only one time series is used?

The data and the plot are available here.

The code for obtaining the plot is:

pre.period<-c(1,72) 
post.period<-c(73,length(salesdata)) 
impact<-CausalImpact(salesdata, pre.period, post.period, model.args = list(nseasons=12)) 
plot(impact) 
summary(impact)
$\endgroup$
  • $\begingroup$ Can you post the data and the plot for people to comment? $\endgroup$ – forecaster Jun 18 '15 at 21:50
  • $\begingroup$ I forecaster thanks for your interest. Here is the data: $\endgroup$ – JosePerles Jun 19 '15 at 11:18
  • $\begingroup$ Hi forecaster, many thanks for your interest. Please, find the data and plot in github.com/Joseperles/R-statistical-course (salesdata.txt and CausalPlot.png) $\endgroup$ – JosePerles Jun 19 '15 at 11:38
  • $\begingroup$ Hi forecaster, here is the code to obtain the plot: pre.period<-c(1,72) post.period<-c(73,length(salesdata)) impact<-CausalImpact(salesdata, pre.period, post.period, model.args = list(nseasons=12)) plot(impact) summary(impact) $\endgroup$ – JosePerles Jun 19 '15 at 12:04
5
$\begingroup$

There are two ways of running an analysis with the CausalImpact R package. The documentation covers both. You can either let the package construct a suitable model automatically or you can specify a custom model.

In the former case, the kind of model constructed by the package depends on your input data:

  • If your data, as in your case, contains no predictor time series (i.e., the data argument is a univariate time series), then the model contains a local level component and, if specified in model.args, a seasonal component. It's generally not recommended to do this as the counterfactuals predicted by your model will be overly simplistic. They are not using any information from the post-period. Causal inference then becomes as hard as forecasting. Having said this, the model still provides you with prediction intervals, which you can use to assess whether the deviation of the time series in the post-period from its baseline is significant.

  • If your data contains one or more predictor time series (i.e., the data argument has at least two columns), then, on top of the above, the model contains a regression component. In all practical cases I've seen it really is the predictor time series that make the model powerful as they allow you to compute much more plausible counterfactuals. I'd generally recommend adding at least a handful of predictor time series.

You can find the implementation of the above in: https://github.com/google/CausalImpact/blob/master/R/impact_model.R

$\endgroup$
  • $\begingroup$ Hi Kay, many thanks for your reply.TOday I will try to use the option "coefficients" in plot to know the kind of model, but wiith your reply all is clear. $\endgroup$ – JosePerles Jun 22 '15 at 7:27
  • $\begingroup$ @KayBrodersen, thank you for the excellent package. Does the bsts package handle level shifts and outliers in time series data ? $\endgroup$ – forecaster Jun 23 '15 at 18:55
  • $\begingroup$ @forecaster The default model in CausalImpact assumes Gaussian iid observation noise and a Gaussian random walk on the latent local level. There are no explicit switching variables for level shifts or outliers. You could replace Gaussian observation noise by t-distributed noise, for example, if your data suggests heavy tails. The bsts package documentation has more details. $\endgroup$ – Kay Brodersen Jun 25 '15 at 15:20
  • $\begingroup$ @JosePerles If this answers your question feel free to mark the question as resolved. $\endgroup$ – Kay Brodersen Jun 25 '15 at 15:21
  • $\begingroup$ Yes, for me it is solved. $\endgroup$ – JosePerles Jun 26 '15 at 14:33

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.