SkillAgentSearch skills...

DevMSMs

Tools for using marginal structural models (MSMs) to answer causal questions in developmental science.

Install / Use

/learn @istallworthy/DevMSMs
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- README.md is generated from README.Rmd. Please edit that file -->

devMSMs: Implementing Marginal Structural Models (MSMs) <img src="https://raw.githubusercontent.com/istallworthy/devMSMs/main/inst/imgfile.png" align="right" width="100" alt="Structural Models"/> with Longitudinal Data

<!-- badges: start --> <!-- badges: end -->

Those who study and work with humans are fundamentally interested in questions of causation. More specifically, scientists, clinicians, educators, and policymakers alike are often interested in causal processes involving questions about when (timing) and at what levels (dose) different factors influence human functioning and development, in order to inform our scientific understanding and improve people’s lives. However, for many, conceptual, methodological, and practical barriers have prevented the use of methods for causal inference developed in other fields. <br>

The goal of this devMSMs package and accompanying tutorial paper, Investigating Causal Questions in Human Development Using Marginal Structural Models: A Tutorial Introduction to the devMSMs Package in R (<a href="https://osf.io/preprints/psyarxiv/284mb">preprint</a>), is to provide a set of tools for implementing marginal structural models (MSMs; Robins et al., 2000).

MSMs orginated in epidemiology and public health and represent one under-utilized tool for improving causal inference with longitudinal observational data, given certain assumptions. In brief, MSMs leverage inverse-probability-of-treatment-weights (IPTW) and the potential outcomes framework. MSMs first focus on the problem of confounding, using IPTW to attenuate associations between measured confounders and an exposure (e.g., experience, characteristic, event –from biology to the broader environment) over time. A weighted model can then be fitted relating a time-varying exposure and a future outcome. Finally, the model-predicted effects of different exposure histories that vary in dose and timing can be evaluated and compared as counterfactuals, to reveal putative causal effects. <br>

We employ the term exposure (sometimes referred to as “treatment” in other literatures) to encompass a variety of environmental factors, individual characteristics, or experiences that constitute the putative causal events within a causal model. Exposures may be distal or proximal, reflecting a developing child’s experience within different environments at many levels (Bronfenbrenner & Ceci, 1994), ranging from the family (e.g., parenting), home (e.g., economic strain), school (e.g., teacher quality), neighborhood (e.g., diversity), to the greater politico-cultural-economic context (e.g., inequality). Exposures could also reflect factors internal to the child, including neurodevelopmental (e.g., risk markers), physiological (e.g., stress), and behavioral (e.g., anxiety) patterns to which the child’s development is exposed.
<br>

Core Features

Core features of devMSMs include:

  • Flexible functions with built-in user guidance, drawing on established expertise and best practices for implementing longitudinal IPTW weighting and outcome modeling, to answer substantive causal questions about dose and timing

  • Functions that accept complete or imputed data to accommodate missingness often found in human studies

  • A novel recommended workflow, based on expertise from several disciplines, for using the devMSMs functions with longitudinal data (see Workflows vignettes)

  • An accompanying simulated longitudinal dataset, based on the real-world, Family Life Project (FLP) study of human development, for getting to know the package functions

  • An accompanying suite of <a href="https://github.com/istallworthy/devMSMsHelpers">helper functions</a> to assist users in preparing and inspecting their data prior to the implementation of devMSMs

  • Executable, step-by-step user guidance for implementing the devMSMs workflow and preliminary steps in the form of vignettes geared toward users of all levels of R programming experience, along with a <a href="https://github.com/istallworthy/devMSMs/blob/main/ExampleWorkflow.Rmd">R markdown template file</a>

  • A brief conceptual introduction, example empirical application, and additional resources in the accompanying tutorial paper

<br>

Overview

The package contains 7 core functions for implementing the two phases of the MSM process: longitudinal confounder adjustment and outcome modeling of longitudinal data with time-varying exposures. <br> <img src="https://raw.githubusercontent.com/istallworthy/devMSMs/main/man/figures/devMSMs_overview.png" alt="devMSMs overview" width="900"/> <br> <br>

Below is a summary of the terms used in the devMSMs vignettes and functions. More details and examples can be found in the accompanying manuscript. <br>

| Term | Definition | |-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Exposure | Exposure or experience that constitutes the causal event of interest and is measured at at least two time points, with at least one time point occurring prior to the outcome. | | Outcome | Any developmental construct measured at least once at a final outcome time point upon which the exposure is theorized to have causal effects. | | Exposure Time Points | Time points in development when the exposure was measured, at which weights formulas will be created. | | Exposure Epochs | (optional) Further delineation of exposure time points into meaningful units of developmental time, each of which could encompass multiple exposure time points, that together constitute exposure main effects in the outcome model and exposure histories. | | Exposure Histories | Sequences of relatively high ('h') or low ('l') levels of exposure at each exposure time point or exposure epoch. | | Exposure Dosage | Total cumulative exposure epochs/time points during which an individual experienced high (or low) levels of exposure, across an entire exposure history. | | Confounder | Pre-exposure variable that represents a common cause of exposure at a given time point and outcome; adjusting for all of which successfully blocks all backdoor paths. | | Time-varying confounder | A confounder that often changes over time (even if it is not measured at every time point), and is affected by prior exposure, either directly or indirectly. | | Time invariant confounder | A confounder that occurs only at a single time point, prior to the exposure and remains stable and/or is not possibly affected by exposure. | | Collider | A variable that represents a common effect of exposure at a given time point and outcome; adjusting for which introduces bias. |

<br>

Installation

devMSMs can be installed in R Studio from Github using the devtools package:

require(devtools, quietly = TRUE)
devtools::install_github("istallworthy/devMSMs")
library(devMSMs)
<br>

The helper functions can be installed from the accompanying devMSMsHelpers repo:

devtools::install_github("istallworthy/devMSMsHelpers")
library(devMSMsHelpers)
<br>

Recommended Workflow

We propose a recommended workflow for using devMSMs to answer causal questions with longituinal data. We suggest using the vignettes in the order they appear in the Articles tab. After reading the accompanying manuscript, We recommend first reviewing the <a href="https://istallworthy.github.io/devMSMs/articles/Terminology.html">Terminology</a> and <a href="https://istallworthy.github.io/devMSMs/articles/Data_Requirements.html">Data Requirements</a> vignettes as you begin preparing your data. We then recommend downloading the <a href="https://github.com/istallworthy/devMSMs/blob/main/ExampleWorkflow.Rmd">R markdown template file</a> which contains all the code described in the <a href="https://istallworthy.github.io/devMSMs/articles/Specify_Core_Inputs.html">Specify Core Inputs</a> and Workflows vignettes (for binary (TBA) or <a href="https://istallworthy.github.io/devMSMs/articles/Workflow_Continuous_Exposure.html">continuous</a> exposures) for implementing the steps below.

<img src="https://raw.githubusercontent.com/istallworthy/devMSMs/main/man/figures/devMSMs_schematic_of_workflow.png" alt="devMSMs schematic of workflow" width="1000"/> <br>

Citation & Bug Reports

Please cite yo

View on GitHub
GitHub Stars8
CategoryDevelopment
Updated16d ago
Forks3

Languages

HTML

Security Score

75/100

Audited on Mar 25, 2026

No findings