Skip to content
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

Fix tidy_poisson() p calculation #110

Closed
spsanderson opened this issue Mar 28, 2022 · 0 comments
Closed

Fix tidy_poisson() p calculation #110

spsanderson opened this issue Mar 28, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@spsanderson
Copy link
Owner

spsanderson commented Mar 28, 2022

Describe the bug
There is an issue in the calculation of the p column for tidy_poisson()

To Reproduce
Steps to reproduce the behavior:

> TidyDensity::tidy_poisson()
# A tibble: 50 x 7
   sim_number     x     y      dx      dy     p     q
   <fct>      <int> <int>   <dbl>   <dbl> <dbl> <dbl>
 1 1              1     1 -0.921  0.00554 0.368     0
 2 1              2     1 -0.823  0.0138  0.368     0
 3 1              3     2 -0.724  0.0310  0.368     0
 4 1              4     0 -0.625  0.0626  0.368     0
 5 1              5     0 -0.526  0.114   0.368     0
 6 1              6     1 -0.427  0.188   0.368     0
 7 1              7     0 -0.328  0.279   0.368     0
 8 1              8     1 -0.230  0.374   0.368     0
 9 1              9     2 -0.131  0.451   0.368     0
10 1             10     2 -0.0319 0.493   0.368     0
# ... with 40 more rows

Which gives the following probability plot:

image

Expected behavior

> tidy_poisson()
# A tibble: 50 x 7
   sim_number     x     y     dx      dy     p     q
   <fct>      <int> <int>  <dbl>   <dbl> <dbl> <dbl>
 1 1              1     2 -1.44  0.00429 0.736     0
 2 1              2     0 -1.30  0.00985 0.920     0
 3 1              3     0 -1.16  0.0208  0.981     0
 4 1              4     0 -1.02  0.0403  0.996     0
 5 1              5     0 -0.881 0.0717  0.999     0
 6 1              6     0 -0.741 0.117   1.00      0
 7 1              7     1 -0.600 0.176   1.00      0
 8 1              8     1 -0.460 0.244   1.00      0
 9 1              9     1 -0.319 0.310   1.00      0
10 1             10     0 -0.179 0.365   1.00      0
# ... with 40 more rows

Which gives the following probability plot:
image

The p line needs to be the following:

dplyr::mutate(p = list(stats::ppois(unlist(x), lambda = lambda))) %>%
@spsanderson spsanderson added the bug Something isn't working label Mar 28, 2022
@spsanderson spsanderson added this to the TidyDensity v1.0.2 milestone Mar 28, 2022
@spsanderson spsanderson self-assigned this Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant