-
-
Notifications
You must be signed in to change notification settings - Fork 272
Mediation: new example notebook #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
I don't know what is happening but reviewnb is not working, I can write reviews but posting errors out. I tried yesterday and today it's still happening, I can use it in other PRs though, maybe some weird caching. I basically have two comments only and I think reviewnb is not too necessary here: I am not completely sure that the model will do what we want it to do. I think this will only use m to add the corresponding log likelihood term and won't sample from it. Thus, m is effectively a constant equal to its observed values when sampling and this is what is used in y. However, from the description above, I think m should be sampled when used in y so that the definitions of the different effects hold for every sample. Can (or have you already) you check that the total effect is the same for this and for the equivalent model that estimates only the total effect without moderation? can you also add xarray to the watermark? It should be |
Thanks for checking this. I think I know what you mean but I'm not 100% sure. So I went back to the Yuan and MacKinnon paper. Their model (in WinBUGS/JAGS) is
As far as I can tell I've basically implemented that model. But to be sure I changed the latter parts to μm = im + a * x
m = pm.Normal("m", mu=μm, sd=σm, observed=m)
μy = iy + b * m + cprime * x
y = pm.Normal("y", mu=μy, sd=σy, observed=y) which gives the same results. Implementing the total effect only model, gives the same estimate, ie the posterior for But I think what you are suggesting is something different - and if it's an issue then it would presumably also be an issue with the Yuan and MacKinnon paper, which could be interesting. |
Indeed, I think the main challenge is actually knowing what needs to be implemented. I don't know about JAGS so I am not 100% sure what is happening in that source, but I see 3 (and a half) possibilities:
|
You definitely don't want to assign the normal likelihoods to |
Thanks both. The original model I was working from was defined as: Following @fonnesbeck's suggestion, I changed the model to pm.Normal("m_likehood", mu=im + a * x, sigma=σm, observed=m)
pm.Normal("y_likehood", mu=iy + b * m + cprime * x, sigma=σy, observed=y) which avoids confusion and removes m as a parent of y in the graphviz figure. I'm not sure if it was actually overwriting the 'data m' though because the results are identical. Either way, this makes much more sense. So maybe this resolves the concerns? On a separate note, I also added |
Yeah, I'm not exactly sure what happens if you assign the likelihood to |
Data nodes can be predictors/fixed data on which we condition our inference or observations. The first won't have parents (x) whereas the second won't have children and their parent will be the corresponding likelihood term (y). If a variable does both roles it will have both parents and children like m. It is fine to add m and y as data, but in 3.x this basically has no effect on what you can do with the model.
|
View / edit / reply to this conversation on ReviewNB OriolAbril commented on 2021-05-22T10:48:50Z We should avoid using "sanity check". Here are some alternatives: https://gist.github.com/seanmhanson/fe370c2d8bd2b3228680e38899baf5cc drbenvincent commented on 2021-05-22T11:41:33Z Will change to "double check" |
View / edit / reply to this conversation on ReviewNB OriolAbril commented on 2021-05-22T10:48:51Z I would overlay the distributions instead. I think something like this will work, maybe will need some extra work on colors
ax = az.plot_posterior(..., point_estimate=None, hdi_prob="hide", label="Total...") az.plot_posterior(..., ax=ax) ax.legend(); drbenvincent commented on 2021-05-22T12:08:59Z I've given this a go. It was throwing an error providing the label kwarg, but have explained colours of curves. OriolAbril commented on 2021-05-22T12:38:54Z This is either an issue with ArviZ or a documentation error. According to the docstring |
Will change to "double check" View entire conversation on ReviewNB |
I've given this a go. It was throwing an error providing the label kwarg, but have explained colours of curves. View entire conversation on ReviewNB |
This is either an issue with ArviZ or a documentation error. According to the docstring View entire conversation on ReviewNB |
Here is a new example notebook on mediation. Note that this is not a modification of my previous moderation notebook, this is a brand new one on a new topic. I believe I'm following best practice at this point, but very happy to get some corrections or suggestions.