
Multiply imputes missing covariate values and event times using substantive model compatible fully conditional specification with a Royston-Parmar flexible parametric survival model.
smcfcs.flexsurv(
originaldata,
smformula,
method,
k = 2,
imputeTimes = FALSE,
censtime = NULL,
originalKnots = TRUE,
...
)
The original data frame with missing values.
A formula of the form "Surv(t,d)~x+z"
A required vector of strings specifying for each variable either
that it does not need to be imputed (""), the type of regression model to be
be used to impute. Possible values are "norm"
(normal linear regression),
"logreg"
(logistic regression), "brlogreg"
(bias reduced logistic regression),
"poisson"
(Poisson regression),
"podds"
(proportional odds regression for ordered categorical variables),
"mlogit"
(multinomial logistic regression for unordered categorical variables),
or a custom expression which defines a passively imputed variable, e.g.
"x^2"
or "x1*x2"
. "latnorm"
indicates the variable is a latent
normal variable which is measured with error. If this is specified for a variable,
the "errorProneMatrix"
argument should also be used.
Number of knots to use in the flexible parametric survival model
If set to TRUE, smcfcs.flexsurv
will impute
censored survival times, as well as any missing covariates
Value(s) to use for censoring of imputed event times. If a vector, it should be of length equal to the number of original censored individuals
If imputing censored event times, setting
originalKnots=TRUE
means the automatically chosen knot locations
from the model fitted to the observed times are used throughout. If FALSE
,
knots are chosen automatically at each iteration by flexsurvspline
based on the current observed+imputed event times, according to the chosen
value of k
.
Additional arguments to pass on to smcfcs
Jonathan Bartlett jonathan.bartlett1@lshtm.ac.uk
This version of smcfcs
is for time-to-event outcomes which are modelled
using a flexible parametric proportional hazards survival model, as proposed
by Royston and Parmar (2002). The model is
fitted using the flexsurvspline
function in the
flexsurv package. Specifically it fits models using the hazard scale. The
flexibility of the model can be changed by modifying the k argument, which
specifies the number of knots.
If desired, smcfcs.flexsurv
can be used to impute event times for individuals
who are originally censored, by specifying imputeTimes=TRUE
. In the resulting
imputed datasets every individual will have an event time and the event indicator will
be one for all. Alternatively, you can impute censored times, but setting a larger
potential censoring time, which is either a common value used for all or a vector of times,
by using the censtime
argument. If some individuals have their time-to-event
outcome completely missing and you want to impute this, they should have a time of zero
and the event indicator set to zero.
smcfcs.flexsurv
will not let you impute using norm, latnorm or poisson methods
for variables that are allowed to have time-varying effects, because the usual
rejection sampling bound used by smcfcs is not valid in this setting.
flexsurvspline
sometimes fails during model fitting.
If/when this occurs, smcfcs.flexsurv
takes a posterior draw based
on the model fit from the preceding iteration, and a warning is printed at
the end of the smcfcs.flexsurv
run detailing how many times it occurred.
Royston P, Parmar MKB. Flexible parametric proportional-hazards and proportional-odds models for censored survival data, with application to prognostic modelling and estimation of treatment effects. Statistics in Medicine 2002; 21(15): 2175-2197. tools:::Rd_expr_doi("doi:10.1002/sim.1203")
#the following example is not run when the package is compiled on CRAN
#(to keep computation time down), but it can be run by package users
if (FALSE) {
set.seed(63213)
imps <- smcfcs.flexsurv(ex_flexsurv,
k=2,
smformula="Surv(t,d)~x+z",
method=c("","","logreg",""))
library(mitools)
impobj <- imputationList(imps$impDatasets)
models <- with(impobj, flexsurvspline(Surv(t,d)~x+z, k=2))
summary(MIcombine(models))
# now impute event times as well as missing covariates
imps <- smcfcs.flexsurv(ex_flexsurv,
k=2,
smformula="Surv(t,d)~x+z",
method=c("","","logreg",""),
imputeTimes=TRUE)
# now impute event times as well as missing covariates,
# but setting max observed event time to 2
imps <- smcfcs.flexsurv(ex_flexsurv,
k=2,
smformula="Surv(t,d)~x+z",
method=c("","","logreg",""),
imputeTimes=TRUE,
censtime=2)
}
Run the code above in your browser using DataLab