Title: | Fitting Survival Regression Models via 'Stan' |
---|---|
Description: | Parametric survival regression models under the maximum likelihood approach via 'Stan'. Implemented regression models include accelerated failure time (AFT) models, proportional hazards (PH) models, proportional odds (PO) models, accelerated hazard (AH) models, Yang and Prentice (YP) models, and extended hazard (EH) models. Available baseline survival distributions include exponential, Weibull, log-normal, log-logistic, gamma, generalized gamma, rayleigh, Gompertz and fatigue (Birnbaum-Saunders) distributions. The baseline survival distribution can be further modeled using Bernstein polynomails' approximation of the baseline hazard function. References: Lawless (2002) <ISBN:9780471372158>; Bennett (1982) <doi:10.1002/sim.4780020223>; Chen and Wang(2000) <doi:10.1080/01621459.2000.10474236>; Demarqui and Mayrink (2021) <doi:10.1214/20-BJPS471>. |
Authors: | Fabio Demarqui [aut, cre, cph]
|
Maintainer: | Fabio Demarqui <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-01-27 06:14:52 UTC |
Source: | https://github.com/fndemarqui/survstan |
The aim of the R package survstan is to provide a 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.
_PACKAGE
Stan Development Team (2023). “RStan: the R interface to Stan.” R package version 2.21.8, https://mc-stan.org/.
Lawless JF (2002). Statistical Models and Methods for Lifetime Data, Wiley Series in Probability and Statistics, 2nd Edition edition. John Wiley and Sons. ISBN 9780471372158.
Bennett S (1983). “Analysis of survival data by the proportional odds model.” Statistics in Medicine, 2(2), 273-277. doi:10.1002/sim.4780020223.
Chen YQ, Wang M (2000). “Analysis of Accelerated Hazards Models.” Journal of the American Statistical Association, 95(450), 608-618. doi:10.1080/01621459.2000.10474236.
Demarqui FN, Mayrink VD (2021). “Yang and Prentice model with piecewise exponential baseline distribution for modeling lifetime data with crossing survival curves.” Brazilian Journal of Probability and Statistics, 35(1), 172 – 186. doi:10.1214/20-BJPS471.
Function to fit accelerated failure time (AFT) models.
aftreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
aftreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which function is called. |
baseline |
the chosen baseline distribution; options currently available are: exponential, weibull, lognormal, loglogistic and Birnbaum-Saunders (fatigue) distributions. |
dist |
alternative way to specify the baseline distribution (for compatibility with the |
init |
initial values specification (default value is 0); see the detailed documentation for |
... |
further arguments passed to other methods. |
aftreg returns an object of class "aftreg" containing the fitted model.
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
Function to fit accelerated hazard (AH) models.
ahreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
ahreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which function is called. |
baseline |
the chosen baseline distribution; options currently available are: exponential, weibull, lognormal, loglogistic and Birnbaum-Saunders (fatigue) distributions. |
dist |
alternative way to specify the baseline distribution (for compatibility with the |
init |
initial values specification (default value is 0); see the detailed documentation for |
... |
further arguments passed to other methods. |
ahreg returns an object of class "ahreg" containing the fitted model.
library(survstan) fit <- ahreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
library(survstan) fit <- ahreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
Akaike information criterion
## S3 method for class 'survstan' AIC(object, ..., k = 2)
## S3 method for class 'survstan' AIC(object, ..., k = 2)
object |
an object of the class survstan. |
... |
further arguments passed to or from other methods. |
k |
numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC. |
the Akaike information criterion value when a single model is passed to the function; otherwise, a data.frame with the Akaike information criterion values and the number of parameters is returned.
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) AIC(fit1, fit2, fit3)
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) AIC(fit1, fit2, fit3)
Compute analysis of variance (or deviance) tables for one or more fitted model objects.
## S3 method for class 'survstan' anova(...)
## S3 method for class 'survstan' anova(...)
... |
further arguments passed to or from other methods. |
the ANOVA table.
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) anova(fit1, fit2, fit3)
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) anova(fit1, fit2, fit3)
This function is used to allow the user to specify an arbitrary value for the polynomial's degree m. If m = NULL, then m = min(m_max, ceiling(n^0.4)) is used, where m_max = 15.
bernstein(m = NULL)
bernstein(m = NULL)
m |
the Bernstein polynomial's degree; default is NULL. |
a list with the baseline name and the polynomial's degree m.
Estimated regression coefficients
## S3 method for class 'survstan' coef(object, ...)
## S3 method for class 'survstan' coef(object, ...)
object |
an object of the class survstan |
... |
further arguments passed to or from other methods |
the estimated regression coefficients
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) coef(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) coef(fit)
Confidence intervals for the regression coefficients
## S3 method for class 'survstan' confint(object, parm = NULL, level = 0.95, ...)
## S3 method for class 'survstan' confint(object, parm = NULL, level = 0.95, ...)
object |
an object of the class survstan. |
parm |
a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered. |
level |
the confidence level required. |
... |
further arguments passed to or from other methods. |
100(1-alpha) confidence intervals for the regression coefficients.
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) confint(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) confint(fit)
Generic S3 method cross_time
cross_time(object, ...)
cross_time(object, ...)
object |
a fitted model object |
... |
further arguments passed to or from other methods. |
the crossing survival time
Computes the crossing survival times
## S3 method for class 'survstan' cross_time( object, newdata1, newdata2, conf.level = 0.95, nboot = 1000, cores = 1, ... )
## S3 method for class 'survstan' cross_time( object, newdata1, newdata2, conf.level = 0.95, nboot = 1000, cores = 1, ... )
object |
an object of class survstan |
newdata1 |
a data frame containing the first set of explanatory variables |
newdata2 |
a data frame containing the second set of explanatory variables |
conf.level |
level of the confidence/credible intervals |
nboot |
number of bootstrap samples (default nboot=1000). |
cores |
number of cores to be used in the bootstrap sampling; default is 1 core; |
... |
further arguments passed to or from other methods. |
the crossing survival time
library(survstan) data(ipass) fit <- ypreg(Surv(time, status)~arm, data=ipass, baseline = "weibull") summary(fit) newdata1 <- data.frame(arm=0) newdata2 <- data.frame(arm=1) tcross <- cross_time(fit, newdata1, newdata2, nboot = 10) tcross
library(survstan) data(ipass) fit <- ypreg(Surv(time, status)~arm, data=ipass, baseline = "weibull") summary(fit) newdata1 <- data.frame(arm=0) newdata2 <- data.frame(arm=1) tcross <- cross_time(fit, newdata1, newdata2, nboot = 10) tcross
Function to fit Extended Hazard (EH) models.
ehreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
ehreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which function is called. |
baseline |
the chosen baseline distribution; options currently available are: exponential, weibull, lognormal, loglogistic and Birnbaum-Saunders (fatigue) distributions. |
dist |
alternative way to specify the baseline distribution (for compatibility with the |
init |
initial values specification (default value is 0); see the detailed documentation for |
... |
further arguments passed to other methods. |
ehreg returns an object of class "ehreg" containing the fitted model.
library(survstan) fit <- ehreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
library(survstan) fit <- ehreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
Functions required for compatibility of survstan with emmeans.
Users are not required to call these functions themselves. Instead,
they will be called automatically by the emmeans
function
of the emmeans package.
recover_data.survstan(object, ...) recover_data.ypreg(object, term = c("short", "long"), ...) recover_data.ehreg(object, term = c("AF", "RH"), ...)
recover_data.survstan(object, ...) recover_data.ypreg(object, term = c("short", "long"), ...) recover_data.ehreg(object, term = c("AF", "RH"), ...)
object |
An object of the same class as is supported by a new method. |
... |
Additional parameters that may be supported by the method. |
term |
character specifying whether AF or RH term regression coefficients are to be used. |
Parameters estimates of a survstan model
estimates(object, ...)
estimates(object, ...)
object |
an object of the class survstan. |
... |
further arguments passed to or from other methods. |
the parameters estimates of a given survstan model.
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) estimates(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) estimates(fit)
Computes the (generalized) Akaike An Information Criterion for a fitted parametric model.
## S3 method for class 'survstan' extractAIC(fit, scale, k = 2, ...)
## S3 method for class 'survstan' extractAIC(fit, scale, k = 2, ...)
fit |
a fitted model of the class survstan |
scale |
optional numeric specifying the scale parameter of the model. Currently only used in the "lm" method, where scale specifies the estimate of the error variance, and scale = 0 indicates that it is to be estimated by maximum likelihood. |
k |
numeric specifying the ‘weight’ of the equivalent degrees of freedom part in the AIC formula. |
... |
further arguments passed to or from other methods. |
the ANOVA table.
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) extractAIC(fit1) extractAIC(fit2) extractAIC(fit3)
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) extractAIC(fit1) extractAIC(fit2) extractAIC(fit3)
Data set from a clinical trial conducted by the Gastrointestinal Tumor Study Group (GTSG) in 1982. The data set refers to the survival times of patients with locally nonresectable gastric cancer. Patients were either treated with chemotherapy combined with radiation or chemotherapy alone.
A data frame with 90 rows and 3 variables:
time: survival times (in days)
status: failure indicator (1 - failure; 0 - otherwise)
trt: treatments (1 - chemotherapy + radiation; 0 - chemotherapy alone)
Fabio N. Demarqui [email protected]
Gastrointestinal Tumor Study Group. (1982) A Comparison of Combination Chemotherapy and Combined Modality Therapy for Locally Advanced Gastric Carcinoma. Cancer 49:1771-7.
Probability function, distribution function, quantile function and random generation for the distribution with parameters mu, sigma and varphi.
dggprentice(x, mu, sigma, varphi, log = FALSE) pggprentice(q, mu = 0, sigma = 1, varphi, lower.tail = TRUE, log.p = FALSE) qggprentice(p, mu = 0, sigma = 1, varphi, lower.tail = TRUE, log.p = FALSE) rggprentice(n, mu = 0, sigma = 1, varphi, ...)
dggprentice(x, mu, sigma, varphi, log = FALSE) pggprentice(q, mu = 0, sigma = 1, varphi, lower.tail = TRUE, log.p = FALSE) qggprentice(p, mu = 0, sigma = 1, varphi, lower.tail = TRUE, log.p = FALSE) rggprentice(n, mu = 0, sigma = 1, varphi, ...)
x |
vector of (non-negative integer) quantiles. |
mu |
location parameter of the distribution. |
sigma |
scale parameter of the distribution (sigma > 0). |
varphi |
shape parameter of the distribution. |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
... |
further arguments passed to other methods. |
Probability density function:
where , for
,
and
.
Distribution function:
where ,
is the distribution function of
a gamma distribution with shape parameter
and scale
parameter equals to 1, and
corresponds to the
distribution function of a lognormal distribution with location parameter
and scale parameter
.
dggprentice gives the (log) probability function, pggprentice gives the (log) distribution function, qggprentice gives the quantile function, and rggprentice generates random deviates.
Generic S3 method ggresiduals
ggresiduals(object, ...)
ggresiduals(object, ...)
object |
a fitted model object. |
... |
further arguments passed to or from other methods. |
Generic method to plot residuals of survival models.
the desired residual plot.
ggresiduals method for survstan models
## S3 method for class 'survstan' ggresiduals(object, type = c("coxsnell", "martingale", "deviance"), ...)
## S3 method for class 'survstan' ggresiduals(object, type = c("coxsnell", "martingale", "deviance"), ...)
object |
a fitted model object of the class survstan. |
type |
type of residuals used in the plot: coxsnell (default), martingale and deviance. |
... |
further arguments passed to or from other methods. |
This function produces residuals plots of Cox-Snell residuals, martingale residuals and deviance residuals.
the desired residual plot.
library(survstan) ovarian$rx <- as.factor(ovarian$rx) fit <- aftreg(Surv(futime, fustat) ~ age + rx, data = ovarian, baseline = "weibull", init = 0) ggresiduals(fit, type = "coxsnell") ggresiduals(fit, type = "martingale") ggresiduals(fit, type = "deviance")
library(survstan) ovarian$rx <- as.factor(ovarian$rx) fit <- aftreg(Surv(futime, fustat) ~ age + rx, data = ovarian, baseline = "weibull", init = 0) ggresiduals(fit, type = "coxsnell") ggresiduals(fit, type = "martingale") ggresiduals(fit, type = "deviance")
Probability function, distribution function, quantile function and random generation for the distribution with parameters alpha, gamma and kappa.
dggstacy(x, alpha, gamma, kappa, log = FALSE) pggstacy(q, alpha, gamma, kappa, log.p = FALSE, lower.tail = TRUE) qggstacy( p, alpha = 1, gamma = 1, kappa = 1, log.p = FALSE, lower.tail = TRUE, ... ) rggstacy(n, alpha = 1, gamma = 1, kappa = 1, ...)
dggstacy(x, alpha, gamma, kappa, log = FALSE) pggstacy(q, alpha, gamma, kappa, log.p = FALSE, lower.tail = TRUE) qggstacy( p, alpha = 1, gamma = 1, kappa = 1, log.p = FALSE, lower.tail = TRUE, ... ) rggstacy(n, alpha = 1, gamma = 1, kappa = 1, ...)
x |
vector of (non-negative integer) quantiles. |
alpha |
shape parameter of the distribution (alpha > 0). |
gamma |
scale parameter of the distribution (gamma > 0). |
kappa |
shape parameter of the distribution (kappa > 0). |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
... |
further arguments passed to other methods. |
n |
number of random values to return. |
Probability density function:
for ,
and
.
Distribution function:
where , and
corresponds to the distribution function of a gamma distribution with shape parameter
and scale parameter equals to 1.
dggstacy gives the (log) probability function, pggstacy gives the (log) distribution function, qggstacy gives the quantile function, and rggstacy generates random deviates.
Probability function, distribution function, quantile function and random generation for the distribution with parameters alpha and gamma.
dgompertz(x, alpha = 1, gamma = 1, log = FALSE, ...) pgompertz(q, alpha = 1, gamma = 1, lower.tail = TRUE, log.p = FALSE, ...) qgompertz(p, alpha = 1, gamma = 1, lower.tail = FALSE, log.p = FALSE, ...) rgompertz(n, alpha = 1, gamma = 1, ...)
dgompertz(x, alpha = 1, gamma = 1, log = FALSE, ...) pgompertz(q, alpha = 1, gamma = 1, lower.tail = TRUE, log.p = FALSE, ...) qgompertz(p, alpha = 1, gamma = 1, lower.tail = FALSE, log.p = FALSE, ...) rgompertz(n, alpha = 1, gamma = 1, ...)
x |
vector of (non-negative integer) quantiles. |
alpha |
shape parameter of the distribution (alpha > 0). |
gamma |
scale parameter of the distribution (gamma > 0). |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p). |
... |
further arguments passed to other methods. |
q |
vector of quantiles. |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
Probability density function:
for and
.
Distribution function:
for ,
and
.
dgompertz gives the (log) probability function, pgompertz gives the (log) distribution function, qgompertz gives the quantile function, and rgompertz generates random deviates.
Reconstructed IPASS clinical trial data reported in Argyropoulos and Unruh (2015). Although reconstructed, this data set preserves all features exhibited in references with full access to the observations from this clinical trial. The data base is related to the period of March 2006 to April 2008. The main purpose of the study is to compare the drug gefitinib against carboplatin/paclitaxel doublet chemotherapy as first line treatment, in terms of progression free survival (in months), to be applied to selected non-small-cell lung cancer (NSCLC) patients.
A data frame with 1217 rows and 3 variables:
time: progression free survival (in months)
status: failure indicator (1 - failure; 0 - otherwise)
arm: (1 - gefitinib; 0 - carboplatin/paclitaxel doublet chemotherapy)
Fabio N. Demarqui [email protected]
Argyropoulos, C. and Unruh, M. L. (2015). Analysis of time to event outcomes in randomized controlled trials by generalized additive models. PLOS One 10, 1-33.
Extracts the log-likelihood function for a fitted parametric model.
## S3 method for class 'survstan' logLik(object, ...)
## S3 method for class 'survstan' logLik(object, ...)
object |
a fitted model of the class survstan |
... |
further arguments passed to or from other methods. |
the log-likelihood value when a single model is passed to the function; otherwise, a data.frame with the log-likelihood values and the number of parameters is returned.
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) logLik(fit1, fit2, fit3)
library(survstan) fit1 <- aftreg(Surv(futime, fustat) ~ 1, data = ovarian, baseline = "weibull", init = 0) fit2 <- aftreg(Surv(futime, fustat) ~ rx, data = ovarian, baseline = "weibull", init = 0) fit3 <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) logLik(fit1, fit2, fit3)
Reconstruct the model matrix for a survstan model.
## S3 method for class 'survstan' model.matrix(object, ...)
## S3 method for class 'survstan' model.matrix(object, ...)
object |
an object of the class survstan. |
... |
further arguments passed to or from other methods. |
The model matrix (or matrices) for the fit.
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) model.matrix(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) model.matrix(fit)
Hazard and cumulative hazard functions of the PE distribution
hpexp(x, rho, rates) Hpexp(x, rho, rates)
hpexp(x, rho, rates) Hpexp(x, rho, rates)
x |
vector of time points. |
rho |
vector of time grid knots. |
rates |
vector of failure rates. |
hpexp gives the hazard function and Hpexp gives the cumulative hazard function of the PE distribution.
Probability function, distribution function, quantile function and random generation for the Piecewise Exponential (PE) distribution.
dpexp(x, rho, rates, log = FALSE) ppexp(q, rho, rates, lower.tail = TRUE, log.p = FALSE) qpexp(p, rho, rates, lower.tail = TRUE, log.p = FALSE) rpexp(n, rho, rates)
dpexp(x, rho, rates, log = FALSE) ppexp(q, rho, rates, lower.tail = TRUE, log.p = FALSE) qpexp(p, rho, rates, lower.tail = TRUE, log.p = FALSE) rpexp(n, rho, rates)
x |
vector of time points. |
rho |
vector of time grid knots. |
rates |
vector of failure rates. |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
dpexp gives the (log) probability function, ppexp gives the (log) distribution function, qpexp gives the quantile function, and rpexp generates random deviates.
n <- 10 rho <- c(0, 1, 3, 7, Inf) rates <- c(0.5, 4, 0.8, 0.1) x <- sort(rpexp(n, rho=rho, rates=rates)) Fx <- ppexp(x, rho, rates) y <- qpexp(Fx, rho, rates) # checking: x==y
n <- 10 rho <- c(0, 1, 3, 7, Inf) rates <- c(0.5, 4, 0.8, 0.1) x <- sort(rpexp(n, rho=rho, rates=rates)) Fx <- ppexp(x, rho, rates) y <- qpexp(Fx, rho, rates) # checking: x==y
Function to fit proportional hazards (PH) models.
phreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
phreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which function is called. |
baseline |
the chosen baseline distribution; options currently available are: exponential, weibull, lognormal, loglogistic and Birnbaum-Saunders (fatigue) distributions. |
dist |
alternative way to specify the baseline distribution (for compatibility with the |
init |
initial values specification (default value is 0); see the detailed documentation for |
... |
further arguments passed to other methods. |
phreg returns an object of class "phreg" containing the fitted model.
library(survstan) fit <- phreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
library(survstan) fit <- phreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
This function is used to allow the user to specify the piecewise exponential baseline with arbitrary time grid/number of intervals.
piecewise(rho = NULL, m = NULL)
piecewise(rho = NULL, m = NULL)
rho |
the specified time grid; default is NULL. |
m |
the number of intervals; default is NULL. |
a list with the baseline name, and the provided time grid and number of intervals.
Function to fit proportional odds (PO) models.
poreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
poreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which function is called. |
baseline |
the chosen baseline distribution; options currently available are: exponential, weibull, lognormal, loglogistic and Birnbaum-Saunders (fatigue) distributions. |
dist |
alternative way to specify the baseline distribution (for compatibility with the |
init |
initial values specification (default value is 0); see the detailed documentation for |
... |
further arguments passed to other methods. |
poreg returns an object of class "poreg" containing the fitted model.
library(survstan) fit <- poreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
library(survstan) fit <- poreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
Produces a printed summary of a fitted survstan model.
## S3 method for class 'summary.survstan' print(x, ...)
## S3 method for class 'summary.survstan' print(x, ...)
x |
an object of the class summary.survstan. |
... |
further arguments passed to or from other methods. |
No return value, called for side effects.
Rank a collection of survstan models
rank_models(formula, data, survreg, baseline, dist = NULL, ...)
rank_models(formula, data, survreg, baseline, dist = NULL, ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which function is called. |
survreg |
survival regression models to be fitted (AFT, AH, PH, PO, YP and EH). |
baseline |
baseline distributions to be fitted; options currently available are: exponential, weibull, lognormal, loglogistic and Birnbaum-Saunders (fatigue) distributions. |
dist |
alternative way to specify the baseline distributions (for compability with the |
... |
further arguments passed to other methods. |
a tibble containing the fitted models ranked according to their AICs.
library(survstan) library(dplyr) veteran <- veteran %>% mutate(across(c(trt, prior, celltype), as.factor)) fits <- rank_models( formula = Surv(time, status) ~ celltype+karno, data = veteran, survreg = c("aftreg", "ahreg", "phreg", "poreg", "ypreg", "ehreg"), baseline = c("exponential", "weibull", "lognormal", "loglogistic") )
library(survstan) library(dplyr) veteran <- veteran %>% mutate(across(c(trt, prior, celltype), as.factor)) fits <- rank_models( formula = Surv(time, status) ~ celltype+karno, data = veteran, survreg = c("aftreg", "ahreg", "phreg", "poreg", "ypreg", "ehreg"), baseline = c("exponential", "weibull", "lognormal", "loglogistic") )
residuals method for survstan models
## S3 method for class 'survstan' residuals(object, type = c("coxsnell", "martingale", "deviance"), ...)
## S3 method for class 'survstan' residuals(object, type = c("coxsnell", "martingale", "deviance"), ...)
object |
a fitted model object of the class survstan. |
type |
type of residuals desired: coxsnell (default), martingale and deviance. |
... |
further arguments passed to or from other methods. |
This function extracts the residuals, martingale residuals and deviance residuals of a survstan object.
a vector containing the desired residuals.
library(survstan) ovarian$rx <- as.factor(ovarian$rx) fit <- aftreg(Surv(futime, fustat) ~ age + rx, data = ovarian, baseline = "weibull", init = 0) residuals(fit, type = "coxsnell") residuals(fit, type = "martingale") residuals(fit, type = "deviance")
library(survstan) ovarian$rx <- as.factor(ovarian$rx) fit <- aftreg(Surv(futime, fustat) ~ age + rx, data = ovarian, baseline = "weibull", init = 0) residuals(fit, type = "coxsnell") residuals(fit, type = "martingale") residuals(fit, type = "deviance")
Generic S3 method se
se(object, ...)
se(object, ...)
object |
a fitted model object. |
... |
further arguments passed to or from other methods. |
the standard errors associated with a set of parameter estimators for a given model.
Estimated standard errors
## S3 method for class 'survstan' se(object, ...)
## S3 method for class 'survstan' se(object, ...)
object |
an object of the class survstan. |
... |
further arguments passed to or from other methods. |
a vector with the standard errors.
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) se(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) se(fit)
Summary for a survstan object
## S3 method for class 'survstan' summary(object, conf.level = 0.95, ...)
## S3 method for class 'survstan' summary(object, conf.level = 0.95, ...)
object |
the result of a call to summary.survstan |
conf.level |
the confidence level required. |
... |
further arguments passed to or from other methods. |
an object of the class summary.survstan containing a summary of the fitted model.
Computes the predicted survivor function for a phpe model.
## S3 method for class 'survstan' survfit(formula, newdata = NULL, ...)
## S3 method for class 'survstan' survfit(formula, newdata = NULL, ...)
formula |
an object of the class survstan |
newdata |
a data frame containing the set of explanatory variables; if NULL, a data.frame with the observed failure times and their corresponding estimated baseline survivals is returned. |
... |
further arguments passed to or from other methods. |
a data.frame containing the estimated survival probabilities.
library(survstan) library(ggplot2) data(ipass) ipass$arm <- as.factor(ipass$arm) fit <- ypreg(Surv(time, status)~arm, data=ipass, baseline = "weibull") summary(fit) newdata <- data.frame(arm=as.factor(0:1)) surv <- survfit(fit, newdata) ggplot(surv, aes(x=time, y=surv, color = arm)) + geom_line()
library(survstan) library(ggplot2) data(ipass) ipass$arm <- as.factor(ipass$arm) fit <- ypreg(Surv(time, status)~arm, data=ipass, baseline = "weibull") summary(fit) newdata <- data.frame(arm=as.factor(0:1)) surv <- survfit(fit, newdata) ggplot(surv, aes(x=time, y=surv, color = arm)) + geom_line()
Tidy a survstan object
## S3 method for class 'survstan' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
## S3 method for class 'survstan' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
x |
a fitted model object. |
conf.int |
Logical indicating whether or not to include a confidence interval in the tidied output. Defaults to FALSE. |
conf.level |
the confidence level required. |
... |
further arguments passed to or from other methods. |
Convert a fitted model into a tibble.
a tibble with a summary of the fit.
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") tidy(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") tidy(fit)
Time grid
time_grid(time, event, m = NULL)
time_grid(time, event, m = NULL)
time |
Vector of failure times |
event |
Vector of failure indicators |
m |
Optional. Number of intervals. If |
Time grid.
This function extracts and returns the variance-covariance matrix associated with the regression coefficients when the maximum likelihood estimation approach is used in the model fitting.
## S3 method for class 'survstan' vcov(object, all = FALSE, ...)
## S3 method for class 'survstan' vcov(object, all = FALSE, ...)
object |
an object of the class survstan. |
all |
logical; if FALSE (default), only covariance matrix associated with regression coefficients is returned; if TRUE, the full covariance matrix is returned. |
... |
further arguments passed to or from other methods. |
the variance-covariance matrix associated with the parameters estimators.
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) vcov(fit)
library(survstan) fit <- aftreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull", init = 0) vcov(fit)
Function to fit Yang and Prentice (YP) models.
ypreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
ypreg(formula, data, baseline = "weibull", dist = NULL, init = 0, ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which function is called. |
baseline |
the chosen baseline distribution; options currently available are: exponential, weibull, lognormal, loglogistic and Birnbaum-Saunders (fatigue) distributions. |
dist |
alternative way to specify the baseline distribution (for compatibility with the |
init |
initial values specification (default value is 0); see the detailed documentation for |
... |
further arguments passed to other methods. |
ypreg returns an object of class "ypreg" containing the fitted model.
library(survstan) fit <- ypreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)
library(survstan) fit <- ypreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, baseline = "weibull") summary(fit)