Skip to content

Use posterior functions where possible / avoid duplication of code #408

Open

Description

@florence-bockting

Description

We have certain functions in loo that are more or less copies from code in posterior.
For loo v3.0.0, we need to inspect the loo code base and replace all function definitions that can be replaced by exporting the equivalent function from posterior. This avoids code duplication and reduces maintainability effort.

Example functions

  • is_constant (loo/posterior)
  • posterior:::ps_tail_length vs. loo:::n_pareto

Activity

  1. added this to the v3.0.0 milestone on Oct 16, 2026
  2. VisruthSK commented on Oct 17, 2026

    @VisruthSK
    Member

    See also #249

  3. soujasK commented on Nov 17, 2026

    @soujasK

    Hi @florence-bockting,I would like to work on this for v3.0.0 if nobody else is on it.I compared loo and posterior on current main:

    • is_constant is identical,so loo can use posterior::is_constant
    • gpdfit already calls posterior::gpdfit
    • ps_khat_threshold is different,loo caps it at 0.7 and posterior does not
    • n_pareto uses r_eff and ceiling(),while posterior::ps_tail_length ignores r_eff and uses floor()

    So switching the last two would change results.Should those also move to the posterior versions,or stay in loo for now?

  4. florence-bockting commented on Nov 18, 2026

    @florence-bockting
    ContributorAuthor

    Hi @florence-bockting,I would like to work on this for v3.0.0 if nobody else is on it.I compared loo and posterior on current main:

    • is_constant is identical,so loo can use posterior::is_constant
    • gpdfit already calls posterior::gpdfit
    • ps_khat_threshold is different,loo caps it at 0.7 and posterior does not
    • n_pareto uses r_eff and ceiling(),while posterior::ps_tail_length ignores r_eff and uses floor()

    So switching the last two would change results.Should those also move to the posterior versions,or stay in loo for now?

    Hello @soujasK, thank you for your interest on working on this topic and supporting loo.
    We have submitted yesterday (2026-11-18) a new Cran release of posterior. So, perhaps it makes sense to wait for this one until we can see in Cran (https://cloud.r-project.org/web/packages/posterior/index.html) that the date in "published" is updated.
    Then it might make sense to do a re-evaluation and list all the functions that you would change/modify in this issue.
    Afterwards you can perhaps simply tag us again (@jgabry , @VisruthSK, and me) and then we can give the "Go" and you can move on doing the PR.

    I hope this sounds reasonable =) Thank you again.

  5. soujasK commented on Nov 19, 2026

    @soujasK

    Hi @florence-bockting @jgabry @VisruthSK,posterior 1.8.0 is now on CRAN so I redid the comparison against current loo master.Most functions listed in #249 are already gone from loo.What is left:

    • is_constant:identical to posterior::is_constant (exported),so I would remove the loo copy and use posterior's
    • exp_x_minus_exp_y:identical,but it is internal in posterior,so I would keep the loo copy unless posterior exports it
    • ps_khat_threshold:loo caps it at 0.7 and posterior does not,so switching would change results
    • n_pareto vs posterior::ps_tail_length:loo uses r_eff and ceiling(),posterior ignores r_eff and uses floor(),so also a behaviour change
    • gpdfit:loo already just calls posterior::gpdfit,I would keep the wrapper since loo exports it
    • psis_smooth_tail:already handled in Rely on posterior for pareto smooth tails #290

    So my plan would be to replace is_constant only,and keep the others unless you want ps_khat_threshold and n_pareto to follow posterior.Does that sound ok?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions