Skip to content
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

Issue post-processing model with with Cox family type #1580

Closed
colinorourke opened this issue Jan 6, 2024 · 8 comments
Closed

Issue post-processing model with with Cox family type #1580

colinorourke opened this issue Jan 6, 2024 · 8 comments
Labels
Milestone

Comments

@colinorourke
Copy link

colinorourke commented Jan 6, 2024

I've been working with a model fitted using the "cox" family type. It works great, but most functions such are predict, log_lik, conditional_effects, etc. don't seem to work with models of this type. I'm not sure, but this seems to be because the bhaz_basis_matrix function is checking for objects of class mSpline, but the class of an object create by the mSpline function from the splines2 package seems actually to be MSpline.

A reprex for this error follows:

library(brms)
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.20.4). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').
#> 
#> Attaching package: 'brms'
#> The following object is masked from 'package:stats':
#> 
#>     ar

# load data from survival package
dt = survival::bladder1

# fit survival model in brms
surv_mod = brm(
  stop | cens(status == 0) ~ size + number,
  data = dt,
  family = cox(link = "log"))

# try to get pointwise log-likelihoods, which result in error 
log_lik(surv_mod)
#> Error in bhaz_basis_matrix(y, args, basis = bs): inherits(basis, "mSpline") is not TRUE

Created on 2024-01-06 with reprex v2.0.2

@paul-buerkner
Copy link
Owner

Strange. Which version of the splines2 package are you using? Perhaps they have changed the object class names?

@paul-buerkner
Copy link
Owner

Okay, I can confirm that problem starts with splines2 version > 0.5.0. In the previous version I had (0.4.7) things were just working. Changing object class names is really not a good thing to do in any package... I will fix it in brms soon.

@paul-buerkner paul-buerkner added this to the 2.21.0 milestone Jan 7, 2024
paul-buerkner added a commit that referenced this issue Jan 7, 2024
@paul-buerkner
Copy link
Owner

Should now be fixed.

@nstucke
Copy link

nstucke commented Mar 8, 2024

Hi @paul-buerkner! First, thank you for your work on this!

I have run into an issue similar to what's been described above. I am trying to calculate a Bayes Factor comparing the likelihood of the data under a null vs. alternative hypothesis using 2 Cox (survival) models. Using the bayes_factor() function, I am seeing the same error message described by @colinorourke above:

Error in bhaz_basis_matrix(y, args, basis = bs) :
inherits(basis, "mSpline") is not TRUE

A similar reprex to the above reproduces this error:

# load data from survival package
data <- survival::bladder1

# fit survival model in brms
surv_null_mod <- brm(
  stop | cens(status == 0) ~ size + number,
  data = data,
  family = cox(link = "log"))

surv_alt_mod <- brm(
  stop | cens(status == 0) ~ number,
  data = data,
  family = cox(link = "log"))

# try to calculate bayes factor...error 
bayes_factor(surv_alt_mod, surv_null_mod)

All of my packages/software are up to date:
splines2: version 0.5.1
brms: version 2.20.4
R: version 4.3.3 ("Angel Food Cake")

Could this be an object class names issue?

@paul-buerkner
Copy link
Owner

Update to the latest github version of brms

@nstucke
Copy link

nstucke commented Mar 8, 2024

Updated to brms: version 2.20.15 using:

if (!requireNamespace("remotes")) {
install.packages("remotes")
}
remotes::install_github("paul-buerkner/brms")

Re-ran all models above, and the error persists...

@paul-buerkner
Copy link
Owner

Did you restart R?

@nstucke
Copy link

nstucke commented Mar 8, 2024

Ooooof! That worked! Thank you so much, @paul-buerkner! Appreciate your time!

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

No branches or pull requests

3 participants