Part II: Testing changes between two parts of the same trial – Baseline vs. Cue Period

Sometimes it is desirable to test for changes within-trial. For example, let’s say a cue comes on and we want to test whether the average signal changes significantly during the cue-period compared to a pre-cue baseline period. We can test this within the FLMM framework with a simple intercept-only model.

Data Formating

Let’s load the binary data we used in Part I and select the subset of rows corresponding to the CS+. Again for demonstration purpose, we use data taken from Test 4 of Jeong et al., 2022 and we thank the authors for generously making their data public and helping us analyze it.

library(fastFMM) 
library(dplyr)
dat = read.csv("binary.csv") %>%
        dplyr::filter(cs == 0) # CS+ trials only

We will test this question with a functional intercept only model. The functional intercept, as mentioned in Part I, can be interpreted as the mean signal on CS+ trials. Therefore, any time interval where the 95% confidence interval of the functional intercept does not contain 0 (anywhere) can be interpreted as the CS+ trial time intervals where the mean signal is significiantly different from 0.

But what does it mean for the signal to be significantly different from 0? This depends entirely on how the data is pre-processed. If each trial’s signal is, for example, normalized to a trial-specific baseline, the interpretation of the hypothesis test will be with reference to how 0 is defined in each trial. For example, if we calculate the average signal during the pre-cue period (-2 sec to 0 sec) as a trial-specific baseline, and then subtract that off of every timepoint, then the value 0 is “re-defined” to be the average during the pre-cue period. Thus, significant deviations during the cue-period should be interepreted as significant differences from a trial-level baseline period average. This pre-processing choices can change the results and interpretation, so it is important to carefully describe these choices when results are written up. Let’s take the above approach of subtracting the trial-specific pre-cue baseline period average from each signal value.

# normalize to pre-cue baseline period
baseline_photometry = paste0("photometry.", 1:50) # names of photometry columns during first 2 sec
full_photometry = paste0("photometry.", 1:125) # names of all photometry columns
dat[,full_photometry] = dat[,full_photometry] - rowMeans(dat[,baseline_photometry]) # subtract off trial-specific baseline from each photometry value

To get the basic idea, let’s proceed with an intercept only model with an animal-specific random intercept. As usual, we set parallel=TRUE to speed up the code.

Model 1: \[ \begin{aligned} & \mathbb{E}[Y_{ij}(s) \mid \boldsymbol{\gamma}_i(s)] = \beta_0(s) + {\gamma}_{0,i}(s) \notag \end{aligned} \]

# fit model
mod = fui(photometry ~ 1 + (1 | id), data = dat, parallel = TRUE) # random intercept model

We could have fit more complicated models if we wanted to by, for example, adjusting for baseline covariates (e.g., age, sex) or trial/session number. This changes the interpretation, but may be appropriate in some contexts. We will discuss more complicated models in subsequent vignettes.

Let’s plot the output.

# plot model with best model fit (AIC/BIC)
plot_fui(mod, 
         xlab = "Time (sec)", # label x-axis
         x_rescale = 25, # rescale x-axis to be in sec - photometry sampled at 25 Hz 
         align_x = 2, # align to time of cue onset
         title_names = c("Intercept: Mean Signal CS+")
         )

## TableGrob (1 x 1) "arrange": 1 grobs
##   z     cells    name           grob
## 1 1 (1-1,1-1) arrange gtable[layout]

The only plot is for the functional intercept, \(\beta_0(s)\). Because we fit the model with only CS+ trials in the dataset and specified a model with just a functional intercept, this plot has the interpretation as the mean signal on CS+ trials relative to the pre-cue baseline period average. As we can see, there is a statistically significant increase in the mean signal on CS+ trials, for the first second after cue onset (in the interval: 0s - 1s), relative to the trial-specific pre-cue baseline period average. This provides a trial timepoint-by-timepoint hypothesis test of within-trial changes in signal magnitude.

How to Cite

For use of this package or vignette, please cite the following papers:

Gabriel Loewinger, Erjia Cui, David Lovinger, and Francisco Pereiera. A Statistical Framework for Analysis of Trial-Level Temporal Dynamics in Fiber Photometry Experiments. eLife (2024).

Erjia Cui, Andrew Leroux, Ekaterina Smirnova, and Ciprian Crainiceanu. Fast Univariate Inference for Longitudinal Functional Models. Journal of Computational and Graphical Statistics (2022).

References

Huijeong Jeong, Annie Taylor, Joseph Floeder, Martin Lohmann, Stefan Mihalas, Brenda Wu, Mingkang Zhou, Dennis Burke, Vijay Namboodiri. Mesolimbic dopamine release conveys causal associations. Science 378, 6740 (2022).