Learn R Programming

rstpm2 (version 1.2.2)

stpm2: Flexible parametric survival model.

Description

This implements the Royston-Parmar model.

Usage

stpm2(formula, data, df = 3, cure = FALSE, logH.args = NULL,
      logH.formula = NULL, tvc = NULL, tvc.formula =
      NULL, control = list(parscale = 0.1, maxit = 300),
      init = NULL, coxph.strata = NULL, weights = NULL,
      robust = FALSE, baseoff = FALSE, bhazard = NULL,
      timeVar = "", time0Var = "", use.gr = TRUE,
      use.rcpp= TRUE, reltol=1.0e-8, trace = 0,
      type=c("PH","PO","probit","AH"), frailty = FALSE,
      cluster = NULL, logtheta=0, contrasts = NULL,
      subset = NULL, ...)

Arguments

formula
a formula object, with the response on the left of a ~ operator, and the regression terms (excluding time) on the right. The response must be a survival object as returned by the Surv function. T
data
a data.frame in which to interpret the variables named in the formula argument. [at present: required]
df
an integer that describes the degrees of freedom for the ns function for modelling the baseline log-cumulative hazard (default=3).
logH.args
a list describing the arguments for the nsx function for modelling the baseline log-cumulative hazard (default=NULL). Use this or logH.formula for changing the knot placement and specifying cure models.
logH.formula
a formula for describing the baseline log-cumulative hazard function (default=NULL). Only one of df, logH.args or logH.formula is required. The default model is equal to nsx(log(time),df=3).
tvc
a list with the names of the time-varying coefficients and the degrees of freedom (e.g. tvc=list(x=3) specifies x as a time-varying coefficient with 3 degrees of freedom).
tvc.formula
a formula for describing the time-varying coefficients. If a time-varying coefficient is being model, then only one of tvc and tvc.formula is required.
bhazard
a vector for the background hazard for relative survival estimation. At present, this does not use data and it is required for all individuals - although it is only used at the event times.
control
control argument passed to optim.
init
init should either be FALSE, such that initial values will be determined using Cox regression, or a numeric vector of initial values.
coxph.strata
variable in the data argument for stratification of the coxph model fit for estimating initial values.
weights
an optional vector of 'prior weights' to be used in the fitting process. Should be NULL or a numeric vector.
robust
Boolean used to determine whether to use a robust variance estimator.
baseoff
Boolean used to determine whether fully define the model using tvc.formula rather than combining logH.formula and tvc.formula
timeVar
variable defining the time variable. By default, this is determined from the survival object, however this may be ambiguous if two variables define the time
use.gr
Boolean to determine whether to use the gradient in the optimisation
contrasts
an optional list. See the contrasts.arg of model.matrix.default.
subset
an optional vector specifying a subset of observations to be used in the fitting process.
cure
logical for whether to estimate a cure model.
time0Var
string variable to determine the entry variable; useful for when more than one data variable is used in the entry time.
type
type of link function.
use.rcpp
logical for whether to use C++/Rcpp for estimation
reltol
relative tolerance for the model convergence
trace
logical for whether to provide trace information
frailty
logical for whether to fit a shared frailty model (experimental)
cluster
string for the data variable that determines the cluster for the frailty (experimental)
logtheta
initial value for log-theta used in the gamma shared frailty model (experimental)
...
additional arguments to be passed to the mle2 .

Value

  • An stpm2-class object that inherits from mle2-class.

Details

The implementation extends the mle2 object from the bbmle package.

Note that the default baseline log-cumulative hazard function uses natural splines for log of time with three degrees of freedom. The design matrix is calculated for the event times rather than all observations.

Examples

Run this code
data(brcancer)
summary(fit <- stpm2(Surv(rectime,censrec==1)~hormon,data=brcancer,df=3))

## some predictions
head(predict(fit,se.fit=TRUE,type="surv"))
head(predict(fit,se.fit=TRUE,type="hazard"))

## some plots
plot(fit,newdata=data.frame(hormon=0),type="hazard")
plot(fit,newdata=data.frame(hormon=0),type="surv")

## the same model using logH.formula
summary(stpm2(Surv(rectime,censrec==1)~hormon,data=brcancer,logH.formula=~ns(log(rectime),df=3)))


## time-varying coefficient
summary(fit.tvc <- stpm2(Surv(rectime,censrec==1)~hormon,data=brcancer,df=3,
                     tvc=list(hormon=3)))
anova(fit,fit.tvc) # compare with and without tvc

## some more plots
plot(fit.tvc,newdata=data.frame(hormon=0),type="hr",var="hormon", ylim=c(0,2))
                                        # no lines method: use add=TRUE
plot(fit.tvc,newdata=data.frame(hormon=1),type="hr",var="hormon",
     add=TRUE,ci=FALSE,line.col=2)

plot(fit.tvc,newdata=data.frame(hormon=0),type="sdiff",var="hormon")

plot(fit.tvc,newdata=data.frame(hormon=0),type="hdiff",var="hormon")

plot(fit.tvc,newdata=data.frame(hormon=0),type="hazard")
plot(fit.tvc,newdata=data.frame(hormon=1),type="hazard",line.col=2,ci=FALSE,add=TRUE)

## compare number of knots
hormon0 <- data.frame(hormon=0)
plot(fit,type="hazard",newdata=hormon0)
AIC(fit)
for (df in 4:6) {
    fit.new <- stpm2(Surv(rectime,censrec==1)~hormon,data=brcancer,df=df)
    plot(fit.new,type="hazard",newdata=hormon0,add=TRUE,ci=FALSE,line.col=df)
    print(AIC(fit.new))
}

Run the code above in your browser using DataLab