Skip to content

Adding hierarchical error bars to PSTHs#79

Merged
alexpiet merged 21 commits into
mainfrom
errors
Sep 12, 2025
Merged

Adding hierarchical error bars to PSTHs#79
alexpiet merged 21 commits into
mainfrom
errors

Conversation

@alexpiet

@alexpiet alexpiet commented Sep 8, 2025

Copy link
Copy Markdown
Collaborator

Uses https://github.com/AllenNeuralDynamics/aind_hierarchical_bootstrap to implement hierarchical bootstrapping to provide error bars and significance testing for PSTHs

example:

fig, ax, etrs = plot_fip_psth_compare_alignments(
    nwbs, 
    alignments, 
    channel_name, 
    error_type='hb_sem',
    hierarchical_params={'nboots':10000}
)

etrs is a dictionary that contains the time/values for each PSTH, as well as the bootstrapped values for each channel or alignment, and statistics dataframe for all comparisons performed.

Can add significant results to the plot with:

fip_psth_stats_plot(ax, etrs['stats'], color='k', threshold=0.05)

The README for the aind_hierarchical_bootstrap has a demonstration of why this approach is needed, as well as verification the implementation works: https://github.com/AllenNeuralDynamics/aind_hierarchical_bootstrap

This code ocean capsule has a demonstration of this toolset: https://codeocean.allenneuraldynamics.org/capsule/5461482/tree, /code/hierarchical_bootstrap_demonstration.ipynb

@alexpiet alexpiet marked this pull request as ready for review September 9, 2025 23:51
@rachelstephlee

Copy link
Copy Markdown
Collaborator

example capsule is private-- i can't view it!


ARGS
ax - axis to plot on
stats_df - dataframe of stats results

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add more what this stats_df will have?

also, note that the two plot_fip function will return this as part of etrs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more documentation

@rachelstephlee

Copy link
Copy Markdown
Collaborator

I think I mostly get this. The code is really clean, the example capsule would be crucial.

So if I want to have hierarchically fitted results for per mouse, per session, I would have to use two levels in the hierarchical bootstrapping, levels=['subject_id', 'ses_idx'], giving me statistics of significance per session, per subject. Is that correct?

@rachelstephlee rachelstephlee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks and works great!

can you put the example notebook in this capsule so we can have all sample code together?
https://codeocean.allenneuraldynamics.org/capsule/6488619/tree

I think you just need to cut down the number of nwbs so that it's just 10 nwbs to pull.

@alexpiet alexpiet merged commit cbaa55a into main Sep 12, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants