You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This update introduces two new S3 methods predictEventProb.pamm and predictEventProb.list to the predict.R script. These additions enable compatibility with the pec package when working in a competing risks setting using pammtools.
Review of PR #252 — predictEventProb for pammtools
Overview
The PR adds predictEventProb.pamm() and predictEventProb.list() for pec package compatibility in competing risks. Valuable goal, but the implementation has several bugs and design issues that need fixing before merge.
The existing get_cif.default uses - 1e-20. The PR uses - 1e-5, which is 15 orders of magnitude larger. When overall survival drops below 1e-5 (right tail), CIF increments go negative — a CIF is a probability and must be non-decreasing. Fix: use - 1e-20 or .Machine$double.eps to match existing code.
2. object[["attr_ped"]]$risks is likely NULL
In predictEventProb.pamm(), all_causes is extracted from object[["attr_ped"]]$risks. But looking at get_cif.default (line ~776 of add-functions.R), this exact approach was abandoned in favor of levels(newdata[[cause_var]]) because attr_ped on the model object isn't reliable. If all_causes is NULL, the for loop never executes, no csh* columns are created, and the final pull() silently fails.
These are development objects from the author's session. If defaults are ever evaluated, R throws a confusing "object not found" error. The signature must match the generic: function(object, newdata, times, cause, ...).
4. id_var undefined when newdata is already PED
id_var is assigned only inside the if (!is.ped(...)) block but used unconditionally later in arrange(), group_by(), and the final map(). Passing PED input will error with "object 'id_var' not found".
5. Bare arrange(id, times) — uses unquoted id
The code uses arrange(id, times) instead of arrange(.data[[id_var]], .data$times). This (a) hardcodes the column name id instead of using id_var, and (b) triggers an R CMD check NOTE for no visible binding.
Design Issues (should fix)
6. Dispatching on plain list is too broad
Any list passed to predictEventProb() would match — data frames, gam objects, etc. The principled fix is a custom class (e.g., pamm_list) with a constructor that validates all elements are pamm objects with compatible cut points. At minimum, add validation at the top of the method.
The existing predictSurvProb.pamm uses predict(unpam(object), ...). The PR calls predict(object, ...) directly. It works today because no predict.pamm() exists, but it's inconsistent and fragile if one is added later.
9. @importFrom pammtools get_intervals — a package cannot import from itself. Remove.
10. ~80% code duplication
The PED preparation and CIF calculation are nearly identical between the two methods. Extract shared logic into internal helpers.
11. Missing newline at end of file — trivial but will trigger a NOTE.
Mathematical Note
The CIF formula uses S(t_j) (survival at end of interval) instead of S(t_{j-1}) (survival entering the interval) as in the standard Aalen-Johansen estimator. However, this matches the existing get_cif.default implementation, so it's internally consistent. For fine time grids the bias is small. Worth noting but not a blocker for this PR specifically.
PR Extend arbitrary time point support in add_cif #271 (Extend arbitrary time point support in add_cif): Extends the native add_cif() for arbitrary time points — the same domain as this PR. If both merge, there would be two independent CIF implementations that could diverge. Consider whether predictEventProb should delegate to add_cif internally rather than reimplementing the calculation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This update introduces two new S3 methods predictEventProb.pamm and predictEventProb.list to the predict.R script. These additions enable compatibility with the pec package when working in a competing risks setting using pammtools.