Title: | Flexible Relative Survival Analysis |
---|---|
Description: | Package for parametric relative survival analyses. It allows to model non-linear and non-proportional effects and both non proportional and non linear effects, using splines (B-spline and truncated power basis), Weighted Cumulative Index of Exposure effect, with correction model for the life table. Both non proportional and non linear effects are described in Remontet, L. et al. (2007) <doi:10.1002/sim.2656> and Mahboubi, A. et al. (2011) <doi:10.1002/sim.4208>. |
Authors: | Isabelle Clerc-Urmès [aut], Michel Grzebyk [aut, cre], Guy Hédelin [ctb], CENSUR working survival group [ctb] |
Maintainer: | Michel Grzebyk <[email protected]> |
License: | GPL (>= 2.0) |
Version: | 2.0.18 |
Built: | 2024-11-06 03:26:49 UTC |
Source: | https://github.com/cran/flexrsurv |
flexrsurv
is a package for parametric relative survival analyses. The package implements non-linear,
non-proportional effects and both non proportional and non linear effects, using splines (B-spline and truncated power basis),
Weighted Cumulative Index of Exposure effect, with correction model for the life table.
Both non proportional and non linear effects are described in Remontet et al. (2007) doi:10.1002/sim.2656 and
Mahboubi et al. (2011) doi:10.1002/sim.4208.
The main function is flexrsurv()
Michel Grzebyk and Isabelle Clerc-Urmès, with contributions from the CENSUR working survival group.
Maintainer: <[email protected]>
Mahboubi, A., M. Abrahamowicz, et al. (2011). "Flexible modeling of
the effects of continuous prognostic factors in relative survival." Stat
Med 30(12): 1351-1365. doi:10.1002/sim.4208
Remontet, L., N. Bossard, et al. (2007). "An overall strategy based
on regression models to estimate relative survival and model the effects
of prognostic factors in cancer survival studies." Stat Med 26(10):
2214-2228. doi:10.1002/sim.2656
flexrsurv
is used to fit relative survival regression model.
Time dependent variables, non-proportionnal (time dependent) effects,
non-linear effects are implemented using Splines (B-spline and truncated power basis).
Simultaneously non linear and non proportional effects are implemented
using approaches developed by Remontet et al.(2007) and Mahboubi et al. (2011).
flexrsurv(formula=formula(data), data=parent.frame(), knots.Bh, degree.Bh=3, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate=NULL, weights=NULL, na.action=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "BANDS"), npoints=20, stept=NULL, bands=NULL, init=NULL, initbyglm=TRUE, initbands=bands, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), control.glm=list(epsilon=1e-8, maxit=100, trace=FALSE, epsilon.glm=1e-1, maxit.glm=25), vartype = c("oim", "opg", "none"), debug=FALSE ) flexrsurv.ll(formula=formula(data), data=parent.frame(), knots.Bh=NULL, degree.Bh=3, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate=NULL, weights=NULL, na.action=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "GLM", "BANDS"), npoints=20, stept=NULL, bands=NULL, init=NULL, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), vartype = c("oim", "opg", "none"), debug=FALSE )
flexrsurv(formula=formula(data), data=parent.frame(), knots.Bh, degree.Bh=3, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate=NULL, weights=NULL, na.action=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "BANDS"), npoints=20, stept=NULL, bands=NULL, init=NULL, initbyglm=TRUE, initbands=bands, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), control.glm=list(epsilon=1e-8, maxit=100, trace=FALSE, epsilon.glm=1e-1, maxit.glm=25), vartype = c("oim", "opg", "none"), debug=FALSE ) flexrsurv.ll(formula=formula(data), data=parent.frame(), knots.Bh=NULL, degree.Bh=3, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate=NULL, weights=NULL, na.action=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "GLM", "BANDS"), npoints=20, stept=NULL, bands=NULL, init=NULL, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), vartype = c("oim", "opg", "none"), debug=FALSE )
formula |
a formula object, with the response on the left of a ~ operator, and the terms on the
right. The response must be a survival object as returned by the |
data |
a data.frame in which to interpret the variables named in the formula. |
knots.Bh |
the internal breakpoints that define the spline used to estimate the baseline hazard. Typical values are the mean or median for one knot, quantiles for more knots. |
degree.Bh |
degree of the piecewise polynomial of the baseline hazard. Default is 3 for cubic splines. |
Spline |
a character string specifying the type of spline basis. "b-spline" for B-spline basis, "tp-spline" for truncated power basis and "tpi-spline" for monotone (increasing) truncated power basis. |
log.Bh |
logical value: if TRUE, an additional basis equal to log(time) is added to the spline bases of time. |
bhlink |
logical value: if TRUE, log of baseline hazard is modelled, if FALSE, the baseline hazard is out of the log. |
Min_T |
minimum of time period which is analysed. Default is |
Max_T |
maximum of time period which is analysed. Default is |
model |
character string specifying the type of model for both non-proportionnal and non linear effects.
The model |
rate |
an optional vector of the background rate for a relevant comparative population to be used in the fitting process.
Should be a numeric vector (for relative survival model).
|
weights |
an optional vector of weights to be used in the fitting process. Should be NULL or a numeric vector. If not null, the total likelihood is the weighted sum of individual likelihood. |
na.action |
a missing-data filter function, applied to the model.frame, after any subset argument has been used. Default is options()$na.action. |
int_meth |
character string specifying the the numerical integration method. Possible values are "GL" for Gauss-Legendre quadrature, "CAV_SIM" for Cavalieri-Simpson's rule, "SIM_3_8" for the Simpson's 3/8 rule, "BOOLE" for the Boole's rule, or "BANDS" for the midpoint rule with specified bands. |
npoints |
number of points used in the Gauss-Legendre quadrature (when |
stept |
scalar value of the time-step in numerical integration. It is required only when |
bands |
bands used to split data in the numerical integration when |
init |
starting values of the parameters. |
initbyglm |
a logical value indicating indicating how are found or refined init values. If TRUE, the fitting method described in Remontet
et al.(2007) is ued to find or refine starting values. This may speedup the fit. If FALSE, the maximisation of the likelihood
starts at values given in |
initbands |
bands used to split data when |
optim.control |
a list of control parameters passed to the |
optim_meth |
method to be used to optimize the likelihood.
See |
control.glm |
a list of control parameters passed to the |
vartype |
character string specifying the type of variance matrix computed by |
debug |
control the volum of intermediate output |
A full description of the additive and the multiplicative both non-linear and non-proportional models is given respectively in Remontet (2007) and Mahboubi (2011).
flexrsurv.ll
is the workhorse function: it is not normally called
directly.
flexrsurv
returns an object of class "flexrsurv"
.
An object of class "flexrsurv"
is a list containing at least the following components:
coefficients |
a named vector of coefficients |
loglik |
the log-likelihood |
var |
estimated covariance matrix for the estimated coefficients |
informationMatrix |
estimated information matrix |
bhlink |
the linkk of baseline hazard:
if |
init |
vector of the starting values supplied |
converged |
logical, Was the optimlizer algorithm judged to have converged? |
linear.predictors |
the linear fit on link scale (not including the baseline hazard term if |
fitted.values |
the estimated value of the hazard rate at each event time, obtained by transforming the linear predictors by the inverse of the link function |
cumulative.hazard |
the estimated value of the cumulative hazard in the time interval |
call |
the matched call |
formula |
the formula supplied |
terms |
the |
data |
the |
rate |
the rate vector used |
time |
the time vector used |
workingformula |
the formula used by the fitter |
optim.control |
the value of the |
control.glm |
the value of the |
method |
the name of the fitter function used |
Mahboubi, A., M. Abrahamowicz, et al. (2011). "Flexible modeling of the effects of continuous prognostic factors in relative survival." Stat Med 30(12): 1351-1365. doi:10.1002/sim.4208
Remontet, L., N. Bossard, et al. (2007). "An overall strategy based on regression models to estimate relative survival and model the effects of prognostic factors in cancer survival studies." Stat Med 26(10): 2214-2228. doi:10.1002/sim.2656
print.flexrsurv
,
summary.flexrsurv
,
logLik.flexrsurv
,
predict.flexrsurv
,
NPH
,
NLL
, and
NPHNLL
.
if (requireNamespace("relsurv", quietly = TRUE)) { # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effect of age fit <- flexrsurv(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit) # fit a relative survival model with a non linear & non proportional effect of age fit2 <- flexrsurv(Surv(time,cens)~sex01+NPHNLL(age, time, Knots=60, Degree=3, Knots.t = 1850, Degree.t = 3), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Spline = "b-spline", initbyglm=TRUE, int_meth= "BOOLE", step=50 ) summary(fit2, correlation=TRUE) }
if (requireNamespace("relsurv", quietly = TRUE)) { # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effect of age fit <- flexrsurv(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit) # fit a relative survival model with a non linear & non proportional effect of age fit2 <- flexrsurv(Surv(time,cens)~sex01+NPHNLL(age, time, Knots=60, Degree=3, Knots.t = 1850, Degree.t = 3), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Spline = "b-spline", initbyglm=TRUE, int_meth= "BOOLE", step=50 ) summary(fit2, correlation=TRUE) }
flexrsurvclt
is used to fit relative survival regression model.
transition package.
flexrsurvclt(formula=formula(data), formula.table=NULL, data=parent.frame(), Id, baselinehazard=TRUE, firstWCEIadditive=FALSE, knots.Bh, degree.Bh=3, intercept.Bh=TRUE, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate, logit_start, logit_end, logit_start_byperiod = NULL, logit_end_byperiod = NULL, weights_byperiod = NULL, Id_byperiod = NULL, contrasts.table = NULL, knots.table=c(-2.5,0,2.5), degree.table=3, Spline.table=c("restricted B-splines"), Spline.CLT=R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), model_correction = c("cohort", "period"), weights=NULL, na.action=NULL, datacontrol=NULL, Idcontrol, ratecontrol, logit_startcontrol, logit_endcontrol, logit_start_byperiodcontrol = NULL, logit_end_byperiodcontrol = NULL, weights_byperiodcontrol = NULL, Id_byperiodcontrol = NULL, weightscontrol=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "GLM", "BANDS"), bands=NULL, npoints=20, stept=NULL, init=NULL, initbyglm=TRUE, initbands=bands, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), Coptim.control=list(), lower = -Inf, upper = Inf, control.glm=list(epsilon=1e-8, maxit=100, trace=FALSE, epsilon.glm=.1, maxit.glm=25), vartype = c("oim", "opg", "none"), varmethod = c("optim", "numDeriv.hessian", "numDeriv.jacobian"), numDeriv.method.args=list(eps=5e-7, d=0.001, zero.tol=sqrt(.Machine$double.eps/7e-4), r=4, v=2), debug=FALSE ) flexrsurvclt.ll(formula=formula(data), formula.table=NULL, data=parent.frame(), Id, baselinehazard=TRUE, firstWCEIadditive=FALSE, knots.Bh, degree.Bh=3, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), intercept.Bh=TRUE, Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate, logit_start, logit_end, logit_start_byperiod = NULL, logit_end_byperiod = NULL, weights_byperiod = NULL, Id_byperiod = NULL, contrasts.table = NULL, knots.table=c(-2.5,0,2.5), degree.table=3, Spline.table=c("restricted B-splines"), Spline.CLT=R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), model_correction = c("cohort", "period"), weights=NULL, na.action=NULL, datacontrol=NULL, Idcontrol, ratecontrol, logit_startcontrol, logit_endcontrol, logit_start_byperiodcontrol = NULL, logit_end_byperiodcontrol = NULL, weights_byperiodcontrol = NULL, Id_byperiodcontrol = NULL, weightscontrol=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "GLM", "BANDS"), bands=NULL, npoints=20, stept=NULL, init=NULL, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), Coptim.control= list(), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), lower = -Inf, upper = Inf, vartype = c("oim", "opg", "none"), varmethod = c("optim", "numDeriv.hessian", "numDeriv.jacobian"), numDeriv.method.args=list(eps=5e-7, d=0.001, zero.tol=sqrt(.Machine$double.eps/7e-4), r=4, v=2), debug=FALSE )
flexrsurvclt(formula=formula(data), formula.table=NULL, data=parent.frame(), Id, baselinehazard=TRUE, firstWCEIadditive=FALSE, knots.Bh, degree.Bh=3, intercept.Bh=TRUE, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate, logit_start, logit_end, logit_start_byperiod = NULL, logit_end_byperiod = NULL, weights_byperiod = NULL, Id_byperiod = NULL, contrasts.table = NULL, knots.table=c(-2.5,0,2.5), degree.table=3, Spline.table=c("restricted B-splines"), Spline.CLT=R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), model_correction = c("cohort", "period"), weights=NULL, na.action=NULL, datacontrol=NULL, Idcontrol, ratecontrol, logit_startcontrol, logit_endcontrol, logit_start_byperiodcontrol = NULL, logit_end_byperiodcontrol = NULL, weights_byperiodcontrol = NULL, Id_byperiodcontrol = NULL, weightscontrol=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "GLM", "BANDS"), bands=NULL, npoints=20, stept=NULL, init=NULL, initbyglm=TRUE, initbands=bands, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), Coptim.control=list(), lower = -Inf, upper = Inf, control.glm=list(epsilon=1e-8, maxit=100, trace=FALSE, epsilon.glm=.1, maxit.glm=25), vartype = c("oim", "opg", "none"), varmethod = c("optim", "numDeriv.hessian", "numDeriv.jacobian"), numDeriv.method.args=list(eps=5e-7, d=0.001, zero.tol=sqrt(.Machine$double.eps/7e-4), r=4, v=2), debug=FALSE ) flexrsurvclt.ll(formula=formula(data), formula.table=NULL, data=parent.frame(), Id, baselinehazard=TRUE, firstWCEIadditive=FALSE, knots.Bh, degree.Bh=3, Spline=c("b-spline", "tp-spline", "tpi-spline"), log.Bh=FALSE, bhlink=c("log", "identity"), intercept.Bh=TRUE, Min_T=0, Max_T=NULL, model=c("additive","multiplicative"), rate, logit_start, logit_end, logit_start_byperiod = NULL, logit_end_byperiod = NULL, weights_byperiod = NULL, Id_byperiod = NULL, contrasts.table = NULL, knots.table=c(-2.5,0,2.5), degree.table=3, Spline.table=c("restricted B-splines"), Spline.CLT=R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), model_correction = c("cohort", "period"), weights=NULL, na.action=NULL, datacontrol=NULL, Idcontrol, ratecontrol, logit_startcontrol, logit_endcontrol, logit_start_byperiodcontrol = NULL, logit_end_byperiodcontrol = NULL, weights_byperiodcontrol = NULL, Id_byperiodcontrol = NULL, weightscontrol=NULL, int_meth=c("GL", "CAV_SIM", "SIM_3_8", "BOOLE", "GLM", "BANDS"), bands=NULL, npoints=20, stept=NULL, init=NULL, optim.control=list(trace=100, REPORT=1, fnscale=-1, maxit=25), Coptim.control= list(), optim_meth=c("BFGS", "CG", "Nelder-Mead", "L-BFGS-B", "SANN", "Brent"), lower = -Inf, upper = Inf, vartype = c("oim", "opg", "none"), varmethod = c("optim", "numDeriv.hessian", "numDeriv.jacobian"), numDeriv.method.args=list(eps=5e-7, d=0.001, zero.tol=sqrt(.Machine$double.eps/7e-4), r=4, v=2), debug=FALSE )
formula |
a formula object, with the response on the left of a ~ operator, and the terms on the
right. The response must be a survival object as returned by the |
formula.table |
a formula object, with empty left hand side, and the terms on the right. This is the formula of the proportional part of the correction model for the table table |
data |
a data.frame in which to interpret the variables named in the formulas. |
Id |
vector whose unique values defines the Ids of the subjects. |
baselinehazard |
if FALSE, no baseline hazard in the model |
firstWCEIadditive |
if TRUE, the first WCEI term in the formula is considered as the baseline |
knots.Bh |
the internal breakpoints that define the spline used to estimate the baseline hazard. Typical values are the mean or median for one knot, quantiles for more knots. |
degree.Bh |
degree of the piecewise polynomial of the baseline hazard. Default is 3 for cubic splines. |
intercept.Bh |
TRUE if the first bases is included in the baseline hazard. Default is TRUE. |
Spline |
a character string specifying the type of spline basis. "b-spline" for B-spline basis, "tp-spline" for truncated power basis and "tpi-spline" for monotone (increasing) truncated power basis. |
log.Bh |
logical value: if TRUE, an additional basis equal to log(time) is added to the spline bases of time. |
bhlink |
character string specifying the link function of the baseline hazard:
Default is |
Min_T |
minimum of time period which is analysed. Default is |
Max_T |
maximum of time period which is analysed. Default is |
model |
character string specifying the type of model for both non-proportional and non linear effects.
The model |
rate |
a vector of the background rate for a relevant comparative population to be used in the fitting process.
Should be a numeric vector (for relative survival model).
|
logit_start |
a vector of the logit of the cumulative hazard at the start of the
interval in the life table.
|
logit_end |
a vector of the logit of the cumulative hazard at the end of the
interval in the life table.
|
logit_start_byperiod , logit_end_byperiod , weights_byperiod , Id_byperiod
|
A REMPLIR |
knots.table |
the internal breakpoints on the logit scale that define the knots of the spline used to estimate the correction model of the life table. |
degree.table |
degree of the piecewise polynomial of the spline used to estimate the correction model of the life table. Default is 3 for cubic splines. |
contrasts.table |
an optional list. See the |
Spline.table |
a character string specifying the type of spline basis of the the correction model of the life table. In this version, only "restricted B-splines" is available. "restricted B-splines" are B-spline basis with linear extrapolation + 2nd derivative at boundaries == 0. |
Spline.CLT |
a S4 object with method deriv() and evaluate().
The spline basis of the correction of the life table can be specified either by the parameters ( |
model_correction |
character string specifying A COMPLETER.
|
weights |
an optional vector of weights to be used in the fitting process. Should be NULL or a numeric vector. If not null, the total likelihood is the weighted sum of individual likelihood. |
na.action |
a missing-data filter function, applied to the model.frame. If |
datacontrol |
a data.frame in which to interpret the variables named in the formula for the control group. |
Idcontrol , ratecontrol , logit_startcontrol , logit_endcontrol , weightscontrol
|
Id, rate, logit of the cumulative hazard at the start and the end of the intervalle in the life table, and weights for the control group |
logit_start_byperiodcontrol , logit_end_byperiodcontrol , weights_byperiodcontrol , Id_byperiodcontrol
|
A REMPLIR |
int_meth |
character string specifying the the numerical integration method. Possible values are "GL" for Gauss-Legendre method, "CAV_SIM" for Cavalieri-Simpson's rule, "SIM_3_8" for the Simpson's 3/8 rule, "BOOLE" for the Boole's rule, or "BANDS" for the midpoint rule with specified bands. |
bands |
bands used to split data in the numerical integration when |
npoints |
number of points used in the numerical integration when |
stept |
scalar value of the time-step in numerical integration. It is required only when |
init |
starting values of the parameters. |
initbyglm |
a logical value indicating indicating how are found or refined init values. If TRUE, the fitting method described in Remontet et al.(2007)
is ued to find or refine starting values. This may speedup the fit. If FALSE, the maximisation of the likelihood starts at values
given in |
initbands |
bands used to split data when |
optim.control |
a list of control parameters passed to the |
optim_meth |
method to be used to optimize the likelihood.
See |
Coptim.control |
a list of control parameters passed to the |
lower , upper
|
Bounds on the variables for the "L-BFGS-B" method, or bounds in which to search for method "Brent".
See |
control.glm |
a list of control parameters passed to the |
vartype |
character string specifying the type of variance matrix computed by |
varmethod |
character string specifying the method to compute the hessian matrix when |
numDeriv.method.args |
arguments passed to |
debug |
control the volum of intermediate output |
A full description of the additive and the multiplicative both non-linear and non-proportional models is given respectively in Remontet (2007) and Mahboubi (2011).
flexrsurv.ll
is the workhorse function: it is not normally called
directly.
flexrsurv
returns an object of class "flexrsurv"
.
An object of class "flexrsurv"
is a list containing at least the following components:
coefficients |
a named vector of coefficients |
loglik |
the log-likelihood |
var |
estimated covariance matrix for the estimated coefficients |
informationMatrix |
estimated information matrix |
bhlink |
the linkk of baseline hazard:
if |
init |
vector of the starting values supplied |
converged |
logical, Was the optimlizer algorithm judged to have converged? |
linear.predictors |
the linear fit on link scale (not including the baseline hazard term if |
fitted.values |
the estimated value of the hazard rate at each event time, obtained by transforming the linear predictors by the inverse of the link function |
cumulative.hazard |
the estimated value of the cumulative hazard in the time interval |
call |
the matched call |
formula |
the formula supplied |
terms |
the |
data |
the |
rate |
the rate vector used |
time |
the time vector used |
workingformula |
the formula used by the fitter |
optim.control |
the value of the |
control.glm |
the value of the |
method |
the name of the fitter function used |
Mahboubi, A., M. Abrahamowicz, et al. (2011). "Flexible modeling of the effects of continuous prognostic factors in relative survival." Stat Med 30(12): 1351-1365. doi:10.1002/sim.4208
Remontet, L., N. Bossard, et al. (2007). "An overall strategy based on regression models to estimate relative survival and model the effects of prognostic factors in cancer survival studies." Stat Med 26(10): 2214-2228. doi:10.1002/sim.2656
print.flexrsurv
,
summary.flexrsurv
,
logLik.flexrsurv
,
predict.flexrsurv
,
NPH
,
NLL
, and
NPHNLL
.
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # get the logit_start and logit_end # logit start at age 18 tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.25 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter" ) rdata$slorate <- HH$poprate rdata$logit_start <- log(exp(HH$cumrateenter)-1) rdata$logit_end <- log(exp(HH$cumrateend)-1) rdata$Id <- 1:dim(rdata)[1] # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effect of age # without correction of life table # partial likelihood fit00 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit00) # fit a relative survival model with a non linear effect of age # without correction of life table # full likelihood fit0 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit0) # fit a relative survival model with a non linear effect of age # with correction of life table # full likelihood fit1 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", Spline.CLT=flexrsurv:::R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit1) print(coef(fit1)) # fit a relative survival model with a non linear effect of age # with correction of life table, strabified by sex # full likelihood fit2 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), formula.table= ~sex, rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", Spline.CLT=flexrsurv:::R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit2) AIC(fit0, fit1, fit2) }
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # get the logit_start and logit_end # logit start at age 18 tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.25 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter" ) rdata$slorate <- HH$poprate rdata$logit_start <- log(exp(HH$cumrateenter)-1) rdata$logit_end <- log(exp(HH$cumrateend)-1) rdata$Id <- 1:dim(rdata)[1] # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effect of age # without correction of life table # partial likelihood fit00 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit00) # fit a relative survival model with a non linear effect of age # without correction of life table # full likelihood fit0 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit0) # fit a relative survival model with a non linear effect of age # with correction of life table # full likelihood fit1 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", Spline.CLT=flexrsurv:::R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit1) print(coef(fit1)) # fit a relative survival model with a non linear effect of age # with correction of life table, strabified by sex # full likelihood fit2 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), formula.table= ~sex, rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", Spline.CLT=flexrsurv:::R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) summary(fit2) AIC(fit0, fit1, fit2) }
returns the cumulative hazard and the hazard rate of subjects in a reference life table
getBrassPseudoHazardFromTable(Y, startdate, startage, matchdata = NULL, ratetable = survival::survexp.us, age = 1, year = 2, rmap, agemin = 16, scale = 365.25, ratename = "rateend", cumrateendname = "cumrateend", cumrateentername = "cumrateenter", idname = "Id_byperiod", origin = "01/01/1970", format="%d/%m/%Y", left.open = FALSE, SplineBrass=R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3)*c(1, 0, 1), verbose=FALSE)
getBrassPseudoHazardFromTable(Y, startdate, startage, matchdata = NULL, ratetable = survival::survexp.us, age = 1, year = 2, rmap, agemin = 16, scale = 365.25, ratename = "rateend", cumrateendname = "cumrateend", cumrateentername = "cumrateenter", idname = "Id_byperiod", origin = "01/01/1970", format="%d/%m/%Y", left.open = FALSE, SplineBrass=R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3)*c(1, 0, 1), verbose=FALSE)
Y |
An object with interval data. It can be an object of class |
startdate |
a numeric vector such that |
startage |
a numeric vector of age in days the start (when Y[,]==0). |
matchdata |
an optional data.frame in which to interpret the additional variables to be mapped to the |
ratetable |
an object of class |
age , year
|
character values of the names of the age and period variables in the rate table. |
rmap |
an optional list that maps data set names to the ratetable names. See |
agemin |
numeric value of the age at which the cumulative hazard starts. |
scale |
numeric value to scale |
ratename , cumrateendname , cumrateentername , idname
|
names of the returned variables |
origin , format
|
passed to |
left.open |
logical, passed to |
SplineBrass |
Spline basis used to transform the rates |
verbose |
logical, if |
The cumulative rates are computed using survexp
.
A data.frame
with 3 columns with the rate at the ending time, the cumulative rate from agemin up to the starting time and upt to the ending time.
getHazardFromTable
for the cumulative hazard and the hazard rate of subjects in a reference life table.
survexp
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getPseudoHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.24 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, scale=365.24, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter", idname="Id_byperiod" ) summary(HH) }
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getPseudoHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.24 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, scale=365.24, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter", idname="Id_byperiod" ) summary(HH) }
returns the cumulative hazard and the hazard rate of subjects in a reference life table
getHazardFromTable(Y, startdate, startage, matchdata = NULL, ratetable = survival::survexp.us, age = 1, year = 2, rmap, agemin = 16, scale = 365.25, ratename = "rateend", cumrateendname = "cumrateend", cumrateentername = "cumrateenter", origin = "01/01/1970", format = "%d/%m/%Y", left.open = FALSE, verbose=FALSE)
getHazardFromTable(Y, startdate, startage, matchdata = NULL, ratetable = survival::survexp.us, age = 1, year = 2, rmap, agemin = 16, scale = 365.25, ratename = "rateend", cumrateendname = "cumrateend", cumrateentername = "cumrateenter", origin = "01/01/1970", format = "%d/%m/%Y", left.open = FALSE, verbose=FALSE)
Y |
An object with interval data. It can be an object of class |
startdate |
a numeric vector such that |
startage |
a numeric vector of age in days the start (when Y[,]==0). |
matchdata |
an optional data.frame in which to interpret the additional variables to be mapped to the |
ratetable |
an object of class |
age , year
|
character values of the names of the age and period variables in the rate table. |
rmap |
an optional list that maps data set names to the ratetable names. See |
agemin |
numeric value of the age at which the cumulative hazard starts. |
scale |
numeric value to scale |
ratename , cumrateendname , cumrateentername
|
names of the returned variables |
origin , format
|
arguments passed |
left.open |
logical, passed to |
verbose |
logical, if |
The cumulative rates are computed using survexp
.
A data.frame
with 3 columns with the rate at the ending time, the cumulative rate from agemin up to the starting time and upt to the ending time.
getPseudoHazardFromTable
for the cumulative hazard in each period of a reference life table.
getBrassHazardFromTable
for the cumulative hazard in a corrected reference life table.
survexp
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.24 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, scale=365.24, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter" ) summary(HH) }
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.24 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, scale=365.24, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter" ) summary(HH) }
return the cumulative pseudo hazard and the hazard rate of subjects in a reference life table
getPseudoHazardFromTable(Y, startdate, startage, matchdata = NULL, ratetable = survival::survexp.us, age = 1, year = 2, rmap, agemin = 16, scale = 365.25, ratename = "rateend", cumrateendname = "cumrateend", cumrateentername = "cumrateenter", idname = "Id_byperiod", origin = "01/01/1970", format="%d/%m/%Y", left.open = FALSE, verbose=FALSE)
getPseudoHazardFromTable(Y, startdate, startage, matchdata = NULL, ratetable = survival::survexp.us, age = 1, year = 2, rmap, agemin = 16, scale = 365.25, ratename = "rateend", cumrateendname = "cumrateend", cumrateentername = "cumrateenter", idname = "Id_byperiod", origin = "01/01/1970", format="%d/%m/%Y", left.open = FALSE, verbose=FALSE)
Y |
An object with interval data. It can be an object of class |
startdate |
a numeric vector such that |
startage |
a numeric vector of age in days the start (when Y[,]==0). |
matchdata |
an optional data.frame in which to interpret the additional variables to be mapped to the |
ratetable |
an object of class |
age , year
|
character values of the names of the age and period variables in the rate table. |
rmap |
an optional list that maps data set names to the ratetable names. See |
agemin |
numeric value of the age at which the cumulative hazard starts. |
scale |
numeric value to scale |
ratename , cumrateendname , cumrateentername , idname
|
names of the returned variables |
origin , format
|
passed to |
left.open |
logical, passed to |
verbose |
logical, if |
The cumulative rates are computed using survexp
.
A data.frame
with 3 columns with the rate at the ending time, the cumulative rate from agemin up to the starting time and upt to the ending time.
getHazardFromTable
for the cumulative hazard and the hazard rate of subjects in a reference life table.
survexp
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getPseudoHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.24 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, scale=365.24, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter", idname="Id_byperiod" ) summary(HH) }
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getPseudoHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.24 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, scale=365.24, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter", idname="Id_byperiod" ) summary(HH) }
flexrsuv
fit.Function to extract Log-Likelihood and the number of observations from a flexrsuv
or flexrsuvclt
fit.
## S3 method for class 'flexrsurv' logLik(object, ...) ## S3 method for class 'flexrsurv' nobs(object, ...)
## S3 method for class 'flexrsurv' logLik(object, ...) ## S3 method for class 'flexrsurv' nobs(object, ...)
object |
any object of class |
... |
not used |
logLik
returns a standard logLik
object (see logLik
)
nobs
returns a single number, normally an integer.
Generate the spline basis matrix for non log-linear effect.
NLL(x, Spline = c("b-spline", "tp-spline", "tpi-spline"), Knots = NULL, Degree = 3, Intercept = FALSE, Boundary.knots = range(x), Keep.duplicates = TRUE, outer.ok = TRUE, ...)
NLL(x, Spline = c("b-spline", "tp-spline", "tpi-spline"), Knots = NULL, Degree = 3, Intercept = FALSE, Boundary.knots = range(x), Keep.duplicates = TRUE, outer.ok = TRUE, ...)
x |
the predictor variable. |
Spline |
a character string specifying the type of spline basis. "b-spline" for B-spline basis, "tp-spline" for truncated power basis and "tpi-spline" for monotone (increasing) truncated power basis. |
Knots |
the internal breakpoints that define the spline used to estimate the NLL effect. By default there are none. |
Degree |
degree of splines which are considered. |
Intercept |
a logical value indicating whether intercept/first basis of spline should be considered. |
Boundary.knots |
range of variable which is analysed. |
Keep.duplicates |
Should duplicate interior knots be kept or removed. Defaults is |
outer.ok |
logical indicating how are managed |
... |
not used |
NLL
is based on package orthogonalsplinebasis
Generate the design matrix of spline basis for non proportional effect.
NPH(x, timevar, Spline = c("b-spline", "tp-spline", "tpi-spline"), Knots.t = NULL, Degree.t = 3, Intercept.t = TRUE, Boundary.knots.t = c(0, max(timevar)), Keep.duplicates.t = TRUE, outer.ok = TRUE, ...)
NPH(x, timevar, Spline = c("b-spline", "tp-spline", "tpi-spline"), Knots.t = NULL, Degree.t = 3, Intercept.t = TRUE, Boundary.knots.t = c(0, max(timevar)), Keep.duplicates.t = TRUE, outer.ok = TRUE, ...)
x |
the predictor variable. |
timevar |
the time variable. |
Spline |
a character string specifying the type of spline basis. "b-spline" for B-spline basis, "tp-spline" for truncated power basis and "tpi-spline" for monotone (increasing) truncated power basis. |
Knots.t |
the internal breakpoints that define the spline used to estimate the NPH effect. By default there are none. |
Degree.t |
degree of splines which are considered. |
Intercept.t |
a logical value indicating whether intercept/first basis of spline should be considered. |
Boundary.knots.t |
range of time period which is analysed. By default it is |
Keep.duplicates.t |
Should duplicate interior knots be kept or removed. Defaults is |
outer.ok |
logical indicating how are managed |
... |
not used |
NPH
is based on package orthogonalsplinebasis
Generate the design matrix of spline basis for both non log-linear and non proportional effect.
NPHNLL(x, timevar, model = c("additive", "multiplicative"), Spline = c("b-spline", "tp-spline", "tpi-spline"), Knots = NULL, Degree = 3, Intercept = FALSE, Boundary.knots = range(x), Knots.t = NULL, Degree.t = 3, Intercept.t = (model == "multiplicative"), Boundary.knots.t = c(0, max(timevar)), outer.ok = TRUE, Keep.duplicates = TRUE, xdimnames = ":XxXxXXxXxX ", tdimnames = ":TtTtTTtTtT ")
NPHNLL(x, timevar, model = c("additive", "multiplicative"), Spline = c("b-spline", "tp-spline", "tpi-spline"), Knots = NULL, Degree = 3, Intercept = FALSE, Boundary.knots = range(x), Knots.t = NULL, Degree.t = 3, Intercept.t = (model == "multiplicative"), Boundary.knots.t = c(0, max(timevar)), outer.ok = TRUE, Keep.duplicates = TRUE, xdimnames = ":XxXxXXxXxX ", tdimnames = ":TtTtTTtTtT ")
x |
the predictor variable. |
timevar |
the time variable. |
model |
character string specifying the type of model for both non-proportionnal and non linear effects.
The model |
Spline |
a character string specifying the type of spline basis. "b-spline" for B-spline basis, "tp-spline" for truncated power basis and "tpi-spline" for monotone (increasing) truncated power basis. |
Knots |
the internal breakpoints that define the spline used to estimate the NLL part of effect. By default there are none. |
Degree |
degree of splines of variable which are considered. |
Intercept |
a logical value indicating whether intercept/first basis of spline should be considered. |
Boundary.knots |
range of variable which is analysed. |
Knots.t |
the internal breakpoints that define the spline used to estimate the NPH part of effect. By default there are none. |
Degree.t |
degree of splines of time variable which are considered. |
Intercept.t |
a logical value indicating whether intercept/first basis of spline should be considered. |
Boundary.knots.t |
range of time period which is analysed. |
Keep.duplicates |
Should duplicate interior knots be kept or removed. Defaults is |
outer.ok |
logical indicating how are managed |
xdimnames |
string to build dimnames of |
tdimnames |
string to build dimnames of |
NPHNLL
is based on package orthogonalsplinebasis
Mahboubi, A., M. Abrahamowicz, et al. (2011). "Flexible modeling of the effects of continuous prognostic factors in relative survival." Stat Med 30(12): 1351-1365. doi:10.1002/sim.4208
Remontet, L., N. Bossard, et al. (2007). "An overall strategy based on regression models to estimate relative survival and model the effects of prognostic factors in cancer survival studies." Stat Med 26(10): 2214-2228. doi:10.1002/sim.2656
Predict linear predictors, hazard and cumulative
hazard for a model fitted by flexrsuv
## S3 method for class 'flexrsurv' predict(object, newdata= NULL, type = c("lp", "link", "risk", "hazard", "hazardrate", "rate", "loghazard", "log", "lograte", "cumulative.rate", "cumulative.hazard", "cumulative", "cum", "survival", "surv", "netsurv"), se.fit=FALSE, ci.fit = FALSE, level = .95, na.action=na.pass, ...)
## S3 method for class 'flexrsurv' predict(object, newdata= NULL, type = c("lp", "link", "risk", "hazard", "hazardrate", "rate", "loghazard", "log", "lograte", "cumulative.rate", "cumulative.hazard", "cumulative", "cum", "survival", "surv", "netsurv"), se.fit=FALSE, ci.fit = FALSE, level = .95, na.action=na.pass, ...)
object |
the results of a flexrsurv fit. |
newdata |
Optional new data at which to do predictions. If absent predictions are for the data frame used in the original fit. |
type |
the type of predicted value.
Choices are the linear predictor ( |
se.fit |
if TRUE, pointwise standard errors are produced for the predictions (not available for cumulative hazard). |
ci.fit |
if TRUE, confidence intervale are produced for the predictions. |
level |
Confidence level. |
na.action |
function determining what should be done with missing values in
|
... |
For future methods |
For cumulative hazard, the cumulative hazard is computed from 0 until the given end time. The cumulative hazard is computed using the same numerical integration method as the one used to fit the model.
a vector or a list containing the predictions (element "fit"
) and their
standard errors (element "se.fit"
) if the se.fit option is TRUE.
To work correctly, arguments Boundary.knots
and
Boundary.knots.t
must be included in the call to NPH()
, NLL()
and
NPHNLL()
in the formula of flexrsurv
predict
, flexrsurv
, flexrsurvclt
if (requireNamespace("relsurv", quietly = TRUE)) { # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # change sex coding rdata$sex01 <- rdata$sex -1 # centering age rdata$agec <- rdata$age- 60 # fit a relative survival model with a non linear effect of age fit <- flexrsurv(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Spline = "b-spline", initbyglm=TRUE, int_meth= "BOOLE", step=50 ) summary(fit, correlation=TRUE) newrdata <- rdata newrdata$age <- rep(60, length(rdata$age)) newrdata$sex <- factor(newrdata$sex, labels=c("m", "f")) linpred <- predict(fit, newdata=newrdata, type="lp", ci.fit=TRUE) predhazard <- predict(fit, newdata=newrdata, type="hazard" , ci.fit=TRUE) predcumhazard <- predict(fit, newdata=newrdata, type="cum", ci.fit=TRUE) require(ggplot2) tmp <- cbind(newrdata, linpred) glp <- ggplot(tmp, aes(time, colour=sex)) glp + geom_ribbon(aes(ymin = lwr, ymax = upr, fill=sex)) + geom_line(aes(y=fit)) + scale_fill_manual(values = alpha(c("blue", "red"), .3)) tmp <- cbind(newrdata, predhazard) glp <- ggplot(tmp, aes(time, colour=sex)) glp + geom_ribbon(aes(ymin = lwr, ymax = upr, fill=sex)) + geom_line(aes(y=fit)) + scale_fill_manual(values = alpha(c("blue", "red"), .3)) tmp <- cbind(newrdata, predcumhazard) glp <- ggplot(tmp, aes(time, colour=sex)) glp + geom_ribbon(aes(ymin = lwr, ymax = upr, fill=sex)) + geom_line(aes(y=fit)) + scale_fill_manual(values = alpha(c("blue", "red"), .3)) }
if (requireNamespace("relsurv", quietly = TRUE)) { # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # change sex coding rdata$sex01 <- rdata$sex -1 # centering age rdata$agec <- rdata$age- 60 # fit a relative survival model with a non linear effect of age fit <- flexrsurv(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Spline = "b-spline", initbyglm=TRUE, int_meth= "BOOLE", step=50 ) summary(fit, correlation=TRUE) newrdata <- rdata newrdata$age <- rep(60, length(rdata$age)) newrdata$sex <- factor(newrdata$sex, labels=c("m", "f")) linpred <- predict(fit, newdata=newrdata, type="lp", ci.fit=TRUE) predhazard <- predict(fit, newdata=newrdata, type="hazard" , ci.fit=TRUE) predcumhazard <- predict(fit, newdata=newrdata, type="cum", ci.fit=TRUE) require(ggplot2) tmp <- cbind(newrdata, linpred) glp <- ggplot(tmp, aes(time, colour=sex)) glp + geom_ribbon(aes(ymin = lwr, ymax = upr, fill=sex)) + geom_line(aes(y=fit)) + scale_fill_manual(values = alpha(c("blue", "red"), .3)) tmp <- cbind(newrdata, predhazard) glp <- ggplot(tmp, aes(time, colour=sex)) glp + geom_ribbon(aes(ymin = lwr, ymax = upr, fill=sex)) + geom_line(aes(y=fit)) + scale_fill_manual(values = alpha(c("blue", "red"), .3)) tmp <- cbind(newrdata, predcumhazard) glp <- ggplot(tmp, aes(time, colour=sex)) glp + geom_ribbon(aes(ymin = lwr, ymax = upr, fill=sex)) + geom_line(aes(y=fit)) + scale_fill_manual(values = alpha(c("blue", "red"), .3)) }
Predict the relational model for a life table correction model fitted by flexrsuvclt
or for specified knots, degree and coefficients
predictCLT (...) ## S3 method for class 'flexrsurvclt' predictCLT(object, newdata= NULL, type = c("clt", "correction"), se.fit=FALSE, na.action=na.pass, newcoef = NULL, ...) ## Default S3 method: predictCLT(knots, degree, newdata, newcoef, ...)
predictCLT (...) ## S3 method for class 'flexrsurvclt' predictCLT(object, newdata= NULL, type = c("clt", "correction"), se.fit=FALSE, na.action=na.pass, newcoef = NULL, ...) ## Default S3 method: predictCLT(knots, degree, newdata, newcoef, ...)
object |
the results of a flexrsurvclt fit. |
newdata |
Optional new vector of logarithm of the cumulative distribution odds (LCDO) at which to do predictions.
If absent predictions are for values of the LCDO used in the original fit ( |
newcoef |
Optional new coefficients for which to do predictions.
If absent predictions are for the coefficients of the fitted model in |
type |
the type of predicted value.
Choices are |
se.fit |
if TRUE, pointwise standard errors are produced for the predictions (not yet implemented). |
knots , degree
|
knots and degree of the relational model. |
na.action |
function determining what should be done with missing values in
|
... |
For future methods |
predictCLT
with knots
and degree
arguments computes corrected values of .
a vector or a list containing the predicted relational model (element "fit"
) and their
standard errors (element "se.fit"
) if the se.fit option is TRUE.
predict.flexrsurvclt
, flexrsurv
, flexrsurvclt
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") class(rdata$year)<-"integer" # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # get the logit_start and logit_end # logit start at age 18 tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.25 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter" ) rdata$slorate <- HH$poprate rdata$logit_start <- log(exp(HH$cumrateenter)-1) rdata$logit_end <- log(exp(HH$cumrateend)-1) rdata$Id <- 1:dim(rdata)[1] # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effect of age # with correction of life table # full likelihood fit1 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", Spline.CLT=flexrsurv:::R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) corrected_logit_end <- predictCLT(fit1) try_logit_end <- predictCLT(knots=c(-2.5,0,2.5), degree=3, newcoef = c(0.5, 2), newdata = rdata$logit_end ) plot(rdata$logit_end, corrected_logit_end) points(rdata$logit_end, try_logit_end, col = 2) }
if (requireNamespace("relsurv", quietly = TRUE) & requireNamespace("date", quietly = TRUE)) { library(date) # data from package relsurv data(rdata, package="relsurv") class(rdata$year)<-"integer" # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # get the logit_start and logit_end # logit start at age 18 tmpsurv <- Surv(rep(0, length(rdata$time)), rdata$time, rdata$cens) HH <- getHazardFromTable(tmpsurv, startdate=rdata$year, startage=rdata$age*365.25 , matchdata=rdata, ratetable=slopop, age="age", year="year", rmap=list(sex=sex), agemin=18, ratename = "poprate", cumrateendname ="cumrateend", cumrateentername ="cumrateenter" ) rdata$slorate <- HH$poprate rdata$logit_start <- log(exp(HH$cumrateenter)-1) rdata$logit_end <- log(exp(HH$cumrateend)-1) rdata$Id <- 1:dim(rdata)[1] # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effect of age # with correction of life table # full likelihood fit1 <- flexrsurvclt(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3, Boundary.knots = c(24, 95)), rate=slorate, logit_start=logit_start, logit_end=logit_end, data=rdata, Id=Id, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Max_T=5400, Spline = "b-spline", Spline.CLT=flexrsurv:::R2bBSplineBasis(knots=c(-2.5,0,2.5), degree=3), initbyglm=TRUE, initbands=seq(0, 5400, 100), int_meth= "BANDS", bands=seq(0, 5400, 50) ) corrected_logit_end <- predictCLT(fit1) try_logit_end <- predictCLT(knots=c(-2.5,0,2.5), degree=3, newcoef = c(0.5, 2), newdata = rdata$logit_end ) plot(rdata$logit_end, corrected_logit_end) points(rdata$logit_end, try_logit_end, col = 2) }
Predict a spline function by specifying its type, knots, degree and coefficients
predictSpline (object, x, ...) ## Default S3 method: predictSpline(object=c("b-spline", "tp-spline"), x, knots, degree, keep.duplicates = FALSE, coef=1, ... )
predictSpline (object, x, ...) ## Default S3 method: predictSpline(object=c("b-spline", "tp-spline"), x, knots, degree, keep.duplicates = FALSE, coef=1, ... )
object |
the type of spline to be predicted ("b-spline", the default, or "tp-spline") |
x |
Vector of values at wich to predict the spline function. |
knots , degree
|
knots and degree of the relational model. |
keep.duplicates |
Should duplicate interior knots be kept or removed. Defaults is |
coef |
vector of coefficient of the spline function. |
... |
not used |
predictSpline
.
A vector the evaluated spline function with same length as x.
predict.flexrsurvclt
, flexrsurv
, flexrsurvclt
predspline <- predictSpline("b-spline", x= seq(from=-3, to = 3, by=.1), coef = .5 * 1:5, knots=c(-3,0,3), degree=3) plot(seq(from=-3, to = 3, by=.1), predspline)
predspline <- predictSpline("b-spline", x= seq(from=-3, to = 3, by=.1), coef = .5 * 1:5, knots=c(-3,0,3), degree=3) plot(seq(from=-3, to = 3, by=.1), predspline)
Print number of observations, number of events, the formula, the estimated coeficients and the log likelihood.
## S3 method for class 'flexrsurv' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'flexrsurv' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
the result of a call to the |
digits |
the minimum number of significant digits to be printed in values, see |
... |
other options |
The default method print.default
, and help for the
function flexrsurv
, flexrsurvclt
.
summary
methods for class flexrsurv
.
Produces and prints summaries of the results of a fitted Relative Survival Model
## S3 method for class 'flexrsurv' summary(object, correlation = FALSE, symbolic.cor = FALSE, ...) ## S3 method for class 'summary.flexrsurv' print(x, digits = max(3L, getOption("digits") - 3L), symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), ...)
## S3 method for class 'flexrsurv' summary(object, correlation = FALSE, symbolic.cor = FALSE, ...) ## S3 method for class 'summary.flexrsurv' print(x, digits = max(3L, getOption("digits") - 3L), symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), ...)
object |
an object of class "flexrsurv", usually, a result of a call to |
x |
an object of class |
correlation |
logical; if |
symbolic.cor |
logical. If |
digits |
the number of significant digits to use when printing. |
signif.stars |
logical. If TRUE,'significance stars' are printed for each coefficient. |
... |
further arguments passed to or from other methods. |
print.summary.glm
tries to be smart about formatting the coefficients, standard errors, etc.
and additionally gives ‘significance stars’ if signif.stars
is TRUE
.
Correlations are printed to two decimal places (or symbolically): to see the actual correlations
print summary(object)$correlation
directly.
The dispersion of a GLM is not used in the fitting process, but it is needed to find standard errors. If dispersion is not supplied or NULL, the dispersion is taken as 1 for the binomial and Poisson families, and otherwise estimated by the residual Chisquared statistic (calculated from cases with non-zero weights) divided by the residual degrees of freedom.
The function summary.flexrsurv computes and returns a list of summary statistics of the fitted flexible relative survival model given in object
.
The returned value is an object of class "summary.flexrsurv
", which a list with components:
call |
the " |
terms |
the " |
coefficients |
the matrix of coefficients, standard errors, z-values and p-values. |
cov |
the estimated covariance matrix of the estimated coefficients. |
correlation |
(only if |
symbolic.cor |
(only if |
loglik |
the " |
df.residual |
the " |
summary
, flexrsurv
, flexrsurvclt
.
if (requireNamespace("relsurv", quietly = TRUE)) { # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effetc of age fit <- flexrsurv(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Spline = "b-spline", initbyglm=TRUE, initbands=seq(from=0, to=5400, by=200), int_meth= "CAV_SIM", step=50 ) summary(fit) }
if (requireNamespace("relsurv", quietly = TRUE)) { # data from package relsurv data(rdata, package="relsurv") # rate table from package relsurv data(slopop, package="relsurv") # get the death rate at event (or end of followup) from slopop for rdata rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]]) rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]]) therate <- rep(-1, dim(rdata)[1]) for( i in 1:dim(rdata)[1]){ therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]] } rdata$slorate <- therate # change sex coding rdata$sex01 <- rdata$sex -1 # fit a relative survival model with a non linear effetc of age fit <- flexrsurv(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3), rate=slorate, data=rdata, knots.Bh=1850, # one interior knot at 5 years degree.Bh=3, Spline = "b-spline", initbyglm=TRUE, initbands=seq(from=0, to=5400, by=200), int_meth= "CAV_SIM", step=50 ) summary(fit) }
Generate the spline basis matrix for Weighted cumulative exposure index.
WCEI(x, timevar, fromT=0, Spline.WCEI=NULL, Spline = c("m-spline", "b-spline", "tp-spline", "tpi-spline"), Knots.t = NULL, Degree.t = 3, Intercept.t = TRUE, Boundary.knots.t = range(c(timevar, fromT)), Keep.duplicates.t = TRUE, outer.ok = TRUE, ...)
WCEI(x, timevar, fromT=0, Spline.WCEI=NULL, Spline = c("m-spline", "b-spline", "tp-spline", "tpi-spline"), Knots.t = NULL, Degree.t = 3, Intercept.t = TRUE, Boundary.knots.t = range(c(timevar, fromT)), Keep.duplicates.t = TRUE, outer.ok = TRUE, ...)
x |
the exposure variable. |
timevar |
the time variable. |
fromT |
Time at which starts exposure |
Spline.WCEI |
a S4 object with method deriv(), evaluate() and predict(). |
Spline |
a character string specifying the type of spline basis. "b-spline" for B-spline basis, "tp-spline" for truncated power basis and "tpi-spline" for monotone (increasing) truncated power basis. |
Knots.t |
the internal breakpoints that define the spline used to estimate the WCEI effect. By default there are none. |
Degree.t |
degree of splines which are considered. |
Intercept.t |
a logical value indicating whether intercept/first basis of spline should be considered. |
Boundary.knots.t |
range of variable which is analysed. |
Keep.duplicates.t |
Should duplicate interior knots be kept or removed. Defaults is |
outer.ok |
logical indicating how are managed |
... |
not used |
WCEI
is based on package orthogonalsplinebasis