Causal and selective inference in complex statistical models