rmcelreath / stat_rethinking_2022

Statistical Rethinking course winter 2022
4.11k stars 445 forks source link

wrong model in lecture 9 code? #12

Closed andreashandel closed 2 years ago

andreashandel commented 2 years ago

I'm trying to reproduce what you did in lecture 9. Getting stuck at the marginal/counterfactual example. Your (updated) code is this:

simulate as if all apps from women

p_G1 <- link(m2,data=list( D=rep(1:6,times=apps_per_dept), N=rep(1,total_apps), G=rep(1,total_apps)))

But m2 is the model from the simulated data, and if I understand correctly, here we are trying to mimic the real data. So I think it should be mGD. And indeed, in your script you have this:

OLD WRONG CODE!

p_G1 <- link( mGD , data=list(N=dat$N,D=dat$D,G=rep(1,12)) )

I think mGD is the right model. Unfortunately when I use mGD with the updated code above, my result figure doesn't look like yours (it also doesn't look like yours when. Instead of the main peak at around 0.1, I get the main peak at 0 and a minor one at 0.2. I'm not sure what's going on and trying to figure things out. Any pointers appreciated. Thanks!

rmcelreath commented 2 years ago

Probably right that it should be mGD and it was just copy-pasted. But the code structure is correct.

andreashandel commented 2 years ago

Thanks. But mGD model doesn't produce the same figure as yours, that's where I'm stuck.

rmcelreath commented 2 years ago

My code used m2 by copy-paste mistake. So if you change the model to mGD, the figure will be different.

rmcelreath commented 2 years ago

The 'm2' in the code was likely the m2 from the homework solutions that I wrote at the same time. Not the m2 from the lecture.

andreashandel commented 2 years ago

Yes, m2 doesn't run at all, mGD works, but the figure doesn't look like the one you show in our lecture/slides. I don't get the mode at 0.1 that you show and discuss in your lecture at time 1:02. My mode is always at 0, with a minor one at 0.2. I tried a few different random seeds and increased samples to make sure it wasn't due to variation, but doesn't seem to change. So I'm wondering if I'm doing something wrong or why I can't reproduce your figure.

Btw, while I"m nagging you here, I also want to say a big thanks for offering all that for folks to take. The lectures are great (the book of course too). It hasn't happened in a while that I decided to set dedicated time to work my way through a whole new topic, this has so far definitely been worth it!

rmcelreath commented 2 years ago

There is no reason you should be able to reproduce the figure in the slides, if it was produced with the m2 from the homework solutions (not from the lecture). Sorry for the oversight. Copying and pasting is always risky. But I believe the algorithm is correct.

andreashandel commented 2 years ago

ok, thanks!