Statistics: cicada_tools.stats¶
from cicada_analysis.cicada_tools.stats.<module> import <function>
stats.stats (Statistical tests, lines and bands of groups)¶
-
compare_two_distributions¶
compare_two_distributions(distribution1, distribution2, pvalues=0.05, verbose=True) -> None
Compare two distributions with several two-sample tests and print the results (nothing returned).
| Parameter | Type | Default | Description |
|---|---|---|---|
distribution1 |
any | First distribution | |
distribution2 |
any | Second distribution | |
pvalues |
float | 0.05 | Significance threshold |
verbose |
bool | True | Print results |
Returns: None
-
multiple_comparison_one_factor_effect¶
multiple_comparison_one_factor_effect(distributions_list, pvalues=0.05, verbose=True, sessions_ids=None) -> None
Non-parametric one-factor test across multiple groups (Kruskal-Wallis + post-hoc).
| Parameter | Type | Default | Description |
|---|---|---|---|
distributions_list |
list | List of distributions | |
pvalues |
float | 0.05 | Significance threshold |
verbose |
bool | True | Print results |
sessions_ids |
list | None | Session IDs |
Returns: None
-
compare_groups¶
compare_groups(rows, value, x, hue=None, pvalues=0.05, verbose=True, units=None) -> None
Compares the distributions of value between the groups of column x within each group of column hue (two groups: compare_two_distributions, more: multiple_comparison_one_factor_effect; NaN left out).
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
pd.DataFrame | Data rows | |
value |
str | Value column | |
x |
str | Group column | |
hue |
str | None | Hue column |
pvalues |
float | 0.05 | Significance threshold |
verbose |
bool | True | Print results |
units |
list[str] | None | Columns of the statistical unit (e.g. ['mouse']): the mean of value per unit and group is compared, so n is the number of units. None: every row is a unit |
Returns: None
-
summarize_by_levels¶
summarize_by_levels(table, value, group_columns, levels=...) -> dict
Count, mean, SD, min, median and max of value per combination of group_columns, per session and per mouse by default: {level name: summary table}.
| Parameter | Type | Default | Description |
|---|---|---|---|
table |
pd.DataFrame | Input table | |
value |
str | Value column | |
group_columns |
list | Group columns | |
levels |
any | Levels |
Returns: dict — Summary tables by level
-
chi_square_uniformity_test¶
chi_square_uniformity_test(observed_data, binsize) -> tuple
Chi-square goodness-of-fit test of the histogram of observed_data (bins of binsize) against a uniform distribution. Returns (chi2_stat, p_value, uniformity) (uniformity: p ≥ 0.05).
| Parameter | Type | Description |
|---|---|---|
observed_data |
any | Observed data |
binsize |
float | Bin size |
Returns: tuple — (chi2_stat, p_value, uniformity)
-
line_and_band¶
line_and_band(data, value, by, reduction='median', band='percentiles', low_percentile=25, high_percentile=75) -> pd.DataFrame
Line and band of a value over the rows of each group, e.g. a PSTH at each time point. NaN values are ignored. Band: 'SD' / 'SEM' = line ± SD / SEM (ddof 1), '95% CI' = mean ± the bootstrap half-width of the mean (slow), 'percentiles' = low_percentile to high_percentile, 'none' = no band. No band for a group with fewer than 2 values (as seaborn).
| Parameter | Type | Default | Description |
|---|---|---|---|
data |
pd.DataFrame | One row per unit of the level reduced (event, session, mouse...) | |
value |
str | Column reduced | |
by |
list[str] | Columns of the groups (e.g. ['bodypart', 'trial_name', 'time']) |
|
reduction |
str | 'median' | 'median' or 'mean' |
band |
str | 'percentiles' | 'SD', 'SEM', '95% CI', 'percentiles' or 'none' |
low_percentile |
float | 25 | Lower limit of the 'percentiles' band |
high_percentile |
float | 75 | Upper limit of the 'percentiles' band |
Returns: pd.DataFrame — one row per group, in order of appearance: the by columns, line, low, high (NaN without band) and n (number of non-NaN values)
-
band_functions¶
band_functions(reduction='median', band='percentiles', low_percentile=25, high_percentile=75) -> list
The line and band of line_and_band as functions of a 1-D array, NaN ignored, for code that reduces one time point at a time (e.g. fcts_to_apply of build_population_psth): no line without values, no band under 2 values.
| Parameter | Type | Default | Description |
|---|---|---|---|
reduction |
str | 'median' | As in line_and_band |
band |
str | 'percentiles' | As in line_and_band |
low_percentile |
float | 25 | As in line_and_band |
high_percentile |
float | 75 | As in line_and_band |
Returns: list — [line, low, high], three functions of a 1-D array returning a float
-
array_line_and_band¶
array_line_and_band(values, axis=0, reduction='median', band='percentiles', low_percentile=25, high_percentile=75) -> (line, low, high)
The line and band of line_and_band along one axis of an array (e.g. the trials of each unit and time bin): NaN ignored, no band under 2 values. A band other than the five of line_and_band gives no band.
| Parameter | Type | Default | Description |
|---|---|---|---|
values |
np.ndarray | Values, reduced along axis |
|
axis |
int | 0 | Axis reduced |
reduction |
str | 'median' | As in line_and_band |
band |
str | 'percentiles' | As in line_and_band |
low_percentile |
float | 25 | As in line_and_band |
high_percentile |
float | 75 | As in line_and_band |
Returns: tuple — (line, low, high), each with the shape of values without axis
-
reduce_psth_level¶
reduce_psth_level(rows, by, reduction='median', band='percentiles', low_percentile=25, high_percentile=75) -> pd.DataFrame
Reduce PSTH lines one level up (e.g. the sessions of a mouse, or the mice of a group): line and band of the rows' line values in each group of by (line_and_band). A group made of a single line keeps the band it had at the level below (e.g. a single session keeps its band over events).
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
pd.DataFrame | One row per unit and time point, with line, low, high and the by columns |
|
by |
list[str] | Columns of the groups, the time column included | |
reduction |
str | 'median' | As in line_and_band |
band |
str | 'percentiles' | As in line_and_band |
low_percentile |
float | 25 | As in line_and_band |
high_percentile |
float | 75 | As in line_and_band |
Returns: pd.DataFrame — the by columns, line, low, high, n (number of lines reduced)