Code to reproduce analyses and figures from the manuscript: "A Statistical Framework for Analysis of Trial-Level Temporal Dynamics in Fiber Photometry Experiments". This repository contains tutorials in both R and Python Jupyter notebooks.
In order to run this tutorial the following must be installed:
- The R Project for Statistical Computing (R)
fastFMM
R Package- Optionally Python dependencies if using the Jupyter notebook versions of the tutorials
For more information on installing R and system requirements see the official R documentation and the user guide for installing R, fastFMM
and rpy2
for Python in the Tutorials
folder.
Due to challenges with cross platform R environment management the R package dependencies are not managed with Renv. Download the fastFMM
by running the following command within
install.packages("fastFMM", dependencies = TRUE)
For more information see the fastFMM R package repo.
Additionally part IV of the Tutorial requires the following R packages to be installed:
install.packages('lmerTest')
install.packages('emmeans')
The tutorials are written in R and also Python. The fast-fmm-rpy2 package was created to wrap the fastFMM R package. This can be installed directly from PyPI, for example pip install fast-fmm-rpy2
. However for convenience all the Python dependencies required for these tutorials are managed using uv. The following instructions will get you started with uv.
- Install uv
uv can be installed from PyPI (ex. pip install uv
) or as a standalone installer. See uv docs for more info.
- Install Photometry_FLMM python dependencies
Use uv to create a virtual environment with Python installed and all Python dependencies as defined in the pyproject.toml file.
uv sync
- Add the uv managed venv as a Jupyter notebook kernel
uv run --with jupyter jupyter lab
See Using uv with Jupyter for more info.
Note
As the name implies fast-fmm-rpy2
uses the Python package rpy2
to wrap the R package. Refer to rpy2
documentation for troubleshooting or any issues loading shared C libraries.
-
Versions 3.6.0 and 3.6.1 of rpy2 have a known issue with Windows. See the GitHub issue for a full overview. The bug has been fixed and will ship in the next rpy2 release (3.6.2). In the mean time the rpy2 dependency has been rolled back to version <3.6.
-
If you encounter an issue with rpy2 not being able to find the shared C libraries rpy2 suggests setting the
LD_LIBRARY_PATH
environment variable:
export LD_LIBRARY_PATH="$(uv run python -m rpy2.situation LD_LIBRARY_PATH)":${LD_LIBRARY_PATH}
Note if you are not using uv to manage your environment remove uv run
from the command above.
-
If you encounter additional issues it may help to install RTools.
-
Check current rpy2 Windows issues on GitHub. Windows is not officially supported by rpy2 however the community works hard to make it functional and bug fixes are made.
For the fastFMM usage and a tutorial on package functions, please refer to fastFMM's Vignette.
-
$\textbf{Part 1}$ : Binary Variables -
$\textbf{Part 2}$ : Testing changes within a trial between 2 periods (baseline vs. cue period) -
$\textbf{Part 3}$ : Associations with continuous variables -
$\textbf{Part 4}$ : Testing Factor Variables -
$\textbf{Part 5}$ : Testing how signal–covariate associations change across trials/sessions
See the Tutorials
folder above for the datasets and Rmarkdown files used to generate the above guides.
-
$\textbf{Part 1}$ : Binary Variables -
$\textbf{Part 2}$ : Testing changes within a trial between 2 periods (baseline vs. cue period) -
$\textbf{Part 3}$ : Associations with continuous variables -
$\textbf{Part 4}$ : Testing Factor Variables -
$\textbf{Part 5}$ : Testing how signal–covariate associations change across trials/sessions
- Lawrimore, J., Loewinger, G., & Ptinis, A. (2025). fast-fmm-rpy2 (v1.0.2). Zenodo. https://doi.org/10.5281/zenodo.15653132
- Cui E, Loewinger G (2025). fastFMM: Fast Functional Mixed Models using Fast Univariate Inference. R package version 0.4.0, https://github.com/gloewing/fastfmm
- Cui et al. (2022) Implementation of the fast univariate inference approach
- Loewinger et al. (2024) A statistical framework for analysis of trial-level temporal dynamics in fiber photometry experiments.