Skip to content

Add ppc_loo_pit_ecdf #345

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

TeemuSailynoja
Copy link
Collaborator

@TeemuSailynoja TeemuSailynoja commented Apr 23, 2025

Made an implementation of the ppc_pit_ecdf() for LOO-PITs. This is mostly a convenience function, as one could already pass LOO-PITs to the ppc_pit_ecdf in its pit argument. Now works directly with for example brms::pp_check(brms_fit, "loo_pit_ecdf")

I have two questions:

  1. ppc_loo_pit_ecdf() uses a prob argument. ppc_loo_pit_intervals already imports the args-prob-prob_outer template, which has a different doc string for prob. This template is used outside the ppc_loo functions, so I don´t think adding text specific to this new function there is the best solution. How should this be handled?
  2. I made ppc_loo_pit_ecdf have a slightly different signature to ppc_pit_ecdf. Namely, instead of K, this new function uses a more informative eval_points, and instead of the boolean interpolate_adj, now I have interval_method = c("interpolate", "optimize"). Should I hold on to this change and have the functions share their signature? I think the new one is more clear and ppc_pit_ecdf should also move towards that eventually.

@TeemuSailynoja TeemuSailynoja changed the title Add ppc loo pit ecdf Add ppc_loo_pit_ecdf Apr 23, 2025
@codecov-commenter
Copy link

codecov-commenter commented Apr 23, 2025

Codecov Report

Attention: Patch coverage is 95.79832% with 5 lines in your changes missing coverage. Please review.

Project coverage is 98.60%. Comparing base (4d40ba6) to head (f8fab2f).

Files with missing lines Patch % Lines
R/ppc-loo.R 95.79% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #345      +/-   ##
==========================================
- Coverage   98.66%   98.60%   -0.06%     
==========================================
  Files          35       35              
  Lines        5466     5533      +67     
==========================================
+ Hits         5393     5456      +63     
- Misses         73       77       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jgabry
Copy link
Member

jgabry commented Apr 24, 2025

  1. ppc_loo_pit_ecdf() uses a prob argument. ppc_loo_pit_intervals already imports the args-prob-prob_outer template, which has a different doc string for prob. This template is used outside the ppc_loo functions, so I don´t think adding text specific to this new function there is the best solution. How should this be handled?

Maybe we don't use the args-prob-prob_outer template for ppc_loo_pit_intervals and instead you can do something like this?

@param prob For `ppc_loo_pit_intervals()` `prob` is used for X. For `ppc_loo_pit_ecdf()` `prob` is used for Y.`

where X just basically says what's in the template. Not optimal to copy what's in the template I guess, but not a big deal.

  1. I made ppc_loo_pit_ecdf have a slightly different signature to ppc_pit_ecdf. Namely, instead of K, this new function uses a more informative eval_points, and instead of the boolean interpolate_adj, now I have interval_method = c("interpolate", "optimize"). Should I hold on to this change and have the functions share their signature? I think the new one is more clear and ppc_pit_ecdf should also move towards that eventually.

It would be nice to have the same signature, but I agree with you that your new one is more clear. Since the new one is better, it's ok with me to have a different signature for now until we can also update the one for ppc_pit_ecdf.

man/PPC-loo.Rd Outdated
Comment on lines 65 to 68
eval_points = NULL,
K = NULL,
prob = 0.99,
plot_diff = FALSE,
interval_method = c("interpolate", "optimize")
interpolate_adj = NULL
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also unified the arguments for now, to keep the code more simple.
I suggest that, when I work on the documentation and possibly need to rearrange how the PPC function pages are grouped, I will add the clearer argument names and add a deprecation warning to the old ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, with this rearranging, the template could come back to use with ppc_loo_pit_intervals().

It would probably make sense to have ppc_(loo)_pit_ecdf(), ppc_loo_pit_qq(), and ppc_loo_pit_overlay() share a documentation page, and move ppc_loo_intervals(), and ppc_loo_ribbon() join their LOOless counterparts on the PPC intervals documentation page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also unified the arguments for now, to keep the code more simple.
I suggest that, when I work on the documentation and possibly need to rearrange how the PPC function pages are grouped, I will add the clearer argument names and add a deprecation warning to the old ones.

Sounds good, I like that plan.

Copy link
Member

@jgabry jgabry Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, with this rearranging, the template could come back to use with ppc_loo_pit_intervals().

It would probably make sense to have ppc_(loo)_pit_ecdf(), ppc_loo_pit_qq(), and ppc_loo_pit_overlay() share a documentation page, and move ppc_loo_intervals(), and ppc_loo_ribbon() join their LOOless counterparts on the PPC intervals documentation page.

That also sounds good. When I first included those LOO-based plots I thought it made sense to put them all together. But I think you're right that this reorganization makes sense at this point. I think we'll just want to link between the documentation pages, pointing out that there are other LOO-based plots in various locations.

@jgabry
Copy link
Member

jgabry commented Apr 25, 2025

The code looks great. I will try to make some time later today to actually try using the function. One minor request for now: can you mention this function in the "Plot Descriptions" section of the documentation?

Comment on lines 82 to 86
expect_equal(p1$labels$x, "LOO PIT")
expect_equal(p1$labels$y, "ECDF")
expect_equal(p1$data, p2$data)
expect_gg(p3 <- ppc_loo_pit_ecdf(y, yrep, lw, plot_diff = TRUE))
expect_equal(p3$labels$y, "ECDF difference")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for future compatibility with ggplot2 we probably need to do what was done in https://github.com/stan-dev/bayesplot/pull/337/files#diff-d31e64955d39a8924be5d979cb21c5e96514987aeff9ca8cf2af067e98f3b156 with checking for the get_labs() function and using it if found.

Copy link
Member

@jgabry jgabry Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I just noticed that I haven't done this for the tests for ppc_loo_pit_qq either. If you want you can do it with this PR but I can also do it separately since it's not related to your PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also add the part for ppc_loo_pit_qq.

Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function works great. I made one small comment on the tests and then there's mentioning the function in the "Plot Descriptions" section of the doc, but otherwise I think this is ready without any other changes.

One strange thing is that two of the visual tests are failing for me locally but apparently not on Github Actions. But they're not your tests for the new function, they're ppc-loo-pit-overlay-default.svg and ppc-loo-pit-qq-default.svg. Does everything pass for you locally?

@TeemuSailynoja
Copy link
Collaborator Author

The function works great. I made one small comment on the tests and then there's mentioning the function in the "Plot Descriptions" section of the doc, but otherwise I think this is ready without any other changes.

One strange thing is that two of the visual tests are failing for me locally but apparently not on Github Actions. But they're not your tests for the new function, they're ppc-loo-pit-overlay-default.svg and ppc-loo-pit-qq-default.svg. Does everything pass for you locally?

For me, all tests are passing. I have now added the forward compatibility for the tests of ppc_loo_pit_ecdf, and ppc_loo_pit_qq and included a short description of the function under "Function Descriptions".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants