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

Latest install of rstanarm stan_surv() fails with random effects. #588

Open
padpadpadpad opened this issue Apr 14, 2023 · 9 comments
Open

Comments

@padpadpadpad
Copy link

Summary:

I downloaded rstanarm in my usual way and tried to run a stan_surv model with random effects and it errors.

Description:

When I run the example from stan_surv() that includes random I get the error:

Error : Exception: model_surv_namespace::model_surv: V_event[i_0__][i_1__] is 0, but must be greater than or equal to 1  (in 'model_surv' at line 648)

In addition: Warning messages:
1: In status < 0 || status > 3 :
  'length(x) = 40 > 1' in coercion to 'logical(1)'
2: In status < 0 || status > 3 :
  'length(x) = 40 > 1' in coercion to 'logical(1)'
3: In status < 0 || status > 3 :
  'length(x) = 40 > 1' in coercion to 'logical(1)'
4: In status < 0 || status > 3 :
  'length(x) = 40 > 1' in coercion to 'logical(1)'
failed to create the sampler; sampling not done
Error in check_stanfit(stanfit) : 
  Invalid stanfit object produced please report bug

Reproducible Steps:

I download rstanarm by running: git clone -b feature/survival https://github.com/stan-dev/rstanarm.git in the Terminal. I then run devtools::document() and Build the R package locally.

I then ran:

m_frail <- stan_surv(
  formula = Surv(eventtime, status) ~ trt + (1 | site), 
  data    = frail[1:40,], 
  basehaz = "exp", 
  chains  = 1,
  refresh = 0,
  iter    = 600,
  seed    = 123)

And got the error above. Other random effects model also fail.

RStanARM Version:

I am running rstanarm v2.21.3

R Version:

I am running R version v4.2.2

Operating System:

Your operating system (e.g., OS X 13.2.1)

@lauracp92
Copy link

Hello Daniel,
were you able to fix the error?
Do you know which R version works for doing random effects?
Thank you

@padpadpadpad
Copy link
Author

padpadpadpad commented Sep 12, 2023

Hi @lauracp92 I have not been able to solve this with the most recent install of the rstanarm survival branch. Any ideas @sambrilleman @jgabry ?

I had an old fork of the repository that used to work: https://github.com/padpadpadpad/rstanarm but that has broken now too, with the error:

Error in status < 0 || status > 3 : 
  'length = 40' in coercion to 'logical(1)'

So I do not have a fix for this at all. Frustrating because stan_surv() is amazing and I would love to be able to easily and reliably use it.

Wonder if it is an error linked to an update of rstan more generally?

@jgabry
Copy link
Member

jgabry commented Sep 12, 2023

Does the version in the mc-stan packages repository work?

install.packages("rstanarm", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

@jgabry
Copy link
Member

jgabry commented Sep 12, 2023

fixed typo in my previous comment (it was installing RStan not rstanarm)

@padpadpadpad
Copy link
Author

padpadpadpad commented Sep 14, 2023

@jgabry seems to install but it does not have the survival branch in so the stan_surv() function does not exist.

@jgabry
Copy link
Member

jgabry commented Sep 14, 2023

Hmm I thought that had the survival branch, but you're right that stan_surv isn't there. Maybe post a comment on the PR for the survival branch #323 and see if any of the main contributors to that branch have any ideas why it isn't working, I'm honestly not sure. Sorry about that! (I'm still hoping to include this on CRAN at some point but I think we were still waiting for some work to be finished on that branch.)

@sambrilleman
Copy link
Collaborator

Sorry for the slow reply. Yeah for this issue:

I had an old fork of the repository that used to work: https://github.com/padpadpadpad/rstanarm but that has broken now too, with the error:

take a look at this PR @padpadpadpad: #594
Doing the same on your fork should hopefully fix the issue, for R >= 4.3.

As for the error that started this thread I'm a little unsure at the moment!

@jgabry seems to install but it does not have the survival branch in so the stan_surv() function does not exist.

Also, for this issue, I think it is because if the binary isn't compatible with version of R you have, then it falls back to another version of rstanarm at the next repos source. So what happens is you don't get the version from https://mc-stan.org/r-packages/ because its not compatible with say R 4.3, and then R silently goes to CRAN because you have it in your default repos list and installs the latest CRAN version of rstanarm which doesn't have stan_surv! 😢 The fix would be updating the binaries at https://mc-stan.org/r-packages/ to have a version built for R 4.3, but I'm not sure who has time to do that! I think @rok-cesnovar was going to try, but not sure if he ever got there.
So for people who cannot build from source there is no easy solution I don't think.
Or the better fix, getting stan_surv into the CRAN release 👴 😅

Unfortunately I'm not working on this stuff at the moment, and now work almost exclusively in Python so don't even really have a dev environment set up to easily test stuff out atm...! 😞

@sambrilleman
Copy link
Collaborator

There was an issue thread somewhere here or in the forums about the https://mc-stan.org/r-packages/ falling back to CRAN when there isn't a binary for the R version you have, but I can't for the life of me find it.

@padpadpadpad
Copy link
Author

Hi @sambrilleman and @jgabry, I do really appreciate you responding - especially as Sam no longer actively work on this.

I have tried what you suggested, but now with both the survival branch on rstanarm and my old fork, I get the error error: no member named 'validate_dims' in namespace 'stan::io'.

Seems to be an old-ish problem, but I cannot work out how to fix it easily.

With the latest CRAN installs of rstanarm, rstan and StanHeaders everything works fine.

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

No branches or pull requests

4 participants