-
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
Out of support behavior in distribution functions is not consistent with base R functions #5
Comments
Thanks for opening an issue. I replaced the fewest lines possible to get the functionality requested. Basically I replaced stop() with message() and updated the message. I had to keep in mind the vector case of inputs. Try out the following and let me know if it fixes the issue for pbetabinom and dbetabinom...
which should give:
For the density functions, similar approach.
should give
I'll just submit these changes to CRAN for pbetabinom and dbetabinom. Were there any other functions you really wanted to work this way? |
I think your solution is better than mine. No correction needs to be made for the q > size cases as the result looks like it will be 1 anyway. For q <0 I had been doing it inductively:
However you're right. ifelse(q<0,res,0) at the end would be the simplest solution. The beta Binomial functions are currently the only functions I am making use of right now. I would suggest updating the rest of them for consistency with other base functions, but all of it's up to you. Thank you for the quick response (And the great package)! |
I'll leave this issue open and will work on the rest of the functions as I can. Thanks for writing! I've already submitted v1.1.2 to CRAN. |
Hi Swihart, I took a look at the updated version today and I think that it is incorrect. I'm sorry I did not notice earlier. Setting q to 0 in the case of q < 0 is not correct. 0 is a possible outcome, -1 is not. This results in incorrect results:
The result in the second case should be 0. It is possible to get 0 or fewer success out of 5, but it is not possible to get -1 or fewer out of 5, so the probability should be 0. (The q > size case does work out) Here is an easy inductive fix: (Added after vectorization)
Here is my use case for out of range results (Besides consistency with base R functions): I am flipping 20 coins with an unknown probability of coming up heads. After each flip I stop if the probability that I'll have fewer than 9 heads at the end of the experiment is less than 10% and declare the experiment a failure. I would like to generate a heat map showing the probability of ending with fewer than 9 successes given any potential combination of observations/successes during the experiment: I could add my own handling to the cases where the observed successes are already greater than 9 or the number of successes required to reach 9 is fewer than the remaining number of trials. However the coding is cleaner if the pbetabinom function can correctly handle those cases. (and again inline with the handling of the base R functions) |
Is dbetabinom() okay? Is it just |
I think I have a fix for |
Now gives
|
check out v1.1.3. off to cran. I'll look into patching up other [pd] functions in near future. |
With base R distribution functions if you ask the d function for a value it will return 0 rather than an error. Similarly for the p functions, if you ask for a q value greater or less than the support it will return 1 or 0 respectively.
Examples:
With the rmutil functions out of support values give an error.
The base R method of dealing with this is the mathematically correct one: P(2 heads, one coin flip) =0. P(5 or fewer heads on 3 coin flips)=1. These are defined, if typically uninteresting, values and should not generate an error.
I have not checked all of the functions, but it looks like the fix should be fairly simple. For pbetabinom at least, removing the check will generate the expected results with no additional code.
The text was updated successfully, but these errors were encountered: