dynCorr: Dynamic Correlation Package

Joel A. Dubin, Mike Li, Dandi Qiao, Hans‐Georg MüllerOpenalex Unknown 2012 · OpenAlex

Abstract

The dynCorr R package provides a specialized toolkit for calculating dynamic correlation between pairs of longitudinal data series. Unlike static correlation measures, it accounts for temporal dependencies, allows for time lags, and can even correlate the derivatives (rates of change) of the variables, providing both point estimates and bootstrap-based confidence intervals.

Introduction

Standard correlation coefficients, such as Pearson’s $r$, are often inadequate for longitudinal data—measurements taken repeatedly over time for the same subjects. These traditional methods struggle with the inherent temporal structure of the data. For instance, two variables might be highly correlated, but one might "lead" the other by several days (a lag), or the real relationship might exist between their trends rather than their raw values.

The dynCorr package implements the methodology developed by Dubin and Müller (2005) to bridge this gap. It allows researchers to quantify how two time-varying processes relate to one another while accounting for smoothing, lags, and the specific dynamics of the curves.

Methodology and Implementation

The package relies on a multi-step statistical pipeline to move from raw longitudinal data to sophisticated correlation estimates.

Data Requirements

To utilize the package, data must be structured in a specific format. The core functions require a data frame containing dependent variables, independent variables (typically time), and subject identification.

Core data input parameters for the dynCorr package.

Statistical Pipeline

  1. Local Polynomial Smoothing: Before calculating correlation, the discrete data points for each subject are converted into continuous curves using local polynomial regression. The package specifically utilizes the lpepa function (from the lpridge package) with Epanechnikov kernel weighting.
  2. Dynamic Correlation Estimation: The core function, dynamicCorrelation, calculates the correlation between these smoothed curves. Users can specify whether they want to correlate the original functions (0th derivative), their slopes (1st derivative), or their acceleration (2nd derivative).
  3. Lag Analysis: Users can input a range of lags to see if the correlation improves when one variable is shifted in time relative to the other.
  4. Two-Stage Bootstrapping: The bootstrapCI function generates percentile bootstrap confidence intervals. This is a computationally intensive process that accounts for the uncertainty introduced during both the curve-smoothing and the correlation-estimation phases.
Advanced parameters for lag analysis and bootstrap confidence intervals.

Key Features and Insights

  • Beyond the "Now": The inclusion of lag.input is a powerful feature for longitudinal research. It allows scientists to move beyond simultaneous correlation and discover "lead-lag" relationships where one biological or physical process precedes another.
  • The Importance of Derivatives: By allowing correlation of 1st and 2nd derivatives, the package enables researchers to ask: "Is the rate of increase in Variable A correlated with the value of Variable B?" This is often more informative in dynamic systems than simple value-to-value comparisons.
  • Accounting for Smoothing Error: The authors acknowledge that the curve-creation step introduces error. To handle this, the bootstrap confidence intervals are intentionally shifted slightly toward zero—a conservative approach designed to prevent overestimating the strength of a relationship.

Datasets

The package includes a built-in dataset, dynCorrData, for demonstration and testing. This contains three longitudinal responses for 34 subjects, with measurements taken every ten days. It is specifically structured to showcase different types of relationships: a moderate positive dynamic correlation between the first and third responses, and lesser negative correlations between others.

Conclusion and Future Directions

The dynCorr package provides a streamlined way to move from raw longitudinal data frames to sophisticated dynamic correlation estimates. While powerful, the documentation notes that bootstrapCI is currently slow because it must re-process the entire smoothing and estimation pipeline for every bootstrap sample. Future versions will focus on boosting computing speed and making the bootstrap approach more robust for high-magnitude correlations.

Summary updated

BibTeX
@inproceedings{dubin2012dyncorr,
  author = {Joel A. Dubin and Mike Li and Dandi Qiao and Hans‐Georg Müller},
  title = {{dynCorr: Dynamic Correlation Package}},
  booktitle = {Openalex Unknown},
  year = {2012},
  doi = {10.32614/cran.package.dyncorr},
}
Figure