Export
export
Statistical visualization and plot generation for experimental reports.
This module provides standard reporting visualizations, including horizontal forest plots for treatment lifts and confidence intervals, and required sample size curves comparing standard designs to variance-reduced (CUPED) designs.
| FUNCTION | DESCRIPTION |
|---|---|
plot_forest |
Generates a horizontal forest plot visualizing relative lift and confidence intervals. |
plot_power_curve |
Plots required sample size per variant across a range of Minimum Detectable Effects (MDE). |
plot_forest
plot_forest(
df_raw: DataFrame,
alpha: float = 0.05,
title: str = "A/B Test Results - Relative Lift & 95% CIs",
figsize: tuple = (10, 5),
) -> tuple
Generates a horizontal forest plot visualizing relative lift and confidence intervals.
A Forest Plot is the industrial standard for reviewing multiple metrics simultaneously. It displays each metric's estimated treatment lift along with its surrounding confidence bounds. This allows rapid, visual identification of which metrics experienced significant shifts, whether the shifts are positive or negative, and how much uncertainty surrounds each estimate.
Visual Elements
- Center Dots: Represent the point estimate of the relative lift (\(\\hat{\\theta}\)).
- Horizontal Bars: Represent the \(1 - \\alpha\) confidence interval (\([\\theta_{\\text{lower}}, \\ \\theta_{\\text{upper}}]\)).
- Vertical Reference Line: Placed at \(x = 0\) (represented as a dashed red line) to denote the Null Hypothesis (no effect). If a metric's horizontal bar does not cross this dashed line, the effect is statistically significant.
- Color Coding: Significant shifts (\(p < \\alpha\)) are colored in high-contrast teal, while insignificant shifts are shaded in neutral slate-grey.
| PARAMETER | DESCRIPTION |
|---|---|
df_raw
|
A DataFrame containing the statistical summary. Must include the columns:
-
TYPE:
|
alpha
|
Nominal significance level used to color-code significance. Defaults to 0.05.
TYPE:
|
title
|
Title of the rendered plot. Defaults to
TYPE:
|
figsize
|
Dimensions of the figure canvas. Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple
TYPE:
|
Source code in src\xpyrment\report\export.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
plot_power_curve
plot_power_curve(
power_curve_data: Dict[str, ndarray],
title: str = "A/B Test Design - Required Sample Size vs. MDE",
figsize: tuple = (10, 6),
) -> tuple
Plots required sample size per variant across a range of Minimum Detectable Effects (MDE).
Mathematical Relationship and CUPED Savings
Because sample size scales quadratically with the inverse of the MDE: $$ N \propto \frac{1}{\delta^2} $$ small increases in the precision requirements (smaller MDE) trigger massive increases in the required sample size.
If a pre-period covariate is registered, the plot overlays a second curve displaying the required sample size when applying CUPED variance reduction. - Let \(\\rho\) be the correlation coefficient between the pre-period covariate and the post-period outcome. - The required sample size under CUPED (\(N_{\\text{CUPED}}\)) is deflated by a factor of \((1 - \\rho^2)\): $$ N_{\text{CUPED}} = N_{\text{standard}} \times (1 - \rho^2) $$ - The visual shaded gap between the standard curve and the CUPED curve demonstrates the direct sample size savings (and consequently, the timeline savings) gained by utilizing pre-period covariate adjustment.
| PARAMETER | DESCRIPTION |
|---|---|
power_curve_data
|
A dictionary containing:
-
TYPE:
|
title
|
Title of the rendered plot. Defaults to
TYPE:
|
figsize
|
Dimensions of the figure canvas. Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple
TYPE:
|
Source code in src\xpyrment\report\export.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |