| Title: | Bernstein Polynomial Based Semiparametric Survival Analysis |
|---|---|
| Description: | A set of reliable routines to ease semiparametric survival regression modeling based on Bernstein polynomials. 'spsurv' includes proportional hazards, proportional odds and accelerated failure time frameworks for right-censored data. RV Panaro (2020) <arXiv:2003.10548>. |
| Authors: | Renato Panaro [aut, cre]
(<https://orcid.org/0000-0002-1903-2091>,
https://rvpanaro.github.io/), Fábio Demarqui [aut]
|
| Maintainer: | Renato Panaro <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.0 |
| Built: | 2026-06-11 10:32:23 UTC |
| Source: | https://github.com/cranhaven/cranhaven.r-universe.dev |
A set of flexible routines to allow semiparametric survival regression modeling based on Bernstein polynomial, including Bernstein based proportinal hazards model (BPPH), Bernstein polynomial based proportional odds model (BPPO) and Bernstein based accelerated failure time model (BPAFT) for right-censored data.
spbp fits semi-parametric models for time-to-event survival data.
Non-informative right-censoring assumption is available. Any user-defined Bernstein polynomial can
be user-defined using an arbitrary degree, i.e. highest basis polynomials order.
The framework takes advantage of fully likelihood methods since the polynomial parameters are used to estimate the baseline functions. Even so, this is said to be semi-parametric since this approach does not rely on any distribution. Unlike the Cox model, the BP based models provide smooth hazard and survival curve estimates.
none
Renato Valladares Panaro ([email protected]).
Panaro R.V. (2020). spsurv: An R package for semi-parametric survival analysis. arXiv preprint arXiv:2003.10548.
Demarqui, F. N., & Mayrink, V. D. (2019). A fully likelihood-based approach to model survival data with crossing survival curves. arXiv preprint arXiv:1910.02406.
Demarqui, F. N., Mayrink, V. D., & Ghosh, S. K. (2019). An Unified Semiparametric Approach to Model Lifetime Data with Crossing Survival Curves. arXiv preprint arXiv:1910.04475.
Osman, M., & Ghosh, S. K. (2012). Nonparametric regression models for right-censored data using Bernstein polynomials. Computational Statistics & Data Analysis, 56(3), 559-573.
Lorentz, G. G. (1953). Bernstein polynomials. American Mathematical Society.
Bernstein basis polynomials calculations
bp.basis(time, degree, tau = max(time))bp.basis(time, degree, tau = max(time))
time |
a vector of times. |
degree |
Bernstein polynomial degree |
tau |
must be greater than times maximum value observed. |
A list containing matrices b and B corresponding BP basis and corresponding tau value used to compute them.
Fits the BPAFT model to time-to-event data.
bpaft(formula, degree, data, approach = c("mle", "bayes"), ...)bpaft(formula, degree, data, approach = c("mle", "bayes"), ...)
formula |
a Surv object with time to event observations, right censoring status and explanatory terms. |
degree |
Bernstein polynomial degree. |
data |
a data.frame object. |
approach |
Bayesian or maximum likelihood estimation methods, default is approach = "mle". |
... |
further arguments passed to or from other methods |
An object of class 'spbp'.
spbp, bpph and bppo for other BP based models.
library("spsurv") data("veteran") fit <- bpaft(Surv(time, status) ~ karno + celltype, data = veteran) summary(fit)library("spsurv") data("veteran") fit <- bpaft(Surv(time, status) ~ karno + celltype, data = veteran) summary(fit)
Fits the BPPH model to time-to-event data.
bpph(formula, degree, data, approach = c("mle", "bayes"), ...)bpph(formula, degree, data, approach = c("mle", "bayes"), ...)
formula |
a Surv object with time to event observations, right censoring status and explanatory terms. |
degree |
Bernstein polynomial degree. |
data |
a data.frame object. |
approach |
Bayesian or maximum likelihood estimation methods, default is approach = "mle". |
... |
further arguments passed to or from other methods |
An object of class 'spbp'.
spbp, bppo and bpaft for other BP based models.
library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) summary(fit)library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) summary(fit)
Fits the BPPO model to time-to-event data.
bppo(formula, degree, data, approach = c("mle", "bayes"), ...)bppo(formula, degree, data, approach = c("mle", "bayes"), ...)
formula |
a Surv object with time-to-event observations, right censoring status and explanatory terms. |
degree |
Bernstein polynomial degree. |
data |
a data.frame object. |
approach |
Bayesian or maximum likelihood estimation methods, default is approach = "mle". |
... |
further arguments passed to or from other methods |
An object of class 'spbp'.
spbp, bpph and bpaft for other BP based models.
library("spsurv") data("veteran") fit <- bppo(Surv(time, status) ~ karno + celltype, data = veteran) summary(fit)library("spsurv") data("veteran") fit <- bppo(Surv(time, status) ~ karno + celltype, data = veteran) summary(fit)
Generic S3 method coef
coef(spbp, ...)coef(spbp, ...)
spbp |
a fitted model object |
... |
further arguments passed to or from other methods. |
the estimated regression coefficients
Estimated regression coefficients
## S3 method for class 'spbp' coef(spbp, ...)## S3 method for class 'spbp' coef(spbp, ...)
spbp |
an object of the class spbp |
... |
further arguments passed to or from other methods |
the estimated regression coefficients
Generic S3 method confint
confint(spbp, ...)confint(spbp, ...)
spbp |
a fitted model object |
... |
further arguments passed to or from other methods. |
the estimated regression coefficients
Confidence intervals for the regression coefficients
## S3 method for class 'spbp' confint(spbp, level = 0.95, ...)## S3 method for class 'spbp' confint(spbp, level = 0.95, ...)
spbp |
an object of the class spbp |
level |
the confidence level required |
... |
further arguments passed to or from other methods |
100(1-alpha) confidence intervals for the regression coefficients
Generic S3 method extract
extract(spbp, ...)extract(spbp, ...)
spbp |
a fitted model object |
... |
further arguments passed to or from other methods. |
extract the MCMC chain values of a Bayesian fit.
Extract samples from a fitted spbp model.
## S3 method for class 'spbp' extract(spbp, pars = c("beta", "gamma"), ...)## S3 method for class 'spbp' extract(spbp, pars = c("beta", "gamma"), ...)
spbp |
an object of class 'spbp' result of a |
pars |
parameters to be selected. |
... |
arguments inherent from |
see extract.
spbp, stan_dens.spbp, traceplot.spbp
library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) extract(fit)library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) extract(fit)
Random survival times generation for the weibull or log-logistic distributions with parameters 'scale' and 'shape'.
itsamp( n, beta = c(2, -1), event_scale = 10, censor_scale = 4, features = data.frame(x1 = rnorm(n, 0), x2 = rnorm(n, 0)), shape = 2, model = c("ph", "po", "aft"), dist = c("weibull", "llogis"), censor = TRUE )itsamp( n, beta = c(2, -1), event_scale = 10, censor_scale = 4, features = data.frame(x1 = rnorm(n, 0), x2 = rnorm(n, 0)), shape = 2, model = c("ph", "po", "aft"), dist = c("weibull", "llogis"), censor = TRUE )
n |
integer; sample size |
beta |
vector of regression coefficients |
event_scale, censor_scale
|
event and censoring scale parameters |
features |
matrix of features (columns) |
shape |
event and censoring distribution shape |
model |
either "ph" (default) or "aft" for weibull and "po" or "aft" for log-logistic distribution |
dist |
"weibull" or "llogis" |
censor |
logical; if 'TRUE', censoring is required, that is mean(status) > 0 |
sim_surv returns weibull (log-logistic) randomly generated survival times. According to Collett (2003), the accelerated failure time model encompasses a wide variety of parametric models, including weibull and log-logistic models.
data.frame of 'ncol(x) +2' columns in which the survival times are the response variable denoted by 'y', 'status' indicates failure (0 = failure) and the features are appended to the next columns.
rows <- 200 categorical <- rbinom(rows, size = 3, prob = .5) x <- data.frame(numerical = rnorm(rows), cat0 = as.numeric(categorical == 0), cat1 = as.numeric(categorical == 1), cat2 = as.numeric(categorical == 2), cat3 = as.numeric(categorical == 3)) newdata <- itsamp(n = rows, beta = c(1, -2, .5, .1, 1), features = x, model = 'ph', dist = 'weibull')rows <- 200 categorical <- rbinom(rows, size = 3, prob = .5) x <- data.frame(numerical = rnorm(rows), cat0 = as.numeric(categorical == 0), cat1 = as.numeric(categorical == 1), cat2 = as.numeric(categorical == 2), cat3 = as.numeric(categorical == 3)) newdata <- itsamp(n = rows, beta = c(1, -2, .5, .1, 1), features = x, model = 'ph', dist = 'weibull')
Calculate the posterior mode
mode(ext)mode(ext)
ext |
rstan extracted sample. |
A vector containing the posterior mode of each sample.
Model.matrix of a fitted spbp model.
## S3 method for class 'spbp' model.matrix( object, data = eval(object$call$data, envir = parent.frame()), ... )## S3 method for class 'spbp' model.matrix( object, data = eval(object$call$data, envir = parent.frame()), ... )
object |
an object of class 'spbp', see |
data |
data.frame object. |
... |
arguments inherent from |
The explanatory variables matrix.
library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) model.matrix(fit)library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) model.matrix(fit)
Bernstein Polynomial Based Regression Object Print
## S3 method for class 'spbp' print( x, digits = max(getOption("digits") - 4, 3), signif.stars = getOption("show.signif.stars"), ... )## S3 method for class 'spbp' print( x, digits = max(getOption("digits") - 4, 3), signif.stars = getOption("show.signif.stars"), ... )
x |
an object of class spbp |
digits |
number of digits to display |
signif.stars |
see |
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object Summary BPAFT Bayes
## S3 method for class 'summary.bpaft.bayes' print(...)## S3 method for class 'summary.bpaft.bayes' print(...)
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object Summary BPAFT MLE
## S3 method for class 'summary.bpaft.mle' print(...)## S3 method for class 'summary.bpaft.mle' print(...)
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object Summary BPPH Bayes
## S3 method for class 'summary.bpph.bayes' print(...)## S3 method for class 'summary.bpph.bayes' print(...)
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object Summary BPPH MLE
## S3 method for class 'summary.bpph.mle' print(...)## S3 method for class 'summary.bpph.mle' print(...)
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object Summary BPPO Bayes
## S3 method for class 'summary.bppo.bayes' print(...)## S3 method for class 'summary.bppo.bayes' print(...)
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object BPPO MLE
## S3 method for class 'summary.bppo.mle' print(...)## S3 method for class 'summary.bppo.mle' print(...)
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object Summary Bayes
## S3 method for class 'summary.spbp.bayes' print(x, digits = max(getOption("digits") - 4, 3), ...)## S3 method for class 'summary.spbp.bayes' print(x, digits = max(getOption("digits") - 4, 3), ...)
x |
a summary.spbp.bayes object |
digits |
number of digits to display. |
... |
further arguments passed to or from other methods |
none
Bernstein Polynomial Based Regression Object Summary MLE
## S3 method for class 'summary.spbp.mle' print( x, digits = max(getOption("digits") - 4, 3), signif.stars = getOption("show.signif.stars"), ... )## S3 method for class 'summary.spbp.mle' print( x, digits = max(getOption("digits") - 4, 3), signif.stars = getOption("show.signif.stars"), ... )
x |
a summary.spbp.mle object |
digits |
number of digits to display. |
signif.stars |
see |
... |
further arguments passed to or from other methods |
none
Residuals for a fitted spbp model.
## S3 method for class 'spbp' residuals(object, type = c("cox-snell"), ...)## S3 method for class 'spbp' residuals(object, type = c("cox-snell"), ...)
object |
an object of class 'spbp' result of a |
type |
type of residuals, default is "cox-snell" |
... |
further arguments passed to or from other methods |
spbp.
library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) residuals(fit)library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) residuals(fit)
Semiparametric Survival Analysis Using Bernstein Polynomial
spbp(formula, ...)spbp(formula, ...)
formula |
a Surv object with time to event, status and explanatory terms. |
... |
Arguments passed to 'rstan::sampling' (e.g. iter, chains) or 'rstan::optimizing'. |
Fits Bernstein Polynomial based Proportional regression to survival data.
An object of class 'spbp'.
spbp.default, bpph, bppo, bpaft, https://mc-stan.org/users/documentation/
library("spsurv") data("veteran") ## imports from survival package fit_mle <- spbp(Surv(time, status) ~ karno + factor(celltype), data = veteran, model = "po") summary(fit_mle) fit_bayes <- spbp(Surv(time, status) ~ karno + factor(celltype), data = veteran, model = "po", approach = "bayes", cores = 1, iter = 300, chains = 1, priors = list(beta = c("normal(0,4)"), gamma = "lognormal(0,4)")) summary(fit_bayes)library("spsurv") data("veteran") ## imports from survival package fit_mle <- spbp(Surv(time, status) ~ karno + factor(celltype), data = veteran, model = "po") summary(fit_mle) fit_bayes <- spbp(Surv(time, status) ~ karno + factor(celltype), data = veteran, model = "po", approach = "bayes", cores = 1, iter = 300, chains = 1, priors = list(beta = c("normal(0,4)"), gamma = "lognormal(0,4)")) summary(fit_bayes)
spbp: The BP Based Semiparametric Survival Analysis Function
## Default S3 method: spbp( formula, degree, data, approach = c("mle", "bayes"), model = c("ph", "po", "aft"), priors = list(beta = c("normal(0,4)"), gamma = "lognormal(0,10)"), scale = TRUE, cores = parallel::detectCores(), ... )## Default S3 method: spbp( formula, degree, data, approach = c("mle", "bayes"), model = c("ph", "po", "aft"), priors = list(beta = c("normal(0,4)"), gamma = "lognormal(0,10)"), scale = TRUE, cores = parallel::detectCores(), ... )
formula |
a Surv object with time to event, status and explanatory terms |
degree |
Bernstein Polynomial degree |
data |
a data.frame object |
approach |
Bayesian or Maximum Likelihood estimation methods, default is approach = "bayes" |
model |
Proportional Hazards or Proportional Odds BP based regression, default is model = "ph" |
priors |
prior settings for the Bayesian approach; 'normal' or 'cauchy' for beta; 'gamma', 'inv_gamma' or 'lognormal' for gamma (BP coefficients) |
scale |
logical; indicates whether to center and scale the data |
cores |
number of core threads to use |
... |
further arguments passed to or from other methods |
An object of class spbp
Generic S3 method extract
stan_dens(spbp, ...)stan_dens(spbp, ...)
spbp |
a fitted model object |
... |
further arguments passed to or from other methods. |
the density plot of a MCMC chain.
Posterior density of samples from a fitted spbp model.
## S3 method for class 'spbp' stan_dens(spbp, pars = c("beta", "gamma"), ...)## S3 method for class 'spbp' stan_dens(spbp, pars = c("beta", "gamma"), ...)
spbp |
the result of a |
pars |
parameters to be selected. |
... |
arguments inherent from |
see stan_dens.
spbp, traceplot.spbp, extract.spbp
library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) stan_dens(fit)library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) stan_dens(fit)
Bernstein Polynomial Based Regression Object Summary
## S3 method for class 'spbp' summary(object, interval = 0.95, ...)## S3 method for class 'spbp' summary(object, interval = 0.95, ...)
object |
an object of class spbp |
interval |
interval coverage (confidence or credibility) |
... |
further arguments passed to or from other methods |
An object of class analogous to for e.g. 'summary.bppo.bayes'.
Generic S3 method vcov
survivor(spbp, ...)survivor(spbp, ...)
spbp |
an object of class spbp |
... |
further arguments passed to or from other methods |
estimates survival for each dataset individual (line). Spbp Object Observed Survival
Generic S3 method traceplot
traceplot(spbp, ...)traceplot(spbp, ...)
spbp |
a fitted model object |
... |
further arguments passed to or from other methods. |
the traceplot of a MCMC chain.
Traceplot of a Bayesian fit spbp.
## S3 method for class 'spbp' traceplot(spbp, pars = c("beta", "gamma"), ...)## S3 method for class 'spbp' traceplot(spbp, pars = c("beta", "gamma"), ...)
spbp |
an object of class 'spbp' result of a |
pars |
parameters to be selected. |
... |
arguments inherent from |
see traceplot.
spbp, stan_dens.spbp, extract.spbp
library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) traceplot(fit)library("spsurv") data("veteran") fit <- bpph(Surv(time, status) ~ karno + factor(celltype), data = veteran) traceplot(fit)
Generic S3 method vcov
vcov(spbp, ...)vcov(spbp, ...)
spbp |
a fitted model object |
... |
further arguments passed to or from other methods. |
the variance-covariance matrix associated the regression coefficients.
Covariance of the regression coefficients
## S3 method for class 'spbp' vcov(spbp, ...)## S3 method for class 'spbp' vcov(spbp, ...)
spbp |
an object of the class spbp |
... |
further arguments passed to or from other methods. |
the variance-covariance matrix associated with the regression coefficients.