Post-hoc Spatial Analysis¶
Functions for analyzing spatial distribution of behavioral states.
Overview¶
This module provides tools to:
- Analyze spatial distribution of Level 1 states
- Compute state probabilities across maze regions
- Visualize spatial patterns of behavior
- Compare spatial usage between conditions
Functions¶
compass_labyrinth.post_hoc_analysis.level_1.spatial_analysis
¶
STATE DISTRIBUTIONS BY NODE-TYPE AND REGION Author: Shreya Bangera Goal: ├── Comparison of proportion of time spent in a state across Maze regions and Node types. ├── Allows genotype level comparisons behavioral states.
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,
}
compute_state_probability
¶
compute_state_probability(
df_hmm: DataFrame,
column_of_interest: str,
values_displayed: list[str] | None = None,
state: int = 1,
) -> pd.DataFrame
Computes HMM state proportions by category (e.g., NodeType or Region). Optionally reassigns decision node labels for 3-way and 4-way decisions.
Parameters:
-
df_hmm(DataFrame) –Dataframe with 'Genotype', 'Session', 'HMM_State', and category column.
-
column_of_interest(str) –'NodeType' or 'Region'
-
values_displayed(list[str] | None, default:None) –Categories to include and order
-
state(int, default:1) –HMM_state of interest
Returns:
-
DataFrame–Dataframe with proportions per session.
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/spatial_analysis.py
plot_state_probability_boxplot
¶
plot_state_probability_boxplot(
config: dict,
state_count_df: DataFrame,
column_of_interest: str,
state: int = 1,
figsize: tuple = (16, 7),
palette: str = "Set2",
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plots boxplot of HMM state probabilities by category and genotype.
Parameters state_count: pd.DataFrame Dataframe returned from compute_state_probability() column_of_interest: str Categorical variable on x-axis state: int HMM state used for labeling figsize: tuple Figure size palette: str Seaborn palette save_fig : bool Whether to save the figure. show_fig : bool Whether to display the figure. return_fig : bool Whether to return the figure object.
Returns:
-
fig(Figure | None) –Matplotlib Figure object if return_fig is True, else None.
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/spatial_analysis.py
run_pairwise_ttests
¶
run_pairwise_ttests(
state_count_df: DataFrame,
column_of_interest: str = "NodeType",
) -> pd.DataFrame
Perform pairwise t-tests between genotypes within each level of the column_of_interest.
Parameters:
-
state_count_df(DataFrame) –DataFrame returned from compute_state_probability
-
column_of_interest(str, default:'NodeType') –Column over which comparisons are grouped
Returns:
-
DataFrame–Dataframe with columns: [Group, Genotype1, Genotype2, t-stat, p-value]