survHE light

I’ve made a major refactoring of (the development version of) survHE. I guess one of the main issues with the package (both from the point of view of the user and the maintainer) was that survHE is a big package and installation is a very lengthy process. And this is no surprise: the trade-off here is between the massive savings in computational time that are obtained by pre-compiling the Bayesian models available (through rstan) and the time it takes to get everything installed on your machine… And, from the developer’s point of view, often submission to CRAN has been a pain, because some of the files that get installed are very large and, again because of the nature of the package, there’s quite an intricate structure of “dependencies”, which makes the package very heavy.

What I’ve now done is, to put it pompously, in the spirit of some kind of survHE-verse, in the sense that I’ve split up the package in three parts (well, in fact three packages, really). The first one (which I’m still calling survHE) does contain all the back-bone and prepares for the full functionalities (ie running the built-in survival models under both a frequentist approach, using flexsurv and a Bayesian approach, either using INLA or rstan). But, crucially, the new survHE isn’t enough to open up all these facilities — it only implements the simpler frequentist models and so dispenses with lots of the complicated and computationally-intensive, time-consuming bits. So if you install survHE with:

remotes::install_github("giabaio/survHE", ref="devel")
  • You can only run the models using flexsurv;
  • All the options for the Bayesian models are coded up…

BUT: you need to install additional “modules” to enable the INLA and rstan facilities of survHE. You do this with:

# Install the INLA module
remotes::install_github("giabaio/survHE", ref="inla")

and / or

# Install the HMC module
remotes::install_github("giabaio/survHE", ref="hmc")

The first of these two packages/steps isn’t too time-consuming and installing survHEinla is fairly quick. The second is the actual bottle-neck and installing survHEhmc is a longer process — because like I said, it does install all the pre-compiled models and the heavy dependencies that come from rstan.

Basically, survHEinla and survHEhmc are not really stand-along packages. The user shouldn’t call them individually and, in effect, they don’t have all the actual facilities (eg the functions to plot and produce summaries, as well as the PSA facilities, which are still coded up in the main installation of survHE). On the contrary, they both “depend” on survHE, so that when they are loaded, survHE and all its functions are also automatically loaded.

From the user point of view, not much changes. You can still run a model using fit.models like this:

# Loads the "basic" survHE
library(survHE)
# Loads the example dataset from 'flexsurv'
data(bc)
# Fits a survival model using 'flexsurv' in the background
mle = fit.models(formula=Surv(recyrs,censrec)~group,data=bc,
    distr="exp",method="mle")

To do this, you don’t even need to install the Bayesian modules. But if you have installed either or both of them, you can simply specify the option method='hmc' or method='inla' and, in the background, survHE will check that you have the relevant module installed and load it, if so. As far as the user is concerned the call to fit a Bayesian model is the same as before

# Loads the "basic" survHE
library(survHE)
# Loads the example dataset from 'flexsurv'
data(bc)
# Fits a survival model using 'flexsurv' in the background
inla = fit.models(formula=Surv(recyrs,censrec)~group,data=bc,
    distr="exp",method="inla")

or

hmc = fit.models(formula=Surv(recyrs,censrec)~group,data=bc,
    distr="exp",method="hmc")

If you request a Bayesian model but have only installed survHE (and none of the Bayesian modules) the above calls with method set to either inla or hmc will return a message to instruct you to install survHEinla and/or survHEhmc, which you do like above, using remotes::install_github.

I’ll probably re-package it all and submit the three separate packages to CRAN — although I may leave survHEinla and survHEhmc on the GitHub repo only — this would make the submission process much easier, because in the current version, survHE is a very light-weight package. And installing from GitHub is increasingly easy — and very efficient for us to manage/update.

comments powered by Disqus

Related