Learn R Programming

SEQTaRget - Sequentially Nested Target Trial Emulation

Implementation of sequential trial emulation for the analysis of observational databases. The ‘SEQTaRget’ software accommodates time-varying treatments and confounders, as well as binary and failure time outcomes. ‘SEQTaRget’ allows to compare both static and dynamic strategies, can be used to estimate observational analogs of intention-to-treat and per-protocol effects, and can adjust for potential selection bias

Installation

You can install the development version of SEQ from GitHub with:

install.packages("devtools")
devtools::install_github("CausalInference/SEQTaRget", subdir = "SEQTaRget")

Setting up your Analysis

SEQuential uses R’s S4 object class system to handle function input/output. From the user side, this amounts to calling a helpful constructor SEQopts and then feeding that into SEQuential. SEQestimate can also take the provided options and return a (very rough) estimated time for analysis.

library(SEQTaRget)
data <- SEQdata

model <- SEQuential(data, id.col = "ID", time.col = "time",
                    eligible.col = "eligible", treatment.col = "tx_init", 
                    outcome.col = "outcome", 
                    time_varying.cols = c("N", "L", "P"),
                    fixed.cols = "sex",
                    method = "ITT",
                    options = SEQopts(km.curves = TRUE))

outcome(model)                       # Returns a list of all outcome models as S3 fastglm objects over the course of bootstrapping
diagnostics <- diagnostics(model)    # Returns a list of diagnostic tables
diagnostics$outcome.unique[[1]]      # Returns a table of unique outcomes
diagnostics$outcome.nonunique[[1]]   # Returns a table of nonunique outcomes

# Plotting
km_curve(model)[[1]]                 # Returns the Survival curve
km_data(model)[[1]]                  # Returns a dataframe of survival data in long-format for other analysis/plotting

Assumptions

This package places several assumptions onto the input data and unexpected results and errors may arise if these are not followed-

  1. User provided time.col begins at 0 per unique id.col entries, we also assume that the column contains only integers and continues by 1 for every time step. e.g. (0, 1, 2, 3, …) is allowed and (0, 1, 2, 2.5, …) or (0, 1, 2, 4, 5, …) are not.
    • Provided time.col entries may be out of order as a sort is enforced at the beginning of the function, e.g. (0, 2, 1, 4, 3, …) is valid because it begins at 0 and is continuously increasing by increments of 1, even though it is not ordered.
  2. eligible and column names provided to types of excused.cols are once one only one (with respect to time.col) flag variables

Return

The primary function, SEQuential, returns an S4 object of class SEQoutput with slots:

  1. params - the SEQparams object created through the SEQuential process
  2. DT - Expanded data table with weighting information
  3. outcome - outcome covariates
  4. numerator - numerator covariates when weighting
  5. denominator - denominator covariates when weighting
  6. outcome.model - fastglm model objects
  7. hazard - the hazard ratio
  8. weight.statistics - weighting information
  9. survival.curve - ggplot survival curve
  10. survival.data - survival and risk data for all points of followup
  11. risk.comparison - data table of comparisons between risks at end of followup bootstrapped
  12. risk.data - data table of risks for every level of treatment at each time point
  13. time - elapsed time for the SEQuential analysis
  14. info - list of diagnostic tables
  15. ce.model - Competing event model objects

These can be handily and easily printed to the terminal with by calling the object as model (if continuing the example above). While this this the shape of the output object, not all slots will always be filled, e.g. if a user providers hazard = TRUE, then the survival curves, data, and associated risks will return NA.

Imports

  • data.table
  • doFuture
  • doRNG
  • future
  • future.apply
  • ggplot2
  • fastglm
  • methods
  • stringr
  • survival
  • parallelly
  • knitr

Finding More Information and Examples

Further information on utilizing this package or developing it further is available with the SEQTaRget Pages as a part of this repository. If you are unable to find solutions or answers there, please feel free to open a discussion.

Contributing to the package

Community members are welcome to contribute to this package through several different avenues-

  • Asking/Answering questions about the package via GitHub Discussions. These can be questions about analysis methods, future planned developments for the package, or requests for clarity on package internals.
  • Contributing to GitHub Issues if a bug is found. We have a guided bug report to help us resolve unintended pests quickly.
  • Adding content to the package
    • If you intend to add to the package, we would prefer you to branch and then pull-request. This PR will need to:
      1. Pass current unit-tests to ensure nothing is being broken backwards.
      2. Add tests to added portions of code if they are not already covered in existing tests
      3. Pass R-CMD-Check (initiated on PR) with 0-0-0 status

Copy Link

Version

Install

install.packages('SEQTaRget')

Monthly Downloads

455

Version

1.3.5

License

MIT + file LICENSE

Maintainer

Ryan O'Dea

Last Published

February 5th, 2026

Functions in SEQTaRget (1.3.5)

numerator

Retrieves Numerator Models from SEQuential object
denominator

Retrieves Denominator Models from SEQuential object
outcome

Retrieves Outcome Models from SEQuential object
risk_comparison

Function to return risk information from a SEQuential object
risk_data

Function to return risk information from a SEQuential object
multinomial.summary

Helper function to get the summary table from multinomial
create.default.weight.covariates

Internal Function to create 'default' weighting formula
multinomial.predict

Helper to predict from the nested logistic
inline.pred

Helper Function to inline predict a fastglm object
internal.analysis

Internal analysis tool for handling parallelization/bootstrapping on multiple OS types
diagnostics

Function to return diagnostic tables from a SEQuential object
km_curve

Function to print Kaplan-Meier curves
compevent

Function to return competing event models from a SEQuential object
km_data

Function to return survival data from a SEQuential object
multinomial

Helper function for nested logistic
prepare.data_cached

Helper function to prepare data for fastglm
format.time

Nicely cleans time for readability
parameter.setter

Parameter Helper
internal.survival

Internal function for creating survival curves
internal.hazard

Generic function to format a dataset for hazard ratio calculation
parameter.simplifier

Simplifies parameters down for later use
internal.weights

Internal function for defining weights
internal.plot

Plotting for survival curves
show,SEQoutput-method

Show method for S4 object - SEQoutput.
prepare.output

Output constructor
internal.model

Internal function for fitting outcome models
SEQ_data

Function to return the internal data from a SEQuential object
SEQdata.multitreatment

Simulated multitreatment example data for SEQuential() multinomial models
SEQoutput-class

An S4 class used to hold the outputs for the SEQuential process
SEQopts

Parameter Builder for SEQuential Model and Estimates
SEQestimate

Estimate the (very rough) time to run SEQuential analysis on current machine
SEQuential

SEQuential trial emulation
covariates

Retrieves Outcome, Numerator, and Denominator Covariates
hazard_ratio

Function to return hazard ratios from a SEQuential object
create.default.covariates

Internal Function to create 'default' formula
init_formula_cache

Create formula cache
create.default.LTFU.covariates

Internal Function to create 'default' loss-to-followup formula
SEQparams-class

An internal S4 class to carry around parameters during the SEQuential process - inherits user facing parameters from SEQopts
SEQexpand

Creates an expanded dataset for use with SEQuential()
SEQdata.LTFU

Simulated lost-to-followup example data for SEQuential()
SEQdata

Simulated observational example data for SEQuential
SEQopts-class

An S4 class of user options to feed into the SEQuential processes and estimates This class should match SEQopts in file SEQopts.R
clean_fastglm

Function to clean out non needed elements from fastglm return
create.risk

Internal function to pull Risk Ratio and Risk Difference from data when km.curves = TRUE
SEQweights-class

An internal S4 class to help transfer weight statistics out of internal_weights