Learn R Programming

TrialEmulation

This package implements algorithms to conduct a sequence of target trials analysis.

Installation

The package is available on CRAN:

install.packages('TrialEmulation')

To install the latest development version from github:

remotes::install_github("Causal-LDA/TrialEmulation")

Getting Started

Please see our Getting Started vignette for information on how to work with this package.

A manuscript is in preparation to fully describe the methodology.

Copy Link

Version

Install

install.packages('TrialEmulation')

Monthly Downloads

540

Version

0.0.5

License

Apache License (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Isaac Gravestock

Last Published

August 25th, 2026

Functions in TrialEmulation (0.0.5)

parsnip_model

Fit outcome models using parsnip models
predict_marginal

Predict marginal cumulative incidences with confidence intervals for a target trial population
fit_outcome_model

Method for fitting outcome models
outcome_data

Outcome Data Accessor and Setter
expand_trials

Expand trials
ipw_data

IPW Data Accessor and Setter
read_expanded_data

Method to read expanded data
load_expanded_data

Method to read, subset and sample expanded data
sample_expanded_data

Internal method to sample expanded data
save_to_duckdb

Save expanded data to DuckDB
save_expanded_data

Method to save expanded data
save_to_csv

Save expanded data as CSV
robust_calculation

Robust Variance Calculation
set_expansion_options

Set expansion options
te_data-class

TrialEmulation Data Class
save_to_datatable

Save expanded data as a data.table
print.TE_weight_summary

Print a weight summary object
show_weight_models

Show Weight Model Summaries
set_outcome_model

Specify the outcome model
set_censor_weight_model

Set censoring weight model
summary.TE_data_prep

Summary methods
select_data_cols

Select Data Columns
stats_glm_logit

Fit outcome models using stats::glm
te_model_fitter-class

Outcome Model Fitter Class
te_outcome_fitted-class

Fitted Outcome Model Object
te_outcome_data-class

TrialEmulation Outcome Data Class
te_model_ex

Example of a fitted marginal structural model object
set_switch_weight_model

Set switching weight model
set_data

Set the trial data
te_data_ex

Example of a prepared data object
te_outcome_model-class

Fitted Outcome Model Object
te_datastore-class

te_datastore
te_datastore_csv-class

te_datastore_csv, functions and methods
te_datastore_duckdb-class

te_datastore_duckdb, functions and methods
trial_msm

Fit the marginal structural model for the sequence of emulated trials
weight_model_data_indices

Data used in weight model fitting
te_parsnip_model-class

Fit Models using parsnip
trial_sequence

Create a sequence of emulated target trials object
trial_sequence-class

Trial Sequence class
vignette_switch_data

Example of expanded longitudinal data for sequential trial emulation
te_stats_glm_logit-class

Fit Models using logistic stats::glm
trial_example

Example of longitudinal data for sequential trial emulation
expand

Expand Function
calculate_weights

Calculate Inverse Probability of Censoring Weights
case_control_sampling_trials

Case-control sampling of expanded data for the sequence of emulated trials
data_preparation

Prepare data for the sequence of emulated target trials
fit_weights_model

Method for fitting weight models
fit_msm

Fit the marginal structural model for the sequence of emulated trials
initiators

A wrapper function to perform data preparation and model fitting in a sequence of emulated target trials
data_manipulation

Data Manipulation Function
expand_until_switch

Check Expand Flag After Treatment Switch
check_newdata

Check Data used for Prediction
TrialEmulation-package

TrialEmulation Package
censor_func

Censoring Function in C++
data_censored

Example of longitudinal data for sequential trial emulation containing censoring
calculate_predictions

Calculate and transform predictions
internal-methods

Internal Methods