jamalsenouci / causalimpact

Python port of CausalImpact R library
Apache License 2.0
262 stars 62 forks source link

How to get P-value in Python version? #12

Closed jingwen66 closed 4 years ago

jingwen66 commented 6 years ago

Summary of R package provides "Posterior tail-area probability p" and "Posterior prob. of a causal effect". I cannot find it in summary of python package. Is there any reason of not reporting them?

jamalsenouci commented 6 years ago

No reason other than it hasn't been implemented yet due to lack of time

jingwen66 commented 6 years ago

Is it possible to get it implemented in near future :)

jamalsenouci commented 6 years ago

Possibly but I'm not sure exactly when I'll next have time to work on it

Worerlz commented 6 years ago

Hi, I've implemented this p-value and I used the same technique described on the paper. `post_inf = impact.inferences[post_period[0]:post_period[1]] step_x = np.random.randint(2, size=len(post_inf.index) 1000) step_x[step_x == 0] = -1 x = post_inf['point_pred'].repeat(1000) + abs(post_inf['point_pred'].repeat( 1000) - post_inf['point_pred_upper'].repeat(1000)) np.random.random(size=len(post_inf.index) * 1000) aciertos = post_inf['response'].repeat(1000) - x > 0

goals_f = aciertos.sum() / (len(post_inf.index) * 1000)`

Hope this will be useful

wmelton commented 6 years ago

@Worerlz You should submit a pull request so if it works it can be merged in to Master upon @jamalsenouci approval

WillianFuks commented 5 years ago

Hi @jamalsenouci , just wondering, do you know how we can implement the computation of the p-value in this version of python? Maybe with some guidance we can contribute to the project.

Google's code uses an average over several samples, not sure how the same could be implemented here (or even if @Worerlz suggestion already does the trick)

jamalsenouci commented 4 years ago

I have attempted a p-value implementation in the latest version. This will need updating when the bayesian estimation is done but should do for now.