Learn R Programming

tvmediation

R package for fitting time-varying mediation models

Overview

This package includes a set of functions for estimating mediation effects that vary over time. The package allows a time-varying mediator and time-varying continuous or binary outcome. The treatment variable is assumed to be time-invariant and may have either two or three levels. Confidence intervals for the indirect effect are obtained via bootstrap. The goal of this method is to assess whether the indirect effect varies as a function of time.

Installation

To use the time varying mediation analysis package in R, you must first install the package and load it. Before that, make sure you have R version 4.0.3 or greater. There are two ways to install the package from the CRAN (Comprehensive R Archive Network) repository, by using install.packages or the devtools function.

install.packages("tvmediation", dependencies = TRUE)

The equivalent code using devtools is:

devtools::install_cran("tvmediation", dependencies = TRUE) 
# MAKE SURE YOU HAVE devtools INSTALLED

Alternatively, if you want to install the package directly from the GitHub repository to access new or revised functions in development, the following code may be used:

devtools::install_github("dcoffman/tvmediation", dependencies = TRUE) 
# MAKE SURE YOU HAVE devtools INSTALLED

Getting started

library(tvmediation)

Getting help

Summarized versions of the function vignettes can be accessed through this link. If you encounter a bug, please file a minimal reproducible example on GitHub.

Copy Link

Version

Install

install.packages('tvmediation')

Monthly Downloads

120

Version

1.1.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Donna Coffman

Last Published

May 25th, 2022

Functions in tvmediation (1.1.0)

estBootCIs

Bootstrapping samples to estimate mediation effects confidence intervals for continuous outcome and two treatment (exposure) groups.
bootci_tvmb

Bootstrap samples to estimate confidence intervals for the mediation effect for a binary outcome.
bootci_coeff_3trt

Bootstrap samples to estimate confidence intervals for coefficients for a continuous outcome and three treatment groups.
estCoeff

Function to estimate coefficients at time t.
LongToWide

Function to transpose the data from long to wide format
coeff

Function to estimate coefficients at time t
newMediatorOutcome

Function to compute new Mediator and Outcome using time t and t-1 mean centered on the individual.
bootci_tvm_3trt

Bootstrap samples to estimate confidence intervals for continuous outcome and three treatment groups.
bootci_coeff_binary

Bootstrap samples to estimate confidence intervals for binary outcome coefficients.
tvma

Time Varying Mediation Function: Continuous Outcome and Two Treatment Groups
smoker

Wisconsin Smokers' Health Study 2
smoothest

Function to compute local polynomial estimation using rule of thumb for bandwidth selection
tvma_3trt

Time Varying Mediation Function: Continuous Outcome and Three Treatment Groups
tvmb

Time Varying Mediation Function: Binary Outcome and Two Treatment Groups
bootci_coeff_2trt

Bootstrap function for computing CIs for coefficients for a continuous outcome and two treatment groups
tvmcurve_3trt

Main function for time varying mediation function for continuous outcome and three treatment arms (i.e., exposure groups).