shade-econ / sequence-jacobian

A unified framework to solve and analyze heterogeneous-agent macro models.
MIT License
253 stars 149 forks source link

Covariance Computation #2

Closed MattCocci closed 5 years ago

MattCocci commented 5 years ago

https://github.com/shade-econ/sequence-jacobian/blob/0dd6ce62efa2cb755df18c9a394fd6ac941626f2/estimation.py#L24

Could be wrong, but I believe the line should be

total = (dft.conjugate() * sigmas**2) @ dft.swapaxes(1, 2)

mrognlie commented 5 years ago

Yikes, good catch, thanks!

Without the **2, this was implicitly taking in variances rather than standard deviations, which maybe was our original usage, but was inconsistent with the docstring. (It also was inconsistent with the usage of sigma_measurement in the log_likelihood function, which actually was treated as the standard deviation of measurement error.)

I just pushed the corrected line with the **2. In the Krusell-Smith notebook that calls this, I changed the numbers in an offsetting way: previously the notebook used shock "standard deviations" of 0.01 and 0.04 that were treated by the code as variances, and now I changed them to 0.1 and 0.2, so that the theoretical autocovariances are the same as before. After that, the only difference is that I bumped up the measurement error from 0.01 to 0.05, since the former value now seemed quite small in the context of shocks with standard deviations 0.1 and 0.2.

Thanks so much for catching this - it's one of those embarrassing bloopers that careful eyes can find!

Let us know if you find anything else or have further questions about this or any other part of the code. I don't think there are any other issues with estimation.py in particular - it's pretty transparent except for somewhat-obscure FFT usage in all_covariances(), which we tested against the slower but more straightforward formula - but certainly I should never rule anything out! :)

Thanks again, Matt

MattCocci commented 5 years ago

Great. Caught this only after simulating aggregates from the MA rep, then comparing to drawing aggregates directly from the joint normal distribution with variance-covariance matrix built from all_covariances, as in the notebooks. After this change, they both match.

And the code and notebooks are excellent. Really appreciate everything posted in the repo.