Post-hoc Bout Analysis¶
Functions for analyzing behavior at the bout level.
Overview¶
This module provides tools to:
- Define and extract bouts from continuous data
- Compute bout-level statistics and metrics
- Analyze state composition within bouts
- Compare bout characteristics across conditions
Functions¶
compass_labyrinth.post_hoc_analysis.level_1.bout_analysis
¶
BOUT-TYPE BASED STATE COMPARISONS Author: Shreya Bangera Goal: ├── Classifies bouts as successful or unsuccessful based on target reach. ├── Computes and compares HMM state proportions across these bout types.
NODE_TYPE_MAPPING
module-attribute
¶
NODE_TYPE_MAPPING = {
"decision_reward": DECISION_REWARD,
"nondecision_reward": NONDECISION_REWARD,
"corner_reward": CORNER_REWARD,
"decision_nonreward": DECISION_NONREWARD,
"nondecision_nonreward": NONDECISION_NONREWARD,
"corner_nonreward": CORNER_NONREWARD,
"entry_zone": ENTRY_ZONE_NODES,
"target_zone": TARGET_ZONE_NODES,
"decision_3way": DECISION_3WAY,
"decision_4way": DECISION_4WAY,
}
assign_bout_indices
¶
Assign bout indices to each row in the dataframe based on delimiter nodes. Bout = delimiter_node --> Other non-entry nodes --> delimiter_node
Parameters:
-
df(DataFrame) –Dataframe with 'Session' and 'Grid Number' columns.
-
delimiter_node(int, default:47) –Grid Number that indicates the start of a new bout.
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/bout_analysis.py
compute_surveillance_probabilities
¶
compute_surveillance_probabilities(
df_hmm: DataFrame,
decision_nodes: str = "decision_reward",
) -> tuple[pd.DataFrame, pd.DataFrame]
Compute surveillance probability at Decision nodes by Bout type. - Successful -> reached the target at least once - Unsuccessful -> doesn't reached the target
Parameters:
-
df_hmm(DataFrame) –Dataframe with 'Genotype', 'Session', 'HMM_State', 'Grid Number', 'Region', and 'Bout_Index'.
-
decision_nodes(str, default:'decision_reward') –Type of decision node to consider for surveillance probability.
Returns:
-
DataFrame–Dataframe with median surveillance probabilities per genotype, session, and bout type.
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/bout_analysis.py
plot_surveillance_by_bout
¶
plot_surveillance_by_bout(
config: dict,
median_df: DataFrame,
ylim: float,
figure_size: tuple = (6, 6),
palette: list = ["grey"],
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Barplot to depict the surveillance probabilities with t-test independent p-values.
Parameters:
-
config(dict) –Project configuration dictionary.
-
median_df(DataFrame) –Dataframe with median surveillance probabilities per genotype, session, and bout type.
-
ylim(float) –Y-axis limit for the plot.
-
figure_size(tuple, default:(6, 6)) –Size of the figure.
-
palette(list, default:['grey']) –Color palette for the plot.
-
save_fig(bool, default:True) –Whether to save the figure.
-
show_fig(bool, default:True) –Whether to display the figure.
-
return_fig(bool, default:False) –Whether to return the figure object.
Returns:
-
Figure–The generated matplotlib figure.
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/bout_analysis.py
test_within_genotype_success
¶
T-tests between Successful vs Unsuccessful bouts for each genotype.
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/bout_analysis.py
test_across_genotypes_per_bout
¶
T-tests between genotypes for either Successful or Unsuccessful bouts.
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/bout_analysis.py
run_within_genotype_mixedlm_with_fdr
¶
Run a mixed-effects model per genotype comparing Successful vs Unsuccessful bouts, with Session as a random effect. Applies FDR correction.
Returns - DataFrame with Genotype, Effect size, raw P-value, FDR P-value, and significance flag.