Stan_surv in rstanarm

Hi all,

I am using R 4.1.2 and trying to fit a model with stan_surv. I followed the instruction to install rstanarm from

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

However, I still cannot see the function stan_surv. Did I miss any steps?

My understanding is that you need to use the developer version of rstanarm from github.
The code below should work but I’m having problems with the install in windows

devtools::install_github(“stan-dev/rstanarm”,ref = “feature/survival”, build_vignettes = FALSE)

Having the same problem, unable to load stan_surv into R 4.2.2, have tried the following

  1. install.packages(“rstanarm”, repos = c(“Repository for distributing (some) stan-dev R packages | r-packages”, getOption(“repos”)))
  2. remotes::install_github(‘stan-dev/rstanarm@feature/survival’, build_vignettes = FALSE)
    3.devtools::install_github(“stan-dev/rstanarm”,ref = “feature/survival”, build_vignettes = FALSE)

but still can’t get the function.

Any suggestions?

Thanks

1 Like

I was able to get these functions to work by cloning the branch and then building the package from RStudio.

2 Likes

Thanks for the reply. While i have a GitHub account, I’m quite a newbie in its use. Do i clone this as a download zip file? How do I build a package with RStudio. if you have the time to supply some more details that would be great.
Thanks again.

1 Like

Yes you could download the code as a .zip file by clicking on the green ‘code’ button on github. Then in the downloaded folder you can open rstanarm.Rproj, which will open in R studio. Since the repository is an R package, you should see the ‘build’ pane somewhere in your Rstudio window. From the ‘build’ pane you can click the ‘Install and Restart’ button, which will install the package as though you had run install.packages().

For me this made the stan_surv() function available where installing from github had failed.

Downloading the .zip will work, but learning how to properly clone a github repository may be useful to you as well. I recommend this beginner’s resource for learning how to use github with R.

2 Likes

Thanks, that worked! Reading HappyGit is on my to do list.
Need to build the documentation files for this package.
While waiting for that finish, do you know if the argument family = “cox” works?

1 Like

Hmm not sure about family = “cox” in rstanarm, I didn’t spend much time in the package. I ended up switching over to brms after playing around a little bit.

Hi all,
I am a new member in this forum. I want to use function ‘Stan_surv’ in ‘rstanarm’ package.
I really need to use function ‘Stan-surv’ for running Cox PH model using Bayesian method. But I got error "could not find function ‘Stan_surv’ after installing package “rstanarm” in different ways. Then I found this instruction for installing the package from alex.b.r
"make: *** [stan_files/bernoulli.o] Error 1
rm stan_files/bernoulli.cc
ERROR: compilation failed for package ‘rstanarm’

  • removing ‘/usr/local/lib/R/4.3/site-library/rstanarm’"

Can anyone know this and help me how to address this error? Or any suggestion?
I am using R 4.3.1 version on a Mac computer.

Thank you,

According to the message and instructions you are referring to, “Stan_surv” should actually be with a lower case “s”: “stan_surv”. If that’s not the cause, someone else needs to step in and advise :)

Hello everyone,

I am a researcher currently working with R version 4.3.2 and I’ve encountered an issue while trying to install the feature/survival branch of rstanarm. I am attempting a direct installation from GitHub using the command:

devtools::install_github("stan-dev/rstanarm", ref = "feature/survival", build_vignettes = FALSE)

However, I am running into an error during the installation process. The error message is as follows:

C:/PROGRA~1/R/R-43~1.2/bin/x64/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/surv.stan
Error in rstan::stanc(file, allow_undefined = TRUE, obfuscate_model_name = FALSE) : 
  0
Semantic error in 'string', line 404, column 2 to line 411, column 3:
   -------------------------------------------------
   402:    }
   403:  
   404:    vector quadrature_log_cdf(vector qwts, vector log_hazard, int qnodes, int N) {
           ^
   405:      int M = rows(log_hazard);
   406:      vector[M] hazard = exp(log_hazard);
   -------------------------------------------------

Real return type required for probability functions ending in _log, _lpdf, _lupdf, _lpmf, _lupmf, _cdf, _lcdf, or _lccdf.

From what I understand, the error seems to be related to the function quadrature_log_cdf returning a vector instead of a real type, which could potentially be a bug.

I would greatly appreciate any insights or solutions anyone might have regarding this issue. Has anyone else encountered this problem or have any advice on how to resolve it?

Thank you in advance for your help!

1 Like