Quantitative Workplace Experimentation and Power Analysis Script
Generate a robust statistical script to conduct power calculations and hypothesis testing for organizational intervention studies.
Use this template when setting up or evaluating randomized workplace experiments, productivity interventions, or operational team trials. It delivers an end-to-end Python script covering sample sizing, statistical power, covariate adjustment, and significance testing.
Role: Principal Experimentation Statistician with extensive expertise in causal inference and organizational trial design.
Context
- Study initiative: {{experiment_name}}
- Cohort profile: {{sample_population}}
- Key performance indicator: {{primary_metric}}
- Historical reference baseline: {{baseline_rate}}
- Target minimum detectable effect: {{minimum_detectable_effect}}
- Significance threshold: {{alpha_level}}
Task
Author an end-to-end Python statistical execution script that computes sample size requirements, performs pre-trial balance checks, and implements regression-adjusted hypothesis testing for {{experiment_name}} evaluated across {{sample_population}}.
Method
- Import production-grade scientific libraries (
scipy.stats,statsmodels,numpy,pandas) with deterministic random seeding. - Ingest parameters for {{primary_metric}}, {{baseline_rate}}, and {{minimum_detectable_effect}} to calculate statistical power curves across sample sizes.
- Implement two-sided prospective sample size calculations targeting 80% and 90% power given {{alpha_level}}.
- Construct data hygiene and outlier detection functions tailored to {{primary_metric}} distributional quirks.
- Write baseline balance assessment routines (standardized mean differences) comparing control and treatment cohorts.
- Implement Ordinary Least Squares or Logistic Regression estimation with robust Huber-White standard errors.
- Compute point estimates, confidence intervals, and p-values alongside Cohen's d effect magnitude benchmarks.
- Generate formatted CLI diagnostic summaries and structured logging of statistical conclusions.
Constraints
- Code MUST be fully functional, modular Python 3.10+ without pseudocode or undefined variable stubs.
- Script MUST handle both continuous and binary distributions based on {{primary_metric}} characteristics.
- MUST NOT use deprecated functions from older
scipyorstatsmodelsreleases. - Provide clear inline docstrings adhering to Google Python style guidelines.
Output format
Provide a single production-ready Python script organized into:
- Configuration block defining hyper-parameters from {{baseline_rate}}, {{minimum_detectable_effect}}, and {{alpha_level}}.
- Power & Sample Size Calculation Module (min 20 lines).
- Statistical Testing & Estimation Class (min 40 lines).
- Execution Block (
if __name__ == '__main__':) demonstrating end-to-end analysis on mock synthetic data.
Self-review
- Confirm all formulaic power calculations explicitly match standard two-tailed formulas.
- Verify that {{sample_population}} and {{primary_metric}} variable names are consistently utilized throughout the code.
- Ensure error handling exists for degenerate variance or underpowered sample sizes.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.