power_analysis¶
tissue_simulator.power_analysis ¶
Power analysis utilities for ABM replicate planning.
This module provides effect-size, coefficient-of-variation, and statistical-power tools used to demonstrate that tissue_simulator initialization reduces inter-replicate variance, lowering the number of simulation replicates required to achieve a target power.
The functions here are intended to compare endpoint distributions produced by different ABM initialization strategies (e.g., random placement versus tissue_simulator-driven placement) on identical downstream models.
cohens_d ¶
Compute the pooled-standard-deviation Cohen's d effect size.
Uses sample standard deviations with ddof=1 (Bessel's correction)
and the standard pooled-variance formula.
Parameters¶
group_a : array_like First sample of endpoint values. group_b : array_like Second sample of endpoint values.
Returns¶
float
Cohen's d. Positive values indicate group_a has the larger
mean. Returns 0.0 when both groups are constant and identical;
returns inf when the pooled standard deviation is zero but
the means differ.
Source code in tissue_simulator/power_analysis.py
coefficient_of_variation ¶
Compute the coefficient of variation: std / |mean|.
Uses sample standard deviation (ddof=1).
Parameters¶
values : array_like Sample of endpoint values.
Returns¶
float
Coefficient of variation. Returns inf if the sample mean is
zero (CV is undefined in that case).
Source code in tissue_simulator/power_analysis.py
required_replicates ¶
required_replicates(effect_size: float, alpha: float = 0.05, power: float = 0.8, alternative: str = 'two-sided') -> int
Solve for the per-group sample size of a two-sample t-test.
Returns the smallest integer N per group such that an independent two-sample t-test achieves at least the requested power for the given Cohen's d effect size.
Parameters¶
effect_size : float
Cohen's d. The absolute value is used; sign is irrelevant for
sample-size calculation.
alpha : float, optional
Type-I error rate. Defaults to 0.05.
power : float, optional
Desired statistical power (1 - beta). Defaults to 0.8.
alternative : {"two-sided", "larger", "smaller"}, optional
Alternative hypothesis as accepted by statsmodels. Defaults to
"two-sided".
Returns¶
int Required sample size per group, rounded up.
Raises¶
ImportError
If statsmodels is not installed.
ValueError
If effect_size is zero (sample size is undefined).
Source code in tissue_simulator/power_analysis.py
power_curve ¶
power_curve(effect_sizes: ArrayLike, n_range: ArrayLike, alpha: float = 0.05, alternative: str = 'two-sided') -> np.ndarray
Build a 2D grid of achieved power across effect sizes and sample sizes.
Parameters¶
effect_sizes : array_like
Cohen's d values to evaluate (rows of the output).
n_range : array_like
Per-group sample sizes to evaluate (columns of the output).
alpha : float, optional
Type-I error rate. Defaults to 0.05.
alternative : {"two-sided", "larger", "smaller"}, optional
Alternative hypothesis. Defaults to "two-sided".
Returns¶
numpy.ndarray
Array of shape (len(effect_sizes), len(n_range)) containing
the achieved power for each (effect size, N) pair.
Raises¶
ImportError If statsmodels is not installed.
Source code in tissue_simulator/power_analysis.py
compare_initialization_variance ¶
compare_initialization_variance(endpoints_by_method: Mapping[str, ArrayLike], alpha: float = 0.05, power: float = 0.8) -> Dict[str, object]
Compare endpoint variability across initialization methods.
For each method computes mean, sample standard deviation, and coefficient of variation. For each unordered pair of methods, computes Cohen's d on the endpoint samples and the per-group N needed to detect that effect at the requested alpha and power.
Parameters¶
endpoints_by_method : dict[str, array_like] Mapping of method name to a 1D array of endpoint values (one value per replicate of that method). alpha : float, optional Type-I error rate used for the required-N calculation. power : float, optional Desired statistical power used for the required-N calculation.
Returns¶
dict Structured results with two top-level keys:
``"per_method"`` : dict[str, dict]
Per-method ``n``, ``mean``, ``std``, ``cv``.
``"pairwise"`` : list[dict]
One record per unordered method pair, each with
``method_a``, ``method_b``, ``cohens_d``,
``required_n_per_group``, ``alpha``, ``power``.
``required_n_per_group`` is ``None`` when the effect size
is zero or statsmodels is unavailable.
Source code in tissue_simulator/power_analysis.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
summarize_power_analysis ¶
Format a human-readable report from compare_initialization_variance.
Parameters¶
comparison : dict
Output of :func:compare_initialization_variance.
Returns¶
str Multi-line report covering per-method summary statistics and all pairwise effect sizes and required sample sizes.