Hemodynamic Response Function Modeling with hrf

hrf is an R package for modeling the hemodynamic response function (HRF). It also includes functions for constructing a design matrix for a general linear model (GLM), and for comparing multiple GLMs with different design matrices.

library(hrf)

HRF modeling

TR <- 2.2
upsample <- 1000
upsample <- round(TR*upsample)/TR # TR*upsample must be an int

u <- seq(0, 30, by=1/upsample) #go out 30 sec
HRF <- HRF_calc(t = u, deriv=0)
dHRF <- HRF_calc(t = u, deriv=1)

matplot(cbind(HRF, dHRF), type="l", lwd=2, col=c("black", "blue"))

Design matrix construction

# Read in data. 
events <- read.csv("../tests/data/motor1-events.tsv", sep="\t")

# Convert 3-col data.frame to list of 2-col data.frames
events$trial_type <- as.factor(events$trial_type)
trials <- levels(events$trial_type)
events <- setNames(lapply(
  trials, 
  function(x){events[events$trial_type==x,seq(2)]}
), trials)
des <- make_design(events, nTime=370, TR=0.72)
## Maximum corr.:  0.17 
## Maximum VIF:    1.171
des
## ====BfMRI_design =======================
## Fields: LFoot, LHand, RFoot, RHand, Tongue 
## ----------------------------------------
plot(des)
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## ℹ The deprecated feature was likely used in the hrf package.
##   Please report the issue at <https://github.com/mandymejia/hrf/issues>.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.