Package 'rpsftmPlus'

Title: Extensions To Rpsftm Package
Description: A collection of extenstions to the rpsftm package to enable descriptive analysis of trials affected by treatment switching and enable additional analysis of rpsft models.
Authors: Iain Bennett [aut, cre], F. Hoffmann La Roche Ltd [cph]
Maintainer: Iain Bennett <[email protected]>
License: Apache License (>= 2)
Version: 1.0.0
Built: 2024-12-07 03:08:07 UTC
Source: https://github.com/Roche/rpsftmPlus

Help Index


Convert a survfit to a dataframe of survival and censoring data

Description

This function returns a data frame containing following variables derived from a survfit object. Extends the S3 survfit class.

  • t - Time

  • s - KM Survival estimate

  • c - Censoring indicator - 0 is censored, 1 is event

  • strata - character description of strata that survival estimates are for

  • Plus all strata variables

Usage

## S3 method for class 'survfit'
as.data.frame(x)

Arguments

x

survfit object (survival)

Examples

library(survival)
sf <- survfit(Surv(time, status)~x, data = survival::aml)
as.data.frame(sf)

Plots at risk status from an rpsftm object

Description

This function returns a ggplot derived from an rpsftm object showing status over time. It assumes that only a single switch in treatment occurs i.e. a patient who is randomized to control but has 25

Usage

ggatrisk(x, eval.times = NULL)

Arguments

x

rpsftm object (rpsftm)

eval.times

- vector of times to evaluate at risk status for. Default is all event and censoring times.

Examples

# use data included in rpsftm package
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm::rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

ggatrisk(imm.fit)

Plots observed and counterfactual survival from rpsftm object

Description

This function returns a ggplot derived from an rpsftm object showing 3 survival curves. Observed survival for experimental and control arm. Latent survival time for control arm.

Usage

ggcfact(x, incidence = FALSE)

Arguments

x

rpsftm object (rpsftm)

incidence

TRUE or FALSE (should survival or 1-survival be plotted)

Examples

# use data included in rpsftm package
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm::rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

ggcfact(imm.fit)

Plots hypothetical results from an rpsftm object

Description

This function returns a ggplot derived from an rpsftm object showing hazard ratio and 95 percent CI for each psi tested in the g-estimation. A flat line suggests that there is no impact of switching on the results. A sloped line indicates that switching does affect the results.

Usage

ggdiscount(x)

Arguments

x

rpsftm object (rpsftm)

Examples

# use data included in rpsftm package
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm::rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

ggdiscount(imm.fit)

Plots exposure status from an rpsftm object

Description

This function returns a ggplot derived from an rpsftm object showing exposure to randomized and switch treatment over time. It assumes that only a single switch in treatment occurs i.e. a patient who is randomized to control but has 25 percents exposure to experimental is assumed to have switched at 0.75 times the event time.

Usage

ggexposure(x)

Arguments

x

rpsftm object (rpsftm)

Examples

# use data included in rpsftm package
library(rpsftm)
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

ggexposure(imm.fit)

Plots latent survival from rpsftm object

Description

This function returns a ggplot derived from an rpsftm object showing latent survival time for experimental and control arms. If converged then the two latent survival curves should overlap.

Usage

gglatent(x, incidence = FALSE)

Arguments

x

rpsftm object (rpsftm)

incidence

TRUE or FALSE (should survival or 1-survival be plotted)

Examples

# use data included in rpsftm package
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

gglatent(imm.fit)

Plots g-estimation from rpsftm object

Description

This function returns a ggplot derived from an rpsftm object showing psi vs test statistic. In case of convergence should see a unique solution.

Usage

ggpsi(x)

Arguments

x

rpsftm object (rpsftm)

Examples

# use data included in rpsftm package
library(rpsftm)
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

ggpsi(imm.fit)

Evaluate at risk status from an rpsftm object

Description

This function returns a data frame containing following variables derived from an rpsftm object. It assumes that only a single switch in treatment occurs i.e. a patient who is randomized to control but has 25

  • .arm - 0 or 1 - randomized arm

  • Arm - "Randomized to Control" or "Randomized to Experimental"

  • Time - time that status applies for

  • Status - one of "Event", "Censored", "At risk on Control", "At risk on Experimental"

  • Count - count of patients in this status at this time.

  • Percent - based on total number of patients in arm.

Usage

rpsftm.atrisk(x, eval.times = NULL)

Arguments

x

rpsftm object (rpsftm)

eval.times

- vector of times to evaluate at risk status for. Default is all event and censoring times.

Examples

# use data included in rpsftm package
library(rpsftm)
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

rpsftm.atrisk(imm.fit, eval.times = c(0, 1, 2, 3))

Fits a cox model to an rpsftm object

Description

This function fits a cox model to an rpsftm object. It estimates a hazard ratio for the comparison of experimental observed time compared to control latent time. In addition the variance of the treatment coefficient is inflated based on the test used in g-estimation. Any strata included in rpsftm call are used in the cox model.

Usage

rpsftm.coxph(x)

Arguments

x

rpsftm object (rpsftm)

Examples

# use data included in rpsftm package
library(rpsftm)
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

rpsftm.coxph(imm.fit)

Refits an rpsftm model for common treatment effect sensitivity analysis

Description

This function refits an rpsftm object with a specific weight applied to control arm efficacy. It is a short cut to recalling rpsftm with same parameters and varying the treat_modifier parameter.

Usage

rpsftm.refit(x, k)

Arguments

x

rpsftm object (rpsftm)

k

weight to be applied in the control arm for treatment effect. Single number.

Details

See also documentation for rpsftm call treat_modifier= value.

Examples

# use data included in rpsftm package
library(rpsftm)
immdef <- rpsftm::immdef
immdef$rx <- with(immdef, 1 - xoyrs/progyrs)

# fit the model
imm.fit <- rpsftm(Surv(progyrs, prog) ~ rand(imm, rx),
                  data=immdef,
                  censor_time=censyrs)

rpsftm.refit(imm.fit, k = 0.7)
rpsftm.refit(imm.fit, k = 1.3)

rpsftmPlus: An R package for Rank Preserving Structural Time models

Description

The package extends the rpsftm package with some useful default reports and functions to facilitate sensitivity analysis. Covering descriptive, diagnostic and reporting aspects. All the functions are designed to take an rpsftm object (see rpstm::rpsftm() for details on creation) as an argument. The descriptive functions do not actually require an rspft model to be fit but rather just use it as a convenient way to store information about switching alongside survival.

Details

The following functions are then used for descriptive analysis: * ggexposure: ggexposure(x). This function plots a single line per patient showing exposure prior to event or censoring. * ggatrisk: ggatrisk(x). This function plots at risk on treatments. * rpsftm.atrisk: rpstm.atrisk(x, eval.times). This function returns n and * ggdiscount: ggdiscount(x). This function plots hypothetical results from removing switch treatment from control arm.

The following functions are used for diagnostics: * ggpsi: ggpsi(x). This function plots psi vs Z(psi) to assess a unique solution. * gglatent: gglatent(x). This function plots the latent survival time to assess if balanced.

The following functions are used for reporting: * rpsftm.coxph: rpsftm.coxph(x). This function compares observed experimental and latent control arms with a cox model. It inflates the variance to account for the g-estimation step and correct the CI limits.

The following functions are used for sensitivity analysis of the common treatment effect: * rpsftm.refit: rpsftm.refit(x, k). This function refits an rpsftm model varying the treat_modifier parameter. Allowing sensitivities to the common treatment effect assumption.

The following functions are utilities that may have further use elsewhere and do not take an rpsftm() object as a parameter: * as.data.frame.survfit: as.data.frame.survfit(x). For a given survfit() object returns KM estimates and strata in a dataframe.