Title: | Rank Preserving Structural Failure Time Models |
---|---|
Description: | Implements methods described by the paper Robins and Tsiatis (1991) <DOI:10.1080/03610929108830654>. These use g-estimation to estimate the causal effect of a treatment in a two-armed randomised control trial where non-compliance exists and is measured, under an assumption of an accelerated failure time model and no unmeasured confounders. |
Authors: | Simon Bond [aut, cre] (primary author of code, secondary author of vignette), Annabel Allison [aut] (primary author of vignette, secondary author of code) |
Maintainer: | Simon Bond <[email protected]> |
License: | GPL-2 |
Version: | 1.2.9 |
Built: | 2024-12-08 06:56:21 UTC |
Source: | CRAN |
This implements the method of Robins JM, Tsiatis AA.
The key function is rpsftm
, which provides estimates of the causal parameter of interest.
rpfstm: a package to fit Rank Preserving Structural Failure Time Model
Maintainer: Simon Bond [email protected] (primary author of code, secondary author of vignette)
Authors:
Annabel Allison (primary author of vignette, secondary author of code)
Robins JM, Tsiatis AA. Correcting for non-compliance in randomized trials using rank preserving structural failure time models. Communications in Statistics–Theory and Methods 1991; 20: 2609–2631
If the the fit
inherits *both* rpsftm
and coxph
then this pulls out the genuine
survival::coxph
object that is deeply nested in the object, and then runs survival::cox.zph
on it.
Or it avoids overwriting the function from survival
by calling survival::cox.zph
directly if the object
does not inherit rpsftm
. Or it fails.
cox.zph(fit, ...)
cox.zph(fit, ...)
fit |
the result of fitting a rpsftm model using |
... |
any other arguments to pass to |
This does rely on the order of loading packages. The rpsftm
package must be loaded after survival
,
if both are required, to avoid the masking of synonymous functions causing errors.
Simulated data to use with the rpsftm
function.
immdef
immdef
A simulated data frame with 9 variables and 1000 observations representing a study where participants were randomly assigned to receive treatment immediately or deferred. Participants in the deferred arm could crossover and receive treatment. The primary endpoint was time to disease progression.
The data are based on a randomized controlled trial Concorde doi:10.1016/S0140-6736(94)90006-X
participant ID number
indicator that the participant was assigned to the Deferred treatment arm
indicator that the participant was assigned to the Immediate treatment arm
censoring time, in years, corresponding to the close of study minus the time of entry for each participant
an indicator that crossover occurred
the time, in years, from entry to switching, or 0 for participants in the Immediate arm
an indicator of disease progression (1), or censoring (0)
time, in years, from entry to disease progression or censoring
the time of entry into the study, measured in years from the date of randomisation
Function used to plot the KM curves of the treatment-free transformed times
## S3 method for class 'rpsftm' plot(x, ...)
## S3 method for class 'rpsftm' plot(x, ...)
x |
an object returned from the |
... |
further arguments passed to or from other methods. |
a ggplot plot of the fitted KM curves. The underlying data.frame has variables
time: failure time
survival: estimated treatment-free survival probability
upper: upper confidence interval at level defined by alpha in the call to rpsftm
lower: lower confidence interval at level defined by alpha in the call to rpsftm
group: randomised treatment arm
Simon Bond
fit <- rpsftm(Surv(progyrs, prog)~rand(imm,1-xoyrs/progyrs),immdef, censyrs) plot(fit) library(ggplot2) plot(fit)+ scale_linetype_discrete(labels=c("Control","Experimental"))+ ylim(0.5,1)+ geom_ribbon(aes(ymin=lower, ymax=upper, fill=group), alpha=0.3)+ labs(x="Time (years)", title=NULL, lty="Arm", fill="Arm")
fit <- rpsftm(Surv(progyrs, prog)~rand(imm,1-xoyrs/progyrs),immdef, censyrs) plot(fit) library(ggplot2) plot(fit)+ scale_linetype_discrete(labels=c("Control","Experimental"))+ ylim(0.5,1)+ geom_ribbon(aes(ymin=lower, ymax=upper, fill=group), alpha=0.3)+ labs(x="Time (years)", title=NULL, lty="Arm", fill="Arm")
print method for rand() objects - to display the summary of rx, by arm
## S3 method for class 'rand' print(x, ...)
## S3 method for class 'rand' print(x, ...)
x |
a rand() object |
... |
further arguments passed to or from other methods. |
a summary of rx values broken down by arm for a rand() object
Simon Bond
Function used to print of the underlying test object at the point estimate of a rpsftm object
## S3 method for class 'rpsftm' print(x, ...)
## S3 method for class 'rpsftm' print(x, ...)
x |
an object returned from the |
... |
further arguments passed to or from other methods. |
a print of the underlying test object at the point estimate.
Simon Bond
A function that is defined to be used in the formula argument, and identified as specials in the terms() object
rand(arm, rx)
rand(arm, rx)
arm |
the randomised treatment arm. a factor with 2 levels, or numeric variable with values 0/1. |
rx |
the proportion of time on active treatment (arm=1 or the non-reference level of the factor) |
matrix with two columns named arm and rx. These can be used in the formula argument to rpsftm()
Simon Bond
x <- with(immdef, rand(imm , 1 - xoyrs / progyrs ) ) x class(x) y <- as.data.frame(x) head(y)
x <- with(immdef, rand(imm , 1 - xoyrs / progyrs ) ) x class(x) y <- as.data.frame(x) head(y)
Function to apply residual method to rpsftm objects
## S3 method for class 'rpsftm' residuals(object, ...)
## S3 method for class 'rpsftm' residuals(object, ...)
object |
an object returned from the |
... |
further arguments passed to or from other methods. |
a residuals object.
Simon Bond
residuals
residuals.coxph
residuals.survreg
Main Function used for estimating causal parameters under the Rank Preserving Structural Failure Time Model
rpsftm( formula, data, censor_time, subset, na.action, test = survdiff, low_psi = -1, hi_psi = 1, alpha = 0.05, treat_modifier = 1, autoswitch = TRUE, n_eval_z = 100, ... )
rpsftm( formula, data, censor_time, subset, na.action, test = survdiff, low_psi = -1, hi_psi = 1, alpha = 0.05, treat_modifier = 1, autoswitch = TRUE, n_eval_z = 100, ... )
formula |
a formula with a minimal structure of |
data |
an optional data frame that contains variables |
censor_time |
variable or constant giving the time at which censoring would, or has occurred. This should be provided for all observations unlike standard Kaplan-Meier or Cox regression where it is only given for censored observations. If no value is given then re-censoring is not applied. |
subset |
expression indicating which subset of the rows of data should be used in the fit. This can be a logical vector (which is replicated to have length equal to the number of observations), a numeric vector indicating which observation numbers are to be included (or excluded if negative), or a character vector of row names to be included. All observations are included by default. |
na.action |
a missing-data filter function. This is applied to the model.frame after any subset argument has been used. Default is options()$na.action. |
test |
the survival regression function to calculate the z-statistic: survdiff, coxph, survreg |
low_psi |
the lower limit of the range to search for the causal parameter |
hi_psi |
the upper limit of the range to search for the causal parameter |
alpha |
the significance level used to calculate confidence intervals |
treat_modifier |
an optional variable that psi is multiplied by on an individual observation level to give differing impact to treatment. |
autoswitch |
a logical to autodetect cases of no switching. If TRUE, then if all observations in an arm have perfect compliance then recensoring is not applied in that arm. If FALSE the recensoring is applied regardless of perfect compliance. |
n_eval_z |
The number of points between hi_psi and low_psi at which to evaluate the Z-statistics in the estimating equation. Default is 100. |
... |
arguments to supply to the test function. |
the formula object Surv(time, status)~rand(arm,rx)
. rand()
stands
for randomisation, both the randomly assigned and actual observed treatment.
arm: the randomised treatment arm. a factor with 2 levels, or numeric variable with values 0/1.
rx: the proportion of time on active treatment (arm=1 or the non-reference level of the factor)
Further adjustment terms can be added on the right hand side of the formula if desired, included strata()
or cluster()
terms.
a rpsftm method object that is a list of the following:
psi: the estimated parameter
fit: a survdiff object to produce Kaplan-Meier curves of the estimated counterfactual untreated failure times for each treatment arm
CI: a vector of the confidence interval around psi
Sstar: the recensored Surv()
data using the estimate value of psi to give counterfactual untreated failure times.
rand: the rand() object used to specify the allocated and observed amount of treatment.
ans: the values from uniroot_all
used to solve the estimating equation,
but embedded within a list as per uniroot
, with an extra element root_all
,
a vector of all roots found in the case of multiple solutions. The first element of root_all
is subsequently used.
eval_z: a data frame with the Z-statistics from the estimating equation evaluated at a sequence of values of psi. Used to plot and check if the range of values to search for solution and limits of confidence intervals need to be modified.
Further elements corresponding to either a survdiff
, coxph
, or survreg
object. This will always include:
call: the R call object
formula: a formula representing any adjustments, strata or clusters- used for the update()
function
terms: a more detailed representation of the model formula
Simon Bond
survdiff
, coxph.object
, survreg.object
?immdef fit <- rpsftm(Surv(progyrs, prog)~rand(imm,1-xoyrs/progyrs),immdef, censyrs) print(fit) summary(fit) plot(fit)
?immdef fit <- rpsftm(Surv(progyrs, prog)~rand(imm,1-xoyrs/progyrs),immdef, censyrs) print(fit) summary(fit) plot(fit)
Function used to summarise the fitted model to an rpsftm object
## S3 method for class 'rpsftm' summary(object, ...)
## S3 method for class 'rpsftm' summary(object, ...)
object |
an object returned from the |
... |
further arguments passed to or from other methods. |
a summary of the fitted regression model.
Simon Bond
Function to apply survfit method to rpsftm objects
## S3 method for class 'rpsftm' survfit(formula, ...)
## S3 method for class 'rpsftm' survfit(formula, ...)
formula |
an object returned from the |
... |
further arguments passed to or from other methods. |
a survfit object.
Simon Bond