Skip to content

fmrihrf

0.4.0Package record

Hemodynamic Response Functions for fMRI Data Analysis

0packages depend
5.3Kdownloads / year
81.4%test coverage
13/13flavors OK

Overview

About

Creates, manipulates, and evaluates hemodynamic response functions and event-related regressors for functional magnetic resonance imaging data analysis. Supports multiple basis sets including Canonical, Gamma, Gaussian, B-spline, and Fourier bases. Features decorators for time-shifting and blocking, and efficient convolution algorithms for regressor construction. Methods are based on standard fMRI analysis techniques as described in Jezzard et al. (2001, ISBN:9780192630711).

Changes in 0.4.0

Breaking changes

  • block_hrf(normalize = TRUE) now computes each basis's absolute-peak normalization factor once, over the full blocked span, using the fixed reference-grid policy of normalize_hrf(..., "unit_peak_per_basis"). Previously each call normalized against its requested times: a scalar evaluation could become 1 even far from the peak, and the convolution and loop methods could disagree. Scalar, vector, and chunked queries now retain the same scale. Negative responses keep their sign and zero bases stay zero. Rebuild designs and refit analyses that used normalized blocked HRFs.
  • Every positive block_hrf() width is now integrated, including widths below precision. Previously a short block returned the unintegrated impulse response, creating a discontinuity when width crossed the numerical step. width = 0 retains the impulse convention. With summate = FALSE, the integral is divided by width; with finite half_life, decay attenuates the integrand but does not renormalize the averaging weights.
Show all changes in 0.4.0Hide the rest of the changes in 0.4.0
  • hrf_bspline(), hrf_bspline_generator() and HRF_BSPLINE now return a basis that is zero at both ends of the span. Previously the last basis function equalled 1 at span and was cut to 0 beyond it, so any weight on it produced a step at the end of every response. The N functions are now the interior functions of a clamped basis with N + 2 functions (the same construction as fmrireg::estimate_hrf()). Fitted coefficients and design matrices built from these bases change; N must be at least degree - 1. The tent basis (hrf_tent_generator(), getHRF("tent"), and hrf_bspline(degree = 1)) changes the same way: its tents now peak at interior knots and the basis is zero at both ends (with N = 5 over 24 s, peaks at 4, 8, ..., 20 s instead of 4.8, ..., 24 s).
  • hrf_weighted(method = "constant") now uses every weight: n weights fill n bins. With width, the window is split into n equal bins; with times, weight i covers [times[i], times[i + 1]) and the last bin is as wide as the one before it. Previously the last weight only closed the window (and was returned at the single time times[n]). normalize = TRUE now makes all n weights sum to 1. The method = "linear" form is unchanged. Weight vectors that ended with a 0 as an end marker give the same values as before, with span one bin longer.
  • Corrected the documentation of normalize in hrf_boxcar() and hrf_weighted(). A unit-area boxcar makes the GLM coefficient the integrated signal in the window, not its mean, and a weighted HRF's coefficient is a least-squares amplitude, not a weighted mean. Behaviour is unchanged.

Plotting

  • New hrf_palette() and matching ggplot2 scales scale_colour_hrf(), scale_color_hrf() and scale_fill_hrf(). The categorical palette has at least 3:1 contrast on white and near-black backgrounds and stays distinguishable under common colour-vision deficiencies; the ordered palette is for basis functions and parameter sweeps. All package plots use them.
  • plot_hrfs() and plot_regressors() now plot every column of a basis set (basis = "first" restores the old behaviour), accept layout = "stack" for one panel per curve, and choose the palette with palette. plot_hrfs() gains reference for a dashed grey comparison curve. plot_regressors() accepts a regressor_set(), draws events as bars whose width is the event duration, and shows scan-time values with samples.
  • plot_regressors(), plot.Reg() and plot.FeatureReg() evaluate with a precision matched to the plotting grid by default (precision = NULL), so sharp HRF edges are drawn where they occur.
  • Inside knitr documents, plot_hrfs() and plot_regressors() return their result visibly and let knitr print the plot, like a ggplot object. This lets document themes add dark-mode figure versions. Assigning the result inside a chunk no longer draws it; print it explicitly.
  • The base-graphics plot() methods use the same palette, mark onsets with ticks on the time axis, and draw multi-basis regressors one panel per basis function (layout = "overlay" for the old style).
  • All vignette figures were redrawn with these helpers; the reconstruction section of the advanced vignette now fits basis weights to target HRFs.

Improvements

  • Improved vignette plots for narrow screens: compact legends, shared-axis panels for gamma libraries and reconstruction, and visible light/dark series colors. Comparison helpers respect the active ggplot2 theme and accept draw = FALSE for customization or vignette auto-printing.
  • Fixed clipped peak annotations and respected onset transparency in event and feature-regressor plots. Clarified the spline example's 24-second support without changing its evaluated values.
  • Updated the website and vignettes to albersdown 2.1.0. Vignettes now use its self-contained output format with light, dark, and phone-sized figures, replacing the copied theme assets. Figure resolution is limited to keep the source package compact.
  • Added feature_regressor() for continuously sampled features (for example RMS energy). Each sample is a zero-order-hold bin of width dt, with optional pre-convolution centering and scaling. This is the continuous analogue of an amplitude-modulated event train, not a list of trials.
  • Added fixed-scale HRF normalization with normalize_hrf() and the hrf_norm argument to gen_hrf() and getHRF(). Modes include Nilearn/SPM reference-grid scaling, unit peak, unit integral, and independent per-basis unit peaks. The existing normalise_hrf() and normalize = TRUE interfaces retain their per-basis unit-peak behavior.
  • Factored the duplicated single-basis / multi-basis branching in block_hrf(), evaluate.HRF(), and normalise_hrf() into three internal helpers (.weighted_combine, .normalise_result, .get_peaks). No user-visible behavior change.

Convolution engine consolidation

The package carried four evaluation engines. conv provided the best

speed/accuracy tradeoff in development benchmarks, so there is now one compiled

convolution engine.

  • method = "conv" remains the default and is the only compiled convolution engine. It avoids FFT zero-padding overhead and is substantially faster than loop on large designs; exact speedups depend on design size, basis count, and precision.
  • method = "fft" and method = "Rconv" are deprecated. They now evaluate via conv and warn. The FFT engine never repaid its zero-padding, because the HRF is short relative to the sampled design, and it was the only method that could fail outright (on an internal FFT size above ~1e7). Rconv was an R reimplementation of conv that silently fell back to loop whenever the grid was irregular or durations varied. Both implementations have been removed.
  • method = "loop" is retained as the reference implementation. It can be more accurate at a given precision because event onsets are evaluated directly, and it remains the automatic fallback for regressors built from a list of per-event HRFs.
  • Event onsets and block edges are no longer snapped to the internal grid. Each is placed at its exact sub-bin position, substantially reducing off-grid error at the default precision = 0.33. Blocks are projected onto the linear hat basis, preserving trapezoid accuracy while keeping the exact edge placement.
  • method = "loop" no longer truncates blocked events at hrf_span. It now extends to hrf_span + duration, removing a residual error that did not shrink as precision decreased. Its support calculation no longer assumes a multi-point regular grid, so one-point and irregular grids work as well. Blocks whose onset precedes the requested grid are retained when their duration carries the response into it.

Bug Fixes

  • Let the generated Rcpp wrapper translate native exceptions after C++ stack unwinding, removing the remaining direct Rf_error() call (issue #42).
  • Clarified that summate = FALSE computes a temporal average, whose peak can decrease for longer blocks; normalize = TRUE controls unit-peak scaling (issue #49).
  • Preserved parameter metadata in closed HRF constructors and decorators without incorrectly warning that the captured parameters would be ignored.
  • Fixed loop-based block regressors integrating the kernel beyond its declared span, where the convolution engine already truncated it. The restored SPMG undershoot exposed this existing tail discrepancy. Support is now applied before block integration on both paths.
  • **Breaking:** corrected the SPMG canonical positive coefficient from 0.0833 to 1/120 and used the exact undershoot coefficient 1/(6*15!). HRF_SPMG1, HRF_SPMG2, and HRF_SPMG3 now have the SPM double-gamma shape (about 8.9% undershoot relative to peak, previously 0.6%). This changes both raw scale and shape; existing analyses should be refitted.
  • **Breaking:** the third column of HRF_SPMG3 is now a genuine response dispersion derivative, holding positive-component mean and mass fixed and using SPM's (h(d) - h(d + 0.01))/0.01 sign/step convention. Previously it was a second time derivative. deriv(HRF_SPMG3, ...) follows the corrected basis. Temporal derivatives remain analytic. These are raw, unorthogonalized continuous kernels; exact sampled SPM/Nilearn design compatibility is not implied. Existing normalize, normalise_hrf(), normalize_hrf(), and hrf_norm scaling policies are unchanged. Coefficients and derivative-based amplitude summaries must respect the selected scaling and basis geometry.
  • Fixed issue #50: feature_regressor() now rejects matrix and array inputs instead of silently flattening them into one long feature. Pass one feature column at a time.

Addresses the defects reported in issue #45.

  • **Breaking:** epoch (duration > 0) regressors are no longer scaled by 1/precision. evaluate() on a Reg object summed microtime samples of a unit-height boxcar without a step-size factor, so the amplitude of every epoch regressor grew as the precision argument shrank -- at the default precision = 0.33 an epoch column was inflated roughly 3.2x relative to the integral it was meant to approximate. The compiled engines now apply the same trapezoid quadrature evaluate.HRF() uses, so a block response is amplitude * integral h(t - onset - u) du over the block and converges as precision decreases. Point events (duration = 0) are unaffected. Fitted betas from epoch designs will change scale. Because this release also corrects response shapes and event timing, model fits and t-statistics cannot be assumed unchanged; rebuild design matrices and refit existing analyses.
  • **Breaking:** summate = FALSE now takes effect on every evaluation method. It was silently ignored by the conv (the default), fft, and Rconv engines, which never received the flag; only method = "loop" honoured it.
  • **Breaking:** evaluate.HRF() selects its impulse and block branches on duration alone rather than on duration < precision. A numerical setting could previously decide which model was evaluated: at precision = 0.2 a duration of 0.19 was treated as an impulse and 0.20 as a block, a five-fold amplitude jump. Durations smaller than precision are now integrated as blocks.
  • The accepted evaluation methods (conv, fft, Rconv, loop) now agree to within quadrature error on block regressors; the deprecated names fft and Rconv route to conv.
  • hrf_sine() and hrf_fourier() no longer error on a scalar t. vapply() dropped the result to a plain vector when length(t) == 1, so the support mask failed with "incorrect number of subscripts on matrix". This was reachable from public API via lag_hrf(), block_hrf(), and getHRF("fourier").
  • HRF_BSPLINE and hrf_bspline_generator() now place interior knots from span, fixed when the object is constructed. splines::bs() was called without knots= and fell back to quantiles of whatever t was supplied, so the basis depended on the evaluation grid and disagreed with hrf_bspline(). Evaluating on a single time point produced a degenerate basis.
  • The internal Daguerre basis normalizes each column against a fixed reference grid rather than against the caller's t. Including negative lags inflated the divisor and shrank every returned value.
  • hrf_gaussian(), hrf_mexhat(), hrf_inv_logit(), and hrf_lwu() return 0 for t < 0, as the other kernels already did. The regressor path masked negative lags itself, but block_hrf() and lag_hrf() sample the shape function directly and mixed in pre-onset values -- up to 2% of peak for a blocked Mexican hat. Note that hrf_mexhat() is discontinuous at t = 0 as a result, since its formula is non-zero there.

From NEWS.md in the release

Install

Health

CRAN checks
13OK
Slowest check: 5.5 min · r-oldrel-windows-x86_64
Status changes
  • OK13 OK2026-08-05
  • NOTE12 OK, 1 NOTE2026-08-01
  • OK13 OK2026-06-08
  • ERROR12 OK, 1 ERROR2026-06-07
  • OK12 OK2026-04-25
Show 3 earlier changesHide 3 earlier changes
  • NOTE11 OK, 3 NOTE2026-04-22
  • ERROR10 OK, 3 NOTE, 1 ERROR2026-04-18
  • NOTE11 OK, 3 NOTE2026-03-10
Advisories

none known

Documentation

In release 0.4.0
READMEYes · 524 wordsVignettesYes · 4 · dynamicNEWSYes · 100% structured · mentions 0.4.0Citation fileYes · software entry onlyWebsiteYes · pkgdown
Help pages
74 (7 internal)includes a package overview page
Examples that run
97%68 run in a plain check (1 of them under a condition) · 1 only when donttest examples are enabled (R CMD check --as-cran) · 1 hold no code
Exported functions with examples
97%
Documented parameters
98%
Return-value docs
100%
Help pages citing references
0%

Downloads

5.3K
CRAN downloads in the past year
Rank #6,475 · ~15/day · ~445/mo
Daily download trend is not available in this view yet.
47530 days
1.3K90 days
5.3K1 year
Compare downloads with other packages →
Also on439 r2u3 autocran

Repository

0Stars
0Forks
12Open issues
0Open PRs
1Releases
247Commits
3Commit identities
247 commits · Last activity 2026-10-17 · Default branch at 0.4.0.9000, ahead of CRAN 0.4.0 (checked 2026-10-25)
Responsiveness
How these are sampled
PRs merged (all time)
100%
Median days to close, 50 most recently updated closed issues
22
Median days to close, 50 most recently updated closed PRs
0

Releases over time

2026-02-20 · 12026-07-07 · 1
PracticesBeta

8 development-tooling and community-health practices detected across 4 families in the upstream repository

Checks run against github.com/bbuchsbaum/fmrihrf on 2026-10-25.

Continuous integration (2)
GitHub ActionsR CMD check workflow

The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel

Docs source (3)
pkgdown

GitHub Pages site last deployed 2026-10-17 · The repository has a site deploy workflow

pkgdown site last built 2026-10-17

CRAN release process (2)
cran-comments.mdCRAN-SUBMISSION
Lint, format, editor (1)
RStudio project
How this is detected·Detection ruleset v4 (2026-10-20)
AI coding toolsBeta

This repository shows signs of AI coding tools.

  • Codexfirst seen 2025-06-01
    Pull request it wrote: opened by a project member
  • Claude Codefirst seen 2025-06-03
    Named in .Rbuildignore: .claude, CLAUDE.md
    Named in .gitignore: CLAUDE.md
    Pull request it wrote: opened by a project member
    Commits: 66 by its own account · at least 94 crediting it in the message
  • Cursorfirst seen 2026-09-12
    Pull request it wrote: opened by a project member
    Commits: 2 by its own account
Models named in its commits
  • Claude Opus 5.569 commits · Sep to Oct 2026
  • Claude Opus 4.64 commits · Feb to Apr 2026
  • Claude Sonnet 4.63 commits · Feb 2026
  • Claude Opus 52 commits · Aug 2026
  • Claude Opus 4.51 commit · Jan 2026
Counts are commits, not lines of code. Commits by a tool's accounts count once across all of its accounts. Commits crediting it are the largest count among its credit lines, a minimum.How this is detected·Detection ruleset v4 (updated 2026-09-27)

Dependencies

Declared dependencies
20 external dependencies (excludes base and recommended)

Installing fmrihrf adds 16 packages (11 with compiled code, 7.5 MB of source tarballs). Heaviest: Rcpp 1.8 MB, RcppArmadillo 1.0 MB, jsonlite 1.0 MB.

Depends (1)
R >= 3.5.0
LinkingTo (2)
Enhances (0)
none
Reverse dependencies
0direct
0indirect

Nothing depends on this yet.

People & History

People (1)
Author, Maintainer since 0.1.0 (2025)
Releases (4)

Pick two releases to compare their code metrics.

  • 0.4.0Latest
    record
    2026-10-04 · current release · diff ↗ ·
    added 8 exports
    feature_regressor, fmrihrf_cli, hrf_palette, install_cli, normalize_hrf, scale_color_hrf, scale_colour_hrf, scale_fill_hrf
    ·
    listed once in CRAN's queue
    Seen in one reading of CRAN's incoming queue, at 2026-10-04 00:17 UTC, so it stayed less than the time between readings.
  • R
    R 4.6.0 released · 2026-04-24
  • 0.3.0
    record
    2026-03-28 · diff ↗
  • 0.2.0
    record
    2026-02-09 · diff ↗ ·
    added 5 exports
    hrf_boxcar, hrf_tent_generator, hrf_weighted, plot_hrfs, plot_regressors
  • 0.1.0
    record
    2025-09-16
  • R
    R 4.5.0 released · 2025-04-11
Across CRAN, the median accepted release of the past year spent 22 hours in the queue, 90% under 11 days.How queue time is measured

Package metadata

First published
2025-09-16
Total releases
4 / 1 yrs
License
MIT + file LICENSE OSI
Minimum R
≥ 3.5.0
Download size
3.3 MB

Cite

Cite this package

Run in R for the authors' entry:

citation("fmrihrf")

The package provides a citation file, so citation() returns the authors' own entry.

Cite the R Observatory

For a number measured here: a download total, a coverage figure, an archival date.

APA

Balamuta, J. J. (2026). R Observatory: Metrics for fmrihrf version 0.4.0 [Data set]. HJJB, LLC. Data release v2026-10-26. https://doi.org/10.5281/zenodo.21843040

From data release v2026-10-26, which the citation names so these numbers can be found later. More on citing and the projects behind them.

Report a problem with this page →

Privacy choices

These apply to this browser and are stored on this device only. Nothing about your choice is sent to us.

Read the privacy policy