fastFMM: Fast Functional Mixed Models using Fast Univariate Inference

Erjia Cui, Gabriel Loewinger, Al XinOpenalex Unknown 2023 · DOI · OpenAlex

Abstract: Implementation of the fast univariate inference approach (Cui et al. (2022) doi:10.1080/10618600.2021.1950006, Loewinger et al. (2024) doi:10.7554/eLife.95802.2) for fitting functional mixed models. User guides and Python package information can be found at https://github.com/gloewing/photometry_FLMM.

Introduction

Functional Data Analysis (FDA) is the primary framework for analyzing data that exists as a continuum, such as time-series, growth curves, or spatial maps. However, when functional observations are nested within subjects or trials—requiring mixed-effects models—the computational burden increases exponentially. Traditional methods often fail to scale for "big" functional data, such as fiber photometry or EEG recordings, where each observation may contain thousands of time points. Researchers are frequently forced to choose between oversimplifying their data or enduring prohibitive computation times.

fastFMM is an R package designed to bridge this gap. It implements the Fast Univariate Inference (FUI) framework, allowing researchers to fit functional mixed models (FMMs) with unprecedented speed and perform rigorous statistical inference on high-dimensional longitudinal data.

The Fast Univariate Inference (FUI) Framework

The core of the package is the FUI algorithm, which operates in three distinct steps to achieve its efficiency:

  1. Massive Univariate Modeling: Instead of fitting one integrated model, the software fits a standard univariate mixed-effects model (using the lme4 engine) independently at every single point along the functional domain.
  2. Penalized Smoothing: To account for the continuous nature of the data, the package applies penalized splines across the functional domain to smooth the "raw" coefficient estimates from the first step.
  3. Joint Inference: fastFMM calculates both pointwise and joint confidence bands. For Gaussian data, it utilizes an efficient analytic approach; for non-Gaussian distributions, it supports various bootstrapping methods (e.g., cluster, case, or wild bootstrap).

Implementation and Features

The package is designed to be accessible to those familiar with standard mixed models, utilizing a syntax similar to the lme4 package. The primary function, fui, offers extensive flexibility for model configuration, including support for parallel computing and various smoothing methods.

Parameters of the core `fui` function, highlighting the flexibility in inference and smoothing methods.

Beyond standard fixed effects, the package supports concurrent models, where predictors themselves can be functional. This allows for the analysis of how one time-varying signal influences another over the same domain.

Key Results and Output

The efficiency of the FUI method allows it to handle functional domains with thousands of points where traditional FMM solvers would fail to converge. The fui function returns a comprehensive object that facilitates both statistical interpretation and visualization.

The structure of the `fui` output object, including estimated fixed effects and critical values for joint confidence intervals.

Key components of the output include:

  • betaHat: Estimated functional fixed effects.
  • qn: Critical values used to construct joint confidence intervals (CIs), which allow researchers to make inferences about the entire estimated curve rather than just individual points.
  • Integrated Visualization: The plot_fui function automates the plotting of functional coefficients alongside their uncertainty bands, aiding in the discovery of significant time windows.

Datasets

To demonstrate its utility in neuroscience, the package includes two real-world datasets:

  • d2pvt: Photometry recordings of D2+ neurons in the thalamus as mice receive different rewards (Machen et al., 2025).
  • lick: Photometry recordings of mesolimbic dopamine release during licking behavior (Jeong et al., 2022).

Limitations

While the analytic approach for Gaussian data is extremely fast, non-Gaussian models (e.g., Binomial or Poisson) require bootstrapping, which increases computational costs. Additionally, while the package includes an experimental impute_outcome feature using Functional Principal Component Analysis (FPCA) for missing values, its downstream effects are still being evaluated.

Summary updated

Abstract

Implementation of the fast univariate inference approach (Cui et al. (2022) &lt;<a href="https://doi.org/10.1080%2F10618600.2021.1950006" target="_top">doi:10.1080/10618600.2021.1950006</a>&gt;, Loewinger et al. (2024) &lt;<a href="https://doi.org/10.7554%2FeLife.95802.2" target="_top">doi:10.7554/eLife.95802.2</a>&gt;) for fitting functional mixed models. User guides and Python package information can be found at &lt;<a href="https://github.com/gloewing/photometry_FLMM" target="_top">https://github.com/gloewing/photometry_FLMM</a>&gt;.
BibTeX
@inproceedings{cui2023fastfmm,
  author = {Erjia Cui and Gabriel Loewinger and Al Xin},
  title = {{fastFMM: Fast Functional Mixed Models using Fast Univariate Inference}},
  booktitle = {Openalex Unknown},
  year = {2023},
  doi = {10.32614/cran.package.fastfmm},
}
Figure