Utilities
Utility functions for logging, visualization, and calculations.
Logging
warn_once
warn_once
Visualization
draw_interval
draw_interval
draw_interval(real_alpha: float, left_alpha: float, right_alpha: float, axes: Axes, alpha: float = 0.05, name: Optional[str] = None, lang: Language = 'en')
Visualize the confidence interval for the estimated Type I error rate (alpha).
This function draws a horizontal line representing the theoretical alpha level, fills the confidence interval around the empirical alpha, and marks the observed empirical alpha with a star. It is typically used in A/A testing to assess whether the statistical test maintains the nominal error rate.
Parameters
real_alpha : float
The empirically observed Type I error rate (proportion of rejections
when null hypothesis is true).
left_alpha : float
Left boundary of the confidence interval for real_alpha.
right_alpha : float
Right boundary of the confidence interval for real_alpha.
axes : plt.Axes
Matplotlib Axes object to draw the plot on.
alpha : float, optional
The theoretical (nominal) significance level, by default 0.05.
name : str, optional
Name of the experiment or group, used as part of the plot title.
If None, only the rejection rate is shown in the title.
lang : Language, optional
Language code for labels ('en' or 'ru'), by default 'en'.
Returns
None
Source code in aboba/utils/draw.py
draw_pvalue_distribution
draw_pvalue_distribution
draw_pvalue_distribution(pvals: List[float], axes: Axes, name: Optional[str] = None, lang: Language = 'en')
Plot a histogram of p-values to assess their distribution.
Under the null hypothesis (e.g., in an A/A test), p-values should be uniformly distributed between 0 and 1. This plot helps diagnose issues like p-hacking, selection bias, or violations of test assumptions. A flat histogram around the density of 1.0 indicates a well-calibrated test.
Parameters
pvals : List[float] A list of p-values obtained from repeated statistical tests. axes : plt.Axes Matplotlib Axes object to draw the plot on. name : str, optional Name of the experiment or group, used as part of the plot title. If None, a generic title is used. lang : Language, optional Language code for labels ('en' or 'ru'), by default 'en'.
Returns
None
Source code in aboba/utils/draw.py
Statistical Calculations
calculate_real_alpha
calculate_real_alpha
Estimate real alpha level and its interval
| PARAMETER | DESCRIPTION |
|---|---|
n_errors
|
number of errors in an experiment
TYPE:
|
n_iter
|
number of experiments
TYPE:
|
method
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Tuple[float, float, float]: real_alpha, left_alpha, right_alpha |