--- title: "Introduction to the R package survstan" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Introduction to the R package survstan} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` To fit a survival model with the __survstan__ package, the user must choose among one of the available fitting functions `*reg()`, where * stands for the type of regression model, that is, `aft` for accelerated failure time (AFT) models, `ah` for accelerates hazards (AH) models, `ph` for proportional hazards (PO) models, `po` for proportional (PO) models, `yp` for Yang \& Prentice (YP) models, or `eh` for extended hazard (EH) models. The specification of the survival formula passed to the chosen `*reg()` function follows the same syntax adopted in the __survival__ package, so that transition to the __survstan__ package can be smoothly as possible for those familiar with the __survival__ package. The code below shows the model fitting of an AFT model with Weibull baseline distribution using the `survstan::aftreg()` function. For comparison purposes, we also fit to the same data the Weibull regression model using `survival::survreg()` function: ```{r setup, message=FALSE} library(survstan) library(dplyr) ovarian <- ovarian %>% mutate( across(c("rx", "resid.ds"), as.factor) ) survreg <- survreg( Surv(futime, fustat) ~ ecog.ps + rx, dist = "weibull", data = ovarian ) survstan <- aftreg( Surv(futime, fustat) ~ ecog.ps + rx, dist = "weibull", data = ovarian ) ``` Although the model specification is quite similar, there are some important differences that the user should be aware of. While the model fitted using the `survival::survreg()` function uses the log scale representation of the AFT model with the presence of an intercept term in the linear predictor, the `survstan::aftreg()` considers the original time scale for model fitting without the presence of the intercept term in the linear predictor. To see that, let us summarize the fitted models: ```{r} summary(survreg) summary(survstan) ``` Next, we show how to fit a PH model using the `survstan::phreg()` function. For comparison purposes, the semiparametric Cox model is also fitted to the same data using the function `survival::coxph()`. ```{r} survstan <- phreg( Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, dist = "weibull" ) cox <- coxph( Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian ) coef(survstan) coef(cox) ```