matheusfacure / python-causality-handbook

Causal Inference for the Brave and True. A light-hearted yet rigorous approach to learning about impact estimation and causality.
https://matheusfacure.github.io/python-causality-handbook/landing-page.html
MIT License
2.56k stars 444 forks source link

Conformal Inference for Synthetic Controls #367

Closed jgu115 closed 7 months ago

jgu115 commented 7 months ago

Hi Matheus,

Thank you for this chapter! I am trying to replicating the code to understand more in depth.

I have an issue on chapter Conformal Inference for Synthetic Controls, in the following paragraph block_permutations = np.stack([np.roll(u, permutation, axis=0)[post_intervention] for permutation in range(len(u))])

The line doesn't run for me due to [post_intervention]. It seems that [post_intervention] is here to serve as an index to array from np.roll(u, permutation, axis=0) ? But a list can't be served as index and I am also not clear about its purpose. if we just want post_intervention residuals , we an filter them upfront. My understanding is we actually want to permute with pre intervention.

The code ran after I took out [post_intervention] but would like to clarify if possible.

Thank you and best, Judith

jgu115 commented 7 months ago

Hi Matheus,

Tried the code again, indexing array with a boolean array actually seems to work fine. Not sure what happened in my earlier tries. So this line is basically saying rotate through all the pre/post residuals and pretend they are all post resids to test statistics. This matches "permute inference" well.

Thank you, Judith