Skip to content

Commit

Permalink
Fix inherits - broken due to breaking change in splines2 0.5
Browse files Browse the repository at this point in the history
splines2 v0.5.0 made a breaking change, and the class was renamed from iSpline to ISpline, and the order of the class heirarchy was also changed. Same for their mSpline class, etc.
  • Loading branch information
sambrilleman committed Oct 31, 2023
1 parent 46e8c90 commit 67478d4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/stan_surv.R
Original file line number Diff line number Diff line change
Expand Up @@ -1732,8 +1732,8 @@ make_basis <- function(times, basehaz, integrate = FALSE) {
basis_matrix <- function(times, basis, integrate = FALSE) {
out <- predict(basis, times)
if (integrate) {
stopifnot(inherits(basis, "mSpline"))
class(basis) <- c("matrix", "iSpline")
stopifnot(inherits(basis, "MSpline"))
class(basis) <- c("ISpline", "splines2", "matrix")
out <- predict(basis, times)
}
aa(out)
Expand Down

4 comments on commit 67478d4

@maurosc3ner
Copy link

@maurosc3ner maurosc3ner commented on 67478d4 Nov 2, 2023

Choose a reason for hiding this comment

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

Hi Sam,

I have a couple of models done with this feature/survival version 2.21.3. I updated because moved to other new laptop and I am having an issue when I call posterior_survfit()

Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 't': no applicable method for 'predict' applied to an object of class "c('matrix', 'mSpline', 'splines2')"

I wonder if it is related to the new version of splines2 or this new version. Is there any workaround for this?

Thanks

@sambrilleman
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm yeah, the other day I was trying to get the feature/survival branch more up-do-date with rstanarm master, and one of the things I hit was that splines2 had changed their classes, from for e.g. from something like c("matrix", "mSpline") to c("MSpline", "splines2", "matrix"), or something like that. It sounds like you are hitting something related to that. Are you using the current posterior_survfit on an older model object? i.e. one you fit with an earlier version of the feature/survival branch? If so, some suggestions that might or might not work:

  1. install an older version of splines2 and see if it works. The predict for the older splines2 should hopefully work with your older model's m-splines basis.
  2. create a fork or branch of feature/survival from before I made the updates, i.e. the commit prior to merging this PR Bring feature/survival up to date with master #607. I'm not 100% I got the correct commit from the history, but I tried here: https://github.com/stan-dev/rstanarm/tree/survival_2_21_3. Maybe you can install that branch instead and see if it fixes your issue. You would probably need the older version of splines2 though, for it to work.
  3. modify the class information for the baseline hazard information / basis stored in your fitted model. So that it matches the class required for the latest splines2. That might work, since the new splines2 predict would hopefully be compatible.

I feel like 3. might make the most sense and be the easiest, if it works.

@sambrilleman
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can see them mention adjusting the class order in major changes for v0.5 here: https://cran.r-project.org/web/packages/splines2/news/news.html

So I guess the predict with new splines2 might not work with the basis object from an older version of splines2.

@sambrilleman
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Brainmelt, I just realised you are commenting on this exact commit, and not just a repo Issue. 😂

Please sign in to comment.