WillianFuks / tfcausalimpact

Python Causal Impact Implementation Based on Google's R Package. Built using TensorFlow Probability.
Apache License 2.0
600 stars 72 forks source link

pycausalimpact vs tfcausalimpact! #7

Closed 99snowleopards closed 3 years ago

99snowleopards commented 3 years ago

thanks for releasing another causal impact library!

do pycausalimpact and tfcausalimpact have the same functionality, and give the same output for the same set of data? how would you recommend one choose between the two?

also, I see that the way to start using both is the same: from causalimpact import CausalImpact - what if I have both python packages installed in the same conda envirnoment - how can I choose which one to use?

Thanks,

WillianFuks commented 3 years ago

Hi @99snowleopards ,

While they do have the same functionality, this newer version is a full Bayesian implementation just as the original R package is, which means the results are equivalent between both of them. That being said I recommend now using tfcausalimpact.

As for the importation clause, you're right that both are equal (this is something that we can not change as we want to be equivalent to the original R package). I'm not sure what happens though if you install both, I suppose that the last one installed will overwrite the previous one. Still, as stated before, installing just the newer package should just be fine (in fact I used the older library as reference for building the new one).

Hope this helps,

Best,

Will

99snowleopards commented 3 years ago

that's helpful, thanks for replying!

I have a related question that I'd greatly appreciate your insight on. I use the BSTS based causal impact model for problems where I have test group time series observations, and related control group time series observations (what you refer to as covariate, X).

I'm also trying to determine the causal impact of an intervention on univariate time series data, where I don't have a related control group. Have you come across any models for such a problem?

My initial thought on this to use the univariate time series to make a forecast for the intervention time period, and compare that forecast (counterfactual) with actual sales. Hope my question makes sense!

Thanks again for this amazing library!

WillianFuks commented 3 years ago

The good thing about the covariates is that they increase precision and reliability on the inference. Running causal impact without them is still possible but less accurate (something you'll have to keep in mind when running your analyzes).

As for how, I recommend working with all structural components that the package sts offers (I wrote a bit about it on the medium post related). You can mix LinearTrend with Auto-Regressive components for instance, run some back-testings and see if it's reliable.

Still, if you can find covariates you'll probably get much better results.

99snowleopards commented 3 years ago

thanks @WillianFuks , I'm very excited to start using this library and understand it better - all your Medium posts are also very detailed and insightful - looking forward to more of them!