-
Notifications
You must be signed in to change notification settings - Fork 1
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
Bug when IV has three categories? #3
Comments
Thanks for this. I will have a look and get back to you. |
Hello, this may be old news but I have also recently had issues with the 3 level IV example. I think I have identified the problem: In the code here: https://github.com/remlapmot/bpbounds/blob/master/R/bpbounds_calc_tri_z3.R#L4 the expected order of the probabilities is to have p(Y = 1, X = 0 | Z = z) coming before p(Y = 0, X = 1 | Z = z). However when using a single index on a 3-dimensional array it goes from top down then left to right. So, in the example array above, p[2] is in fact p(Y = 0, X = 1 | Z = 0). Compare that to the code here: https://github.com/remlapmot/bpbounds/blob/master/R/bpbounds_calc_tri_z2.R#L4 which has the correct order, i.e., p[3] comes before p[2], and p[7] before p[6]. Now this wasn't apparently a problem for your Mendelian randomization example (you get the same bounds as the stata package) because the probabilities were entered in the expected order, but the dimnames of the array are wrong, i.e., mt3[2] = p(Y = 1, X = 0 | Z = 0) and mt3[3] = p(Y = 0, X = 1 | Z = 0) and likewise for Z = 1, 2 . So, an easy fix for the example is to create the array with dimnames for x and y swapped position:
Then probabilities are labeled correctly. Hopefully that is clear enough, and let me know if I missed something! Best regards, |
I've been using your package for a project I've been working on, and I think there might be a bug. If I'm way off, I apologize for the inconvenience.
Anyway, I was running a bunch of simulations, and encountered a scenario where using
bpbounds
on a table of conditional probabilities claims that the IV inequalities are violated. However, I don't think that's the case.The last line of code above returns \max_z P(X = x, Y = 0 | Z = z) + \max_z P(X = x, Y = 1 | Z = z) for x=0,1. Both are less than 1, indicating the IV inequalities are not violated. But when I run
bpbounds(as.table(tabp))
, it returnsInstrumental inequality: FALSE
.I'm also slightly confused by one of the examples from your vignette (which is otherwise great, by the way!):
Here, P(X = 0, Y = 0 | Z = 1) + P(X = 0, Y = 1 | Z = 2) = 1.08, i.e. the IV inequalities are violated, but this is not caught by
bpbounds(as.table(p3))
I'm not sure what's going on, and again, if I'm missing something obvious, please let me know, and I apologize. But thought I would bring this to your attention in case there is indeed a bug in your package.
The text was updated successfully, but these errors were encountered: