extendedmosaicperm.experiments.sign_flip module
- class SignFlipExperiment(n_sims=100, nrand=100, seed=42, violation_strengths=None, sizes=None, exposures_update_interval=10)[source]
Bases:
BaseExperimentCompare permutation-based vs sign-flip inference across generators and sizes.
The experiment runs a grid over:
data generators:
"random","block","common",size settings: e.g.
"small","medium","large",residual symmetry: symmetric vs asymmetric,
methods: permutation (
"perm") vs sign-flip ("sign").
- Parameters:
n_sims (
int) – Number of Monte Carlo replications per configuration.nrand (
int) – Number of random draws (permutations or sign-flips) per fit.seed (
int) – Base seed;seed + simis used for thesim-th replication.violation_strengths (
Optional[list[float]]) – List of residual correlation strengths to iterate over.sizes (
Optional[Dict[str,Dict[str,int]]]) – Mapping from size key to a dict with keys"T","p","k". For example:{"small": {"T": 250, "p": 50, "k": 5}, ...}.exposures_update_interval (
int) – If greater than zero, exposures are redrawn every given number of periods.
Examples
>>> from extendedmosaicperm.experiments.sign_flip import SignFlipExperiment >>> exp = SignFlipExperiment(n_sims=1, nrand=3, seed=0, violation_strengths=[0.0]) >>> exp.run() >>> df = exp.summarize() >>> {"label", "method", "violation_strength"}.issubset(df.columns) True
Initialize an empty experiment container.
- compare_method_timings_all_sizes(n_repeats=10, violation_strength=0.1, symmetric=True, return_full=False)[source]
Benchmark permutation vs sign-flipping for the
"block"generator.For each size setting and method (
"perm","sign"), this routine runsn_repeatsshort fits using the same dataset across methods within a repeat. It records p-values and wall-clock runtimes.- Parameters:
n_repeats (
int) – Number of runs per method per size.violation_strength (
float) – Strength of the residual correlation / symmetry violation for the"block"generator.symmetric (
bool) – Whether residuals are symmetric (True→"sym",False→"asym").return_full (
bool) – IfTrue, also return the full run-level DataFrame in addition to the summary.
- Returns:
If
return_fullisFalse, returns a summary DataFrame with columns:"size","method","pval_mean","pval_std","runtime_mean","runtime_std".
If
return_fullisTrue, returns a pair(summary, df_full), wheredf_fullcontains run-level results with columns:"size","method","p_value","runtime_sec".
- Return type:
pandas.DataFrame or tuple[pandas.DataFrame, pandas.DataFrame]
- Raises:
ValueError – If the
"block"generator is not available.