toolkit for fitting survival models using Stan.
The R package survstan can be used to fit right-censored survival data under independent censoring. The implemented models allow the fitting of survival data in the presence/absence of covariates. All inferential procedures are currently based on the maximum likelihood (ML) approach.
You can install the released version of survstan from CRAN with:
install.packages("survstan")
You can install the development version of survstan from GitHub with:
# install.packages("devtools")
devtools::install_github("fndemarqui/survstan")
Let
The maximum likelihood estimate (MLE) of rstan::optimizing()
function. The function
rstan::optimizing()
further provides the hessian matrix of
Inferences on
Some of the most popular baseline survival distributions are implemented in the R package survstan. Such distributions include:
- Exponential
- Weibull
- Lognormal
- Loglogistic
- Gamma,
- Generalized Gamma (original Stacy’s parametrization)
- Generalized Gamma (alternative Prentice’s parametrization)
- Gompertz
- Rayleigh
- Birnbaum-Saunders (fatigue)
The parametrizations adopted in the package survstan are presented next.
If
$$
f(t|\lambda) = \lambda\exp\left{-\lambda t\right}I_{[0, \infty)}(t),
$$ where
The survival and hazard functions in this case are given by:
If
$$
f(t|\alpha, \gamma) = \frac{\alpha}{\gamma^{\alpha}}t^{\alpha-1}\exp\left{-\left(\frac{t}{\gamma}\right)^{\alpha}\right}I_{[0, \infty)}(t),
$$ where
The survival and hazard functions in this case are given by:
If
$$
f(t|\mu, \sigma) = \frac{1}{\sqrt{2\pi}t\sigma}\exp\left{-\frac{1}{2}\left(\frac{log(t)-\mu}{\sigma}\right)^2\right}I_{[0, \infty)}(t),
$$ where
The survival and hazard functions in this case are given by:
If
where
The survival and hazard functions in this case are given by:
If
where
The survival function is given by
$$S(t|\alpha, \lambda) = 1 - \frac{\gamma^{}(\alpha, \lambda t)}{\Gamma(\alpha)},$$ where $\gamma^{}(\alpha, \lambda t)$ is the lower incomplete gamma function, which is available only numerically. Finally, the hazard function is expressed as:
If
It can be show that the survival function can be expressed as:
Finally, the hazard function is expressed as:
If
$$f(t | \mu, \sigma, \varphi) =
\begin{cases}
\frac{|\varphi|(\varphi^{-2})^{\varphi^{-2}}}{\sigma t\Gamma(\varphi^{-2})}\exp{\varphi^{-2}[\varphi w - \exp(\varphi w)]}I_{[0, \infty)}(t), & \varphi \neq 0 \
\frac{1}{\sqrt{2\pi}t\sigma}\exp\left{-\frac{1}{2}\left(\frac{log(t)-\mu}{\sigma}\right)^2\right}I_{[0, \infty)}(t), & \varphi = 0
\end{cases}
$$ where
It can be show that the survival function can be expressed as:
$$
S(t|\mu, \sigma, \varphi) =
\begin{cases}
S_{G}(x|1/\varphi^2, 1), & \varphi > 0 \
1-S_{G}(x|1/\varphi^2, 1), & \varphi < 0 \
S_{LN}(x|\mu, \sigma), & \varphi = 0
\end{cases}
$$ where
Finally, the hazard function is expressed as:
If
The survival and hazard functions are given, respectively, by
Let
If
where
The survival function in this case is given by:
$$ S(t|\alpha, \gamma) =\Phi\left(\sqrt{\frac{t}{\gamma}}-\sqrt{\frac{\gamma}{t}}\right)(t) $$,
where
When covariates are available, it is possible to fit six different regression models with the R package survstan:
- accelerated failure time (AFT) models;
- proportional hazards (PH) models;
- proportional odds (PO) models;
- accelerated hazard (AH) models.
- Yang and Prentice (YP) models.
- extended hazard (EH) models.
The regression survival models implemented in the R package survstan are
briefly described in the sequel. Denote by
Accelerated failure time (AFT) models are defined as
$$
T = \exp{\mathbf{x} \boldsymbol{\beta}}\nu,
$$ where
$$ f(t|\boldsymbol{\theta}, \boldsymbol{\beta}, \mathbf{x}) = e^{-\mathbf{x} \boldsymbol{\beta}}f_{0}(te^{-\mathbf{x} \boldsymbol{\beta}}|\boldsymbol{\theta}) $$ and
Proportional hazards (PH) models are defined as
$$
h(t|\boldsymbol{\theta}, \boldsymbol{\beta}, \mathbf{x}) = h_{0}(t|\boldsymbol{\theta})\exp{\mathbf{x} \boldsymbol{\beta}},
$$ where
$$ f(t|\boldsymbol{\theta}, \boldsymbol{\beta}, \mathbf{x}) = h_{0}(t|\boldsymbol{\theta})\exp\left{\mathbf{x} \boldsymbol{\beta} - H_{0}(t|\boldsymbol{\theta})e^{\mathbf{x} \boldsymbol{\beta}}\right}, $$ and
Proportional Odds (PO) models are defined as
$$
R(t|\boldsymbol{\theta}, \boldsymbol{\beta}, \mathbf{x}) = R_{0}(t|\boldsymbol{\theta})\exp{\mathbf{x} \boldsymbol{\beta}},
$$ where
and
Accelerated hazard (AH) models can be defined as
so that
The survival function of the extended hazard (EH) model is given by:
The hazard and the probability density functions are then expressed as:
respectively.
The EH model includes the AH, AFT and PH models as particular cases when
The survival function of the Yang and Prentice (YP) model is given by:
The hazard and the probability density functions are then expressed as:
respectively, where
The YO model includes the PH and PO models as particular cases when