Overview

This tutorial demonstrates population-level analysis of processed fiber photometry dopamine data from juvenile songbirds. The analysis examines temporal dynamics, amplitude shifts, and information flow patterns across multiple animals using the VNS package.

Install Required Packages

remotes::install_local(file.path(getwd(),"pkgs", "VNS_0.0.0.9000.tar.gz"),
                      dependencies = TRUE)

Load Package

library("VNS")


Load Population Data

Load the population data created from the data processing and individual analysis pipeline.

load("./data/population_data.rda")


Pooling Workflow

This guide demonstrates how to generate population-level data by processing individual animal and combining them into a unified dataset. The workflow consists of four main steps:

STEP 1: Load Individual NPM Object

npm <- readRDS("./data/npm_B633.rds")


STEP 2: Compute Metrics for Individual Animals

For each animal, we calculate specific TD metrics (e.g., conditional entropy(cH))

B633_res <- npm |>
  create_segment_table(region ="reg0",
                       window = c(-0.4, 0.4),
                       n_segments= 4,
                       min_epoch = 50) |>
  analyze_directional_cH(source_seg = 1, target_seg = 4,
                         output ="data.frame")


STEP 3: Iterate Across All Animals

Apply the same analysis pipeline to each animal in the dataset. This ensures consistent processing and comparable results across subjects.


STEP 4: Combine Individual Results into Population Data

Pool all individual animal results into a single data frame. ‘combine_animal_results’ function: - Merges individual data frames - Adds animal identifiers for tracking - Preserves all computed metrics for population-level analysis

cH_res <- combine_animal_results(
  list(B633_res, P568_res, P569_res, R561_res,R562_res),
  c("B633", "P568", "P569", "R561", "R562")
)


Temporal Shift

Linear Mixed Effects Modeling

td_res <- analyze_td_metrics(temporal_shift_res)


Figure D-G

Population-level analysis of temporal difference learning metrics across vocal development.

Linear mixed-effects models (LMMs) showing developmental trajectories of dopamine transient characteristics (n = 49 observations from 5 birds, 63-91 dph). Median peak timing decreases with development (top-left). Backward shift rate increases with development (top-right). Temporal entropy decreases with development (lower-left). Gini coefficient increases with development (lower-right).

plot_td_panel(temporal_shift_res,show_title = FALSE, show_annotations = FALSE)

Each colored dot represents the mean value for one animal at a given age, with colors indicating individual animals.

Black lines show population-level fixed effects from LMMs with animal identity as random intercept.


Within Window Analysis

td_res2 <- analyze_within_window_trends(temporal_shift_res,
                                        test_method = "both",
                                        window_size = 6,
                                        plot_results = FALSE)


Figure H-K

Paired comparison of temporal discrimination metrics between the first day (Day i) and last day (Day i + 6) of 6-day sliding windows across the experimental period. Median peak timing significantly decreased within windows (top-left).

Backward shift rate significantly increased within windows (top-right). Temporal entropy showed no significant change within windows (lower-left). Gini coefficient showed no significant change within windows (lower-right).

plot_paired_metric_panel(td_res2, window_size = 6,
                      metric_order = c("peak_timing","backward_shift",  "entropy", "gini"),
                      ncol = 2)

Gray lines connect paired observations from individual animals within the same temporal window (n = 57 paired observations from 5 birds across 24 windows).

Red lines and symbols indicate group means ± SEM.


Amplitude Shift

Linear Mixed Effects Modeling

td_res3 <- analyze_amplitude_metrics(amplitude_shift_res)


Figure N-P

Population analysis of amplitude shift pattern across all animals.

Early peak amplitude showed no significant developmental change across the population (left). Late peak amplitude significantly decreased with development (middle). Early/late amplitude ratio significantly increased across development (right).

plot_amplitude_panel(amplitude_shift_res, show_title = FALSE, show_annotations = FALSE)

Individual animals shown in different colors with fitted regression lines.


Within Window Analysis

td_res4 <- analyze_within_window_trends2(amplitude_within_window_res,
                                         model ="mixed_effects",
                                         test_method = "both",
                                         window_size = 6,
                                         plot_results = FALSE)


Supplemental Figure 1

Population-level within-window paired analysis using mixed-effects models across 6-day sliding windows.

Early amplitude showed no significant within-window change (left). Late amplitude decreased significantly within windows (middle). Amplitude ratio increased significantly within windows (right).

plot_paired_metric_panel2(td_res4, window_size = 6, ncol = 3)

Points: individual observations colored by animal

Gray lines: individual observations within each window (animal × window combinations).

Colored lines: mean trajectory for each animal across all windows.

Black line with ribbon: population-level trend with 95% confidence interval from fixed effects.


Information Analysis

Linear Mixed Effects Modeling

td_res5 <- analyze_cH_metrics(cH_res)


Figure S-U

Population analysis of directional conditional entropy across all animals.

Forward conditional entropy significantly decreased with development (left), indicating population-level improvement in predictive capability from early to late temporal events.Backward conditional entropy showed no significant developmental change (middle). Prediction asymmetry significantly increased across development (right), with crossover from backward to forward dominance predicted at 66.2 dph.

plot_cH_panel(cH_res)

Individual animals shown in different colors with fitted regression lines.


Within Window Analysis

td_res6 <- analyze_within_window_info_flow(cH_within_window_res,
                                          model ="mixed_effects",
                                          window_size = 6,
                                          plot_results = FALSE)


Supplemental Figure 2

Population-level within-window paired analysis using mixed-effects models across 6-day sliding windows.

Forward entropy decreased significantly within windows (left), indicating improved forward predictability. Backward entropy showed no significant within-window change (middle). Prediction asymmetry increased significantly within windows (right), demonstrating a shift toward forward prediction dominance.

plot_paired_metric_panel2(td_res6, window_size = 6,  ncol = 3)

Points: individual observations colored by animal.

Gray lines: individual observations within each window (animal × window combinations).

Colored lines: mean trajectory for each animal across all windows.

Black line with ribbon: population-level trend with 95% confidence interval from fixed effects.


Save Results

# Get all object names in the global environment
all_objects <- ls()

# Find objects that start with "td"
td_objects <- all_objects[grepl("^td", all_objects)]

# Save objects starting with "td" to results.rda
save(list = td_objects, file = "./data/results.rda")

# To review the results in a new session load("./data/results.rda")


Summary

This population analysis:

  1. Processed individual animal data and combined into population datasets
  2. Analyzed temporal and amplitude dynamics across multiple animals using LMMs
  3. Quantified information flow and predictive coding development across multiple animals
  4. Generated comprehensive population-level statistical results
  5. Saved analysis results for further investigation

Session Info

## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.2 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## time zone: UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## loaded via a namespace (and not attached):
##  [1] digest_0.6.37     R6_2.6.1          fastmap_1.2.0     xfun_0.52        
##  [5] cachem_1.1.0      knitr_1.50        htmltools_0.5.8.1 rmarkdown_2.29   
##  [9] lifecycle_1.0.4   cli_3.6.5         sass_0.4.10       jquerylib_0.1.4  
## [13] compiler_4.4.1    tools_4.4.1       evaluate_1.0.4    bslib_0.9.0      
## [17] yaml_2.3.10       rlang_1.1.6       jsonlite_2.0.0