Skip to content

Dependence aware tests for ppc*ecdf#428

Open
florence-bockting wants to merge 170 commits into
stan-dev:masterfrom
florence-bockting:dependence-aware-LOO-PIT
Open

Dependence aware tests for ppc*ecdf#428
florence-bockting wants to merge 170 commits into
stan-dev:masterfrom
florence-bockting:dependence-aware-LOO-PIT

Conversation

@florence-bockting
Copy link
Copy Markdown

@florence-bockting florence-bockting commented Mar 4, 2026

Description

The current approach in ppc_loo_pit_ecdf and ppc_pit_ecdf assumes independence of LOO-PIT values which is not valid (Marhunenda et al., 2005). The corresponding graphical test yields an envelope that is too wide, reducing the test's ability to reveal model miscalibration.
Tesso & Vehtari (2026, see preprint) propose three testing procedures that can handle any dependent uniform values and provide an updated graphical representation that uses color coding to indicate influential regions or most influential points of the ECDF. This PR implements the new development, by adding the updated approach (method = "correlated") additionally to the previous approach (method = "independent").

TODOs

  • updated ppc_loo_pit_ecdf() function in ppc-loo.R
  • updated ppc_pit_ecdf() and ppc_pit_ecdf_grouped() function in ppc-distributions.R
  • add unittests and visual regression tests
  • update documentation
  • deprecation suggestion of old method
    • P1: old method (default) and new method available via method argument
    • P2: new method (default) and old method available via method argument
    • P3: old method is removed

Copy link
Copy Markdown
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.

Here are a few comments and questions. So far I've only looked at some of the code, so I may have more, but I thought I would give you these now so we could start discussing.

Comment thread R/ppc-loo.R Outdated
Comment thread R/ppc-loo.R Outdated
Comment thread R/ppc-loo.R Outdated
@jgabry
Copy link
Copy Markdown
Member

jgabry commented Apr 13, 2026

@florence-bockting The changes look good, but I think there are the same issues (with the gamma doc and the pareto_pit issue) in the ppc-distributions.R file too, right? Also, how much of the doc in the two R files now overlaps? Could we write some of it once and share it? (If it's only a small amount of overlap then maybe not worth it).

@florence-bockting
Copy link
Copy Markdown
Author

florence-bockting commented Apr 15, 2026

@jgabry
Thanks for the comments. I was planning to do the refactoring for reducing duplicate code between the ppc-ecdf functions at a later stage as this was already in the original version the case. But given your comment I realized that I should probably do it just now. Thus:

I have refactored the code such that it removes duplicate code and documentation by creating new helper functions or template files.
Furthermore, I increased the helper-text size but also added now the factor for controlling size as an additional argument. When we improve the theme, we can probably get rid of it again. @avehtari

@jgabry
Copy link
Copy Markdown
Member

jgabry commented Apr 16, 2026

@florence-bockting please also officially add yourself to the DESCRIPTION file as part of this PR!

@florence-bockting
Copy link
Copy Markdown
Author

@jgabry just as a little reminder that this PR is still waiting for final review. Thank you

Copy link
Copy Markdown
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.

Here are some review comments. Sorry for the delay! Overall I think this is in good shape, just a few relatively minor comments.

Comment thread R/helpers-ppc.R
) {
# pareto-pit values
if (isTRUE(pareto_pit) && is.null(pit)) {
suggested_package("rstantools")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think rstantools is actually needed for this branch here, right?

Comment thread R/helpers-ppc.R
}
}

alpha <- 1 - prob
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we validate that prob is a valid probability? Either here or before it's passed in? I guess whatever is consistent with how we've been checking other arguments.

Comment on lines +10 to +13
#' @param color When `method = "correlated"`, a vector with base color and
#' highlight color for the ECDF plot. Defaults to
#' `c(ecdf = "grey60", highlight = "red")`. The first element is used for
#' the main ECDF line, the second for highlighted suspicious regions.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code that processes the color vector requires these exact names to be used in order to work properly (I think) but it doesn't check for the names. It indexes color["ecdf"] and color["highlight"]. The doc also mentions "first element" and "second element", but it's the names, not the position, that are used in the code. The user can pass incorrect names or unnamed vectors and I think the colors won't render properly. We should probably either check for the names or just use the position (first element and second element) and forget about the names.

Comment thread R/ppc-loo.R
#' For `ppc_loo_pit_ecdf()` when `method = 'independent'`.
#' The default is to use interpolation if `K` is greater than 200.
#' @param pit An optional vector of probability integral transformed values for
#' which the ECDF is to be drawn. For `ppc_loo_pit_ecdf()`. If `NULL`, PIT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also mention the other ppc_loo_* functions that take the pit argument in addition to ppc_loo_pit_ecdf()?

Comment thread R/ppc-distributions.R
#' @note
#' Note that the default "independent" method is **superseded** by
#' the "correlated" method (Tesso & Vehtari, 2026) which accounts for dependent
#' PIT values.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because this is documented on the same page as the other function that the same @note it shows up twice in the .Rd file. However, it also doesn't show up at all (at least for me) when rendering the doc in RStudio. Maybe the Note field isn't rendered? Do you see that too?

Another option would be to remove both uses of @note and instead use the Plot Descriptions section. And I guess same thing for the loo versions, if applicable.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants