Estimating fMRI timescale maps.
The 2 matches
- [1] § Methods › Estimation of standard errors › Time-domain standard error estimator ↔ fmri_timescales/timescale_utils.py, lines 133–256 · score 0.64 · Bartlett kernel, lag truncation, weighted, regression, standard errors, domain
- [2] § Simulations › Simulation settings ↔ fmri_timescales/sim.py, lines 9–62 · score 0.55 · multivariate normal distribution, Cholesky, matrix, Toeplitz, simulate, ACFs
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 256 lines · 9.2 KB · MIT · 1 match
- from typing import Optional
- import numpy as np
- from joblib import Parallel, delayed
- from scipy.optimize import curve_fit
- from sklearn.base import BaseEstimator
- from fmri_timescales import acf_utils
- def newey_west_omega(u: np.ndarray, n_lags: int | None = None) -> float:
- n_u = len(u)
- if n_lags is None:
- n_lags = int(np.floor(4 * (n_u / 100.0) ** (2 / 9)))
- weights = 1 - np.arange(n_lags + 1) / (n_lags + 1)
- omega = weights[0] * np.sum(u**2)
- for lag in range(1, n_lags + 1):
- omega += weights[lag] * (2 * np.sum(u[lag:] * u[:-lag]))
- return omega
- def _phi_to_tau(phis: np.ndarray, se_phis: np.ndarray, lag: int = 1) -> tuple:
- """phi to tau (timescale), and apply delta method to std err"""
- phis_abs = np.abs(phis) # tau undefined for negative phi
- taus = -lag / np.log(phis_abs)
- se_taus = (lag / (phis_abs * np.log(phis_abs) ** 2)) * se_phis
- return taus, se_taus
- class TD(BaseEstimator):
- """Time Domain (TD) Linear Model, Fit by Linear Least Squares.
- Parameters
- ----------
- var_estimator : str, optional
- The variance estimator to use. Options are "newey-west" or "non-robust", by default "newey-west"
- var_n_lags : int, optional
- The lag truncation number for the bartlett kernel, by default None
- copy_X : bool, optional
- If True X will be copied, else it may be overwritten, by default False
- n_jobs : int, optional
- The number of jobs to use for the computation, by default None
- Attributes
- ----------
- estimates_ : dict
- A dictionary containing four np.ndarray of shape (n_regions, ):
- - "phi": AR(1) coefficient estimates, for each region in X.
- - "se(phi)": Standard errors of AR(1) coefficients.
- - "tau": Timescale estimates, for each region in X.
- - "se(tau)": Standard errors of timescales.
- Examples
- --------
- >>> from fmri_timescales import sim, timescale_utils
- >>> X = sim.sim_ar(ar_coeffs=[0.8], n_timepoints=1000) # x_t = 0.8 x_{t-1} + e_t
- >>> td = timescale_utils.TD(var_estimator="newey-west", var_n_lags=10)
- >>> td.fit(X=X, n_timepoints=1000).estimates_
- {'phi': array([0.79789847]), 'se(phi)': array([0.02045074]), 'tau': array([4.42920958]), 'se(tau)': array([0.50282146])}
- """
- def __init__(
- self,
- var_estimator: str = "newey-west",
- var_n_lags: int | None = None,
- copy_X: bool = False,
- n_jobs: int | None = None,
- ) -> None:
- self.var_estimator = var_estimator
- self.var_n_lags = var_n_lags
- self.copy_X = copy_X
- self.n_jobs = n_jobs
- @delayed
- def _fit_td(self, x: np.ndarray) -> tuple:
- """fit model to a single timeseries x in X"""
- T = len(x) - 1
- # x_t = X[1:], x_{t-1} = x[:-1] (Hz=1)
- phi_ = np.sum(x[1:] * x[:-1]) / np.sum(x[:-1] ** 2)
- # variance estimators
- def non_robust():
- e_ = x[1:] - phi_ * x[:-1]
- q_ = np.sum(x[:-1] ** 2)
- sigma2_ = (1 / T) * np.sum(e_**2)
- return (1 / q_) * sigma2_
- def newey_west():
- e_ = x[1:] - phi_ * x[:-1]
- q_ = np.sum(x[:-1] ** 2)
- u_ = x[:-1] * e_
- omega_ = newey_west_omega(u_, n_lags=self.var_n_lags)
- return (1 / q_) * omega_ * (1 / q_)
- var_estimators = {"non-robust": non_robust, "newey-west": newey_west}
- if self.var_estimator not in var_estimators:
- raise ValueError("var_estimator must be either 'newey-west' or 'non-robust'")
- var_ = var_estimators[self.var_estimator]()
- return phi_, np.sqrt(var_)
- def fit(self, X: np.ndarray, n_timepoints: int):
- """Fit the TD model.
- Parameters
- ----------
- X : np.ndarray of shape (n_timepoints, n_regions)
- An array containing the timeseries of each region.
- n_timepoints : int
- The number of timepoints in X.
- Raises
- ------
- ValueError
- If `X` is not in (n_timepoints, n_regions) form.
- """
- if X.ndim != 2 or X.shape[0] != n_timepoints:
- raise ValueError("X should be in (n_timepoints, n_regions) form")
- X = X.copy() if self.copy_X else X
- X = (X - X.mean(axis=0)) / X.std(axis=0) # mean zero, variance 1
- with Parallel(n_jobs=self.n_jobs) as parallel:
- td_fits = parallel(self._fit_td(X[:, idx]) for idx in range(X.shape[1]))
- phis_, se_phis_ = map(np.array, zip(*td_fits))
- taus_, se_taus_ = _phi_to_tau(phis_, se_phis_)
- self.estimates_ = {"phi": phis_, "se(phi)": se_phis_, "tau": taus_, "se(tau)": se_taus_}
- return self
- class AD(BaseEstimator):
- """Autocorrelation Domain (AD) Nonlinear Model, fit by Nonlinear Least Squares.
- Parameters
- ----------
- var_estimator : str, optional
- The variance estimator to use. Options are "newey-west" or "non-robust", by default "newey-west"
- var_n_lags : int, optional
- The lag truncation number for the bartlett kernel, by default None
- acf_n_lags : int, optional
- The lag truncation number for the autocorrelation function, by default None
- copy_X : bool, optional
- If True X will be copied, else it may be overwritten, by default False
- n_jobs : _type_, optional
- The number of jobs to use for the computation, by default None
- Attributes
- ----------
- estimates_ : dict
- A dictionary containing two np.ndarray of shape (n_regions, ):
- - "tau": Timescale estimates, for each region in X.
- - "se(tau)": Standard errors of timescales.
- Examples
- --------
- >>> from fmri_timescales import sim, timescale_utils
- >>> X = sim.sim_ar(ar_coeffs=[0.8], n_timepoints=1000) # x_t = 0.8 x_{t-1} + e_t
- >>> ad = timescale_utils.AD(var_estimator="newey-west", var_n_lags=10, acf_n_lags=50)
- >>> ad.fit(X=X, n_timepoints=1000).estimates_
- {'phi': array([0.78021651]), 'se(phi)': array([0.02814532]), 'tau': array([4.02927146]), 'se(tau)': array([0.58565806])}
- """
- def __init__(
- self,
- var_estimator: str = "newey-west",
- var_n_lags: int | None = None,
- acf_n_lags: int | None = None,
- copy_X: bool = False,
- n_jobs: int | None = None,
- ) -> None:
- self.var_estimator = var_estimator
- self.var_n_lags = var_n_lags
- self.acf_n_lags = acf_n_lags
- self.copy_X = copy_X
- self.n_jobs = n_jobs
- @delayed
- def _fit_ad(self, x: np.ndarray) -> tuple:
- """fit model to a single timeseries/autocorrelation function x in X"""
- T = len(x)
- # acf estimator
- x_acf = acf_utils.ACF(n_lags=self.acf_n_lags + 1).fit_transform(x.reshape(-1, 1), T).squeeze()[1:]
- # regression function (m), and its linearized regressor (dm_dphi)
- ks = np.arange(1, len(x_acf) + 1)
- def m(ks, phi):
- return phi**ks
- def jac(ks, phi):
- return (ks * phi ** (ks - 1)).reshape(-1, 1)
- # phi estimator
- eps = 1e-10
- phi_, _ = curve_fit(f=m, xdata=ks, ydata=x_acf, p0=1e-2, bounds=(-1 + eps, +1 - eps), ftol=1e-6, jac=jac)
- phi_ = phi_.squeeze()
- # variance estimators
- def non_robust():
- e_ = x[1:] - phi_ * x[:-1]
- q_ = np.sum(x[:-1] ** 2)
- sigma2_ = (1 / T) * np.sum(e_**2)
- return (1 / q_) * sigma2_
- def newey_west():
- q_ = np.sum((ks * phi_ ** (ks - 1)) ** 2)
- weights = ks * (phi_ ** (ks - 1))
- weights_phi = weights * (phi_**ks)
- conv1 = np.convolve(x, weights, mode="full")
- conv2 = np.convolve(x**2, weights_phi, mode="full")
- u_ = x[len(ks) : T] * conv1[len(ks) - 1 : T - 1] - conv2[len(ks) - 1 : T - 1]
- omega_ = (1 / len(u_) ** 2) * newey_west_omega(u_, n_lags=self.var_n_lags)
- return (1 / q_) * omega_ * (1 / q_)
- var_estimators = {"non-robust": non_robust, "newey-west": newey_west}
- if self.var_estimator not in var_estimators:
- raise ValueError("var_estimator must be either 'newey-west' or 'non-robust'")
- var_ = var_estimators[self.var_estimator]()
- return phi_, np.sqrt(var_)
- def fit(self, X: np.ndarray, n_timepoints: int):
- """Fit the AD model.
- Parameters
- ----------
- X : np.ndarray of shape (n_timepoints, n_regions)
- An array containing the timeseries of each region.
- n_timepoints : int
- The number of timepoints in X.
- Raises
- ------
- ValueError
- If `X` is not in (n_timepoints, n_regions) form.
- """
- if X.ndim != 2 or X.shape[0] != n_timepoints:
- raise ValueError("X should be in (n_timepoints, n_regions) form")
- X = X.copy() if self.copy_X else X
- X = (X - X.mean(axis=0)) / X.std(axis=0) # mean zero, variance 1
- if self.acf_n_lags is None:
- self.acf_n_lags = n_timepoints // 100
- with Parallel(n_jobs=self.n_jobs) as parallel:
- ad_fits = parallel(self._fit_ad(X[:, idx]) for idx in range(X.shape[1]))
- phis_, se_phis_ = map(np.array, zip(*ad_fits))
- taus_, se_taus_ = _phi_to_tau(phis_, se_phis_)
- self.estimates_ = {"phi": phis_, "se(phi)": se_phis_, "tau": taus_, "se(tau)": se_taus_}
- return self
timescale_utils.py at commit cd0072e, under MIT · at the source
Overview
- Halicioğlu Data Science Institute, University of California San Diego, La Jolla, CA, United States
- Division of Biostatistics, University of California San Diego, La Jolla, CA, United States
- Department of Cognitive Science, University of California San Diego, La Jolla, CA, United States
- Neurosciences Graduate Program, University of California San Diego, La Jolla, CA, United States
Abstract
Brain activity unfolds over hierarchical timescales that reflect how brain regions integrate and process information, linking functional and structural organization. While timescale studies are prevalent, existing estimation methods rely on the restrictive assumption of exponentially decaying temporal autocorrelation and only provide point estimates without standard errors, limiting statistical inference. In this paper, we formalize and evaluate two methods for mapping timescales in resting-state fMRI: a time-domain fit of an autoregressive (AR1) model and an autocorrelation-domain fit of an exponential decay model. Rather than assuming exponential autocorrelation decay, we define timescales by projecting the fMRI time series onto these approximating models, requiring only stationarity and mixing conditions while incorporating robust standard errors to account for model misspecification. We introduce theoretical properties of timescale estimators and show parameter recovery in realistic simulations, as well as applications to fMRI from the Human Connectome Project. Comparatively, the time-domain method produces more accurate estimates under model misspecification, remains computationally efficient for high-dimensional fMRI data, and yields maps aligned with known functional brain organization. In this work, we show valid statistical inference on fMRI timescale maps, and provide Python implementations of all methods.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 2 matches between paragraphs and lines of code.
griegner/fmri-timescales
cd0072ee3b42f271e49de3682d5f7a41bb9070d2, 18 May 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
21 files
- fmri_timescales/
__init__.py , Python, 3 lines - fmri_timescales/
acf_utils.py , Python, 130 lines - fmri_timescales/
plts.py , Python, 36 lines - fmri_timescales/
sim.py , Python, 177 lines, 1 match - fmri_timescales/
timescale_utils.py , Python, 256 lines, 1 match - notebooks/
fig01to03.ipynb , Jupyter, 151 lines - notebooks/
fig01to03.py , Python, 183 lines - notebooks/
fig04to05.ipynb , Jupyter, 134 lines - notebooks/
fig04to05.py , Python, 97 lines - notebooks/
fig06to07.ipynb , Jupyter, 54 lines - notebooks/
fig06to07.py , Python, 97 lines - notebooks/
sup_autoregression.ipynb , Jupyter, 195 lines - notebooks/
sup_autoregression.py , Python, 74 lines - notebooks/
sup_hcp-description.ipyn , Jupyter, 143 linesb - notebooks/
sup_neuromaps.ipynb , Jupyter, 94 lines - tests/
test_acf_utils.py , Python, 63 lines - tests/
test_plts.py , Python, 10 lines - tests/
test_sim.py , Python, 114 lines - tests/
test_timescale_utils.py , Python, 96 lines - LICENSE, License, 21 lines
- README.md, Text, 105 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 19 scripts, each with its path and the digest of its content;
- 2 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data and Code Availability
All simulation results and fMRI timescale maps, inclusive of the code by which they were derived, can be accessed on https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 4 authors, 6 keywords, 2 funders, 55 references.
Cite
This paper
Riegner, G., Davenport, S., Voytek, B., & Schwartzman, A. (2026). Estimating fMRI timescale maps. Imaging neuroscience (Cambridge, Mass.), 4, IMAG.a.1248. https://
BibTeX
@article{riegner2026esti
author = {Riegner, Gabriel and Davenport, Samuel and Voytek, Bradley and Schwartzman, Armin},
title = {{Estimating fMRI timescale maps}},
journal = {Imaging neuroscience (Cambridge, Mass.)},
year = {2026},
month = jun,
volume = {4},
pages = {IMAG.a.1248},
publisher = {MIT Press},
issn = {2837-6056},
doi = {10.1162/
url = {https://
pmid = {42253608},
pmcid = {PMC13237991}
}
RIS
TY - JOUR
AU - Riegner, Gabriel
AU - Davenport, Samuel
AU - Voytek, Bradley
AU - Schwartzman, Armin
TI - Estimating fMRI timescale maps
T2 - Imaging neuroscience (Cambridge, Mass.)
J2 - Imaging Neurosci (Camb)
PY - 2026
DA - 2026/
VL - 4
SP - IMAG.a.1248
SN - 2837-6056
PB - MIT Press
DO - 10.1162/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1162/
"type": "article-journal",
"title": "Estimating fMRI timescale maps",
"container-title": "Imaging neuroscience (Cambridge, Mass.)",
"author": [
{
"family": "Riegner",
"given": "Gabriel"
},
{
"family": "Davenport",
"given": "Samuel"
},
{
"family": "Voytek",
"given": "Bradley"
},
{
"family": "Schwartzman",
"given": "Armin"
}
],
"container-title-short":
"volume": "4",
"page": "IMAG.a.1248",
"DOI": "10.1162/
"PMID": "42253608",
"PMCID": "PMC13237991",
"ISSN": "2837-6056",
"publisher": "MIT Press",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
4
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1038/s41467-026-74466-2 [code]
- Neuromorphic hierarchical modular reservoirs.Journal: Nature communicationsIn common: neuromaps, Nilearn, NiBabel, 6 other tools, 11 references
- [2] doi:10.1162/imag.a.1275 [code]
- Glucose metabolism echoes long-range temporal correlations in the human brain.Journal: Imaging neuroscience (Cambridge, Mass.)In common: NiBabel, scikit-learn, pandas, 3 other tools, fMRI, 9 references
- [3] doi:10.1038/s41540-026-00727-x [code]
- Association-sensory spatiotemporal hierarchy and functional gradient-regularised recurrent neural network with implications for schizophrenia.Journal: NPJ systems biology and applicationsIn common: statsmodels, pandas, SciPy, 2 other tools, 9 references
- [4] doi:10.1093/cercor/bhag121 [code]
- Preserved intrinsic neural timescale organization with hierarchical variation in autism spectrum disorder.Journal: Cerebral cortex (New York, N.Y. : 1991)In common: 10 references
- [5] doi:10.1038/s41467-026-75959-w [code]
- Charting higher-order models of brain function beyond pairwise interactions.Journal: Nature communicationsIn common: neuromaps, Nilearn, NiBabel, 6 other tools, 4 references
- [6] doi:10.7554/elife.110294 [code]
- Arousal modulates functional connectivity through structured and hemispherically asymmetric community architecture during wakefulness.Journal: eLifeIn common: neuromaps, NiBabel, statsmodels, 5 other tools, fMRI, 4 references
- [7] doi:10.21203/rs.3.rs-9326213/v1 [code]
- Multi-task fMRI outperforms resting-state fMRI for revealing task-invariant organization of the human brainJournal: Research Square (preprint)In common: neuromaps, Nilearn, NiBabel, 5 other tools, fMRI, 4 references
- [8] doi:10.64898/2026.03.09.710558 [code]
- Multi-task fMRI outperforms resting-state fMRI for revealing task-invariant organization of the human brainJournal: bioRxiv (preprint)In common: neuromaps, Nilearn, NiBabel, 5 other tools, fMRI, 4 references
- [9] doi:10.1038/s41467-026-72931-6 [code]
- Three parsimonious spatiotemporal patterns in cerebellum reveal individual traits in function and behavior.Journal: Nature communicationsIn common: Nilearn, NiBabel, statsmodels, 5 other tools, fMRI, 4 references
- [10] doi:10.1162/netn.a.547 [code]
- An evaluation of the efficacy of single-echo and multi-echo fMRI denoising strategies.Journal: Network neuroscience (Cambridge, Mass.)In common: Nilearn, NiBabel, statsmodels, 5 other tools, fMRI, 3 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 19 scripts, and 2 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:7f7bc17ae994fd0e…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
