Published December 10, 2025 | Version v1

R script for statistical analysis of fiber photometry data

Authors/Creators

Description

Code is being made available in relation with the publication of original research data analysed with this code.

Original data was collected with fiber photometry recordings during social interaction sessions.

Raw signals were exported and preprocessed using the pMat toolbox (Bruno, O'Brien et al. 2021). High-frequency noise was removed by smoothing, and ΔF/F was calculated as (calcium signal – scaled isosbestic signal) / scaled isosbestic signal. The ΔF/F traces were then Z-scored relative to the mean and standard deviation of the baseline. For each behavioral event (anogenital sniffing, non-anogenital sniffing, toy sniffing), we compared the normalized signal averaged over 1 s before event onset to the signal averaged over the first 1 s after onset.

Statistical analysis was performed in R (Version 4.0.4; R Core Team, 2021) using RStudio (Version 1.4.1106, PBC; Team R, 2019). Linear mixed-effects models were fitted using the lme4 (Douglas Bates, Bolker and Walker 2015) and lmerTest (Kuznetsova, Brockhoff and Christensen 2017) packages, with type III ANOVA performed using Satterthwaite’s method. Post hoc Tukey’s multiple comparisons were conducted with the emmeans package (Lenith 2023), and the Kenward–Roger approximation for denominator degrees of freedom. Model assumptions were verified by inspection of residual plots.

The models compared Z-scored ΔF/F values before vs. during each behavioral event in a paired manner, with trial included as a random effect nested within session and sessions nested within animal. When recordings were performed bilaterally, hemisphere was added as a cross-nested random effect. Fixed factors included time in relation to trial onset (before vs. during the behavior), and in the case of comparison of active and received behaviors also behavior type. The model for the behavior towards the toy was fitted separately, as these were recorded from separate sessions. 

Files

Files (1.3 kB)

Name Size
md5:e12577e8cd80c417a736c52c1e6e84be
1.3 kB Download

Additional details

Software

Programming language
R