-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Fitting a Binomial distribution with pymc raises ZeroProbability error for certain FillValues in masked arrays #47
Comments
This is because you filled the missing values with 999999, which is outside the support of the variable. You need to give it a valid value, but not one that occurs in the non-missing data. Also, note that you don't have to pass |
Thanks @fonnesbeck for pointing this out! So does that means if my observed data contains all possible values inside the support I cannot treat missing data? observed_values = sp.random.binomial(n = 3.0, p = 0.5, size = 100)
print(sp.unique(observed_values)) Output:
What to choose for the masked value? mask = sp.zeros_like(observed_values)
mask[0] = True
masked_values = sp.ma.masked_array(observed_values, mask = mask, masked_values = ????) Is it really necessary that pymc checks for the masked value to be in the support? Because I have the following situation: I do have a model where the n of the binomials actually is a random variable itself. And I'm fitting a number of datasets. That means I would have to check which masked value to use for every dataset which is certainly possible, but sometimes I might not be able to find a masked value. So I would vote for not checking if the missing values are inside the support. Would you agree. |
You can give it a non-integer value in order to avoid the problem that you cite. For example, if you fill with, say, 1.5 that should work. Its not a matter of PyMC "checking" the the values are inside the support, it is just that PyMC calculates the log-probability at the first iteration, and therefore the values inserted for the missing values at the first iteration have to be valid. If you give discrete values a floating point value, it should end up getting truncated when converted to integers, so that will work. |
Thanks @fonnesbeck, using 1.5 works in my example. btw: Using the |
I'm not sure if I found a bug in pymc. It seems like fitting a Binomial with missing data can produce a
ZeroProbability
error depending on the chosen fill_value that masks missing data. But maybe I'm using it wrongly. I asked a question on stackoverflow, but I did not get an answer, that's why I report it here.I tried the following example with the current master branch from github. I'm aware of the bug concerning Binomial distributions in pymc 2.3.4, but this seems to be a different issue.
I fitted a Binomial distribution with pymc and everything worked as I expected:
Output:
Now, I tried a very similar situation with the difference that one observed value would be missing:
Unexpectedly, I got a
ZeroProbability
error:However, if I change the fill value in the masked array to 1, fitting works again:
Output:
Is this a bug or is there a problem with my model?
Thanks for any help!
The text was updated successfully, but these errors were encountered: