pythonp-valueattribution

Python tfcausalimpact: how can I access the p-value?


I'm using tfcausalimpact (https://github.com/WillianFuks/tfcausalimpact).

When I run the analysis, I know that I can access the p-value by instantiating the model

ci = CausalImpact(data,pre_period,post_period)

ci.summary()

But that gives a wrapped-up text summary, and I want to save the P-value as a variable. How can I do this?


Solution

  • I couldn't find the answer in the documentation. However, on this line of the source code, the CausalImpact.summary method passes self.p_value to another function. The method that computed the p-value describes it as:

    ...the p-value for the hypothesis testing that there's signal in the observed data... Ranging between 0 and 1, represents the likelihood of obtaining the observed data by random chance.

    You can see in the summary template that the "Posterior prob. of a causal effect" is computed as (1 - p_value) * 100) (and some rounding).

    In your code, you should be able to access it programmatically as ci.p_value.