Experimental Design
K-DenseCommunityCreated by K-Dense Inc.
- Skill
- Workflow
- Science and research
- MIT
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Experimental design is the critical phase of research that occurs before data collection. This skill provides a framework for structuring experiments to ensure results are valid and interpretable. It emphasizes Fisher's principles—randomization, replication, and blocking—to isolate effects of interest from nuisance variation. By using this skill, researchers can avoid common structural pitfalls like pseudoreplication and confounding, ensuring that the chosen design matches the research question and the unit of analysis.
What it does
- Provides a decision tree to select the appropriate experimental design based on research goals.
- Generates reproducible randomization and allocation schedules for subjects or samples.
- Creates Design of Experiments (DOE) matrices for factorial, fractional-factorial, and response-surface studies.
- Offers guidance on blocking and stratification to remove nuisance variation.
- Helps identify and prevent structural errors like pseudoreplication and aliasing.
- Supports complex designs including crossover, split-plot, and cluster-randomized studies.
When to use it
- When planning any comparative experiment or clinical trial.
- When you need to assign subjects to groups while balancing nuisance factors.
- When designing multi-factor experiments to screen for significant effects or optimize responses.
- When you need to determine the correct level of replication to avoid pseudoreplication.
- When setting up plate layouts or run orders to minimize drift and batch effects.
Advantages
- Prevents unfixable structural errors that invalidate data analysis.
- Increases statistical precision by effectively managing nuisance variables.
- Ensures causal claims are supported by proper randomization.
- Provides reproducible, seeded layouts for consistent study execution.
- Optimizes experimental efficiency by reducing the number of runs required.
Usage examples
- “How should I assign 60 mice to two treatment groups while accounting for two different study sites?”
- The agent will recommend a stratified block randomization approach, providing a script to generate the schedule that balances the treatment arms within each site.
- “I need to test 5 factors to see which ones affect my yield. What is the best way to set this up?”
- The agent will suggest a fractional factorial or Plackett-Burman screening design to efficiently identify significant factors while minimizing the total number of experimental runs.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/k-dense-ai/experimental-design/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip experimental-design.zip -d .agents/skills
Documentation by K-Dense Inc.
Experimental Design
Overview
The design of a study — how units are assigned to conditions, what is held constant, what is varied, and in what structure — determines what questions the data can answer. No analysis can rescue a confounded or pseudoreplicated design after the fact. This skill is about the decisions made before data collection: picking a design that isolates the effect of interest, randomizing to license causal claims, blocking to remove known nuisance variation, and structuring multi-factor experiments so effects are estimable rather than tangled together.
The three ideas behind almost every good design (Fisher's principles):
Randomization — assign treatments at random so that confounders, known and unknown, are balanced in expectation. This is what turns a comparison into a causal claim.
Replication — independent repetition at the right level, so you can estimate variability and your effects aren't artifacts of a single unit. The most common fatal error is pseudoreplication: counting repeated measurements on the same unit as independent replicates.
Blocking / local control — group similar units (by batch, day, site, litter) and randomize within blocks, removing that nuisance variation from the error term instead of letting it inflate noise.
This skill helps you choose among design types, generate the actual randomization or DOE layout (with reproducible scripts), and avoid the structural mistakes that make data uninterpretable.
When to Use This Skill
Planning any comparative experiment or trial and deciding how to assign units
Randomizing subjects/samples to arms (simple, blocked, stratified, or cluster)
Removing nuisance variation by blocking or stratification
Designing multi-factor experiments: full or fractional factorial, screening designs
Optimizing a response over continuous factors (response-surface designs)
Within-subject / repeated-measures, crossover, split-plot, or Latin-square designs
Cluster- or group-randomized designs (sites, clinics, classrooms, litters)
Deciding the number and level of replicates and avoiding pseudoreplication
Sequential, group-sequential, or adaptive designs with interim analyses
Laying out plates/batches and randomizing run order to defeat drift
Installation
uv venv --python 3.13 .venv-design
uv pip install --python .venv-design/bin/python "numpy==2.5.3" "pandas==3.0.6" "pydoe==1.5.0"pyDOE3 was archived in May 2026; active
development returned to pydoe. The bundled
wrappers target pydoe==1.5.0, imported as lowercase pydoe, and return
designs in real factor units. All seven DOE wrappers and both script demos were
executed with Python 3.13, NumPy 2.5.3, pandas 3.0.6, and SciPy 1.18.1. On
Windows, the environment interpreter is .venv-design/Scripts/python.exe.
Archive the environment versions and exported schedules: a seed alone does not
promise identical output across package or script upgrades.
Choosing a design
Start from the question and the structure of your units, not from a favorite design.
What are you trying to learn?
│
├─ Compare a few predefined conditions (A vs B vs C)?
│ ├─ Units independent, possibly with a known nuisance factor (day, batch, site)?
│ │ → Completely randomized (no nuisance) or RANDOMIZED BLOCK design.
│ ├─ Each unit can receive every condition in sequence (washout possible)?
│ │ → CROSSOVER / repeated-measures design (watch carry-over and correlation).
│ └─ You can only randomize groups, not individuals (schools, clinics)?
│ → CLUSTER-randomized design (account for clustering; see pseudoreplication).
│
├─ Screen MANY factors (5+) to find the few that matter?
│ → FRACTIONAL FACTORIAL or PLACKETT-BURMAN screening design.
│
├─ Quantify main effects AND interactions among a handful of factors?
│ → FULL 2^k FACTORIAL design.
│
├─ Find the settings that OPTIMIZE a response (curvature matters)?
│ → RESPONSE-SURFACE design: central composite or Box-Behnken.
│
└─ Explore a simulation/computer model over a continuous space?
→ SPACE-FILLING design: Latin hypercube.Detailed guidance per branch:
Randomization, blocking, stratification, controls →
references/randomization_and_blocking.mdFactorial, fractional-factorial, screening, response-surface, DOE concepts (aliasing, resolution) →
references/factorial_and_doe.mdCrossover, repeated-measures, split-plot, Latin-square, cluster, nested designs →
references/design_types.mdSequential, group-sequential, and adaptive designs (interim analyses) →
references/sequential_and_adaptive.md
Generating the design
Two scripts produce ready-to-use, reproducible layouts. Run them from the skill's
scripts/ directory or add it to sys.path. Seeds support reproducible layouts
within the recorded software environment.
The default seed is for demonstrations; choose and securely record a study-specific
seed for a real allocation. These helpers do not implement an enrollment system
or conceal future assignments from recruiters.
Randomization / allocation schedules — scripts/randomization.py
from randomization import (
simple_randomization, block_randomization,
stratified_block_randomization, cluster_randomization,
assign_factorial_runs, arm_balance,
)
# Permuted blocks balance at completed-block boundaries.
# A partial final block or interim prefix need not have the requested ratio.
sched = block_randomization(n=60, arms=["treatment", "control"], seed=42)
# Balance a prognostic variable across arms by randomizing within each stratum
sched = stratified_block_randomization({"siteA": 30, "siteB": 30},
arms=["drug", "placebo"], ratio=(2, 1), seed=42)
# Randomize whole clusters, not individuals (the cluster is the unit)
sched = cluster_randomization(["clinic1", "clinic2", "clinic3", "clinic4"], seed=42)
arm_balance(sched) # sanity-check the counts per arm
sched.to_csv("allocation_schedule.csv", index=False)Choosing among them: simple is fine for large n but can produce imbalance with
small n; block enforces the ratio within each complete block; stratified block
does this independently within each stratum; cluster is mandatory when the intervention
is delivered at a group level. See references/randomization_and_blocking.md.
For a sequence of stratum labels, unit_id is the original one-based input
position, including when strata are interleaved. Join the exported schedule to
your subject IDs using that position and verify every ID exactly once. A dict
input creates grouped planning slots rather than assigning an existing roster.
Missing stratum labels and duplicate cluster IDs are rejected.
DOE matrices — scripts/doe_designs.py
from doe_designs import (
full_factorial, two_level_factorial, fractional_factorial,
plackett_burman, central_composite, box_behnken, latin_hypercube,
)
# Factors as real-world (low, high) ranges -> design comes back in real units
factors = {"temp_C": (20, 60), "conc_mM": (1, 10), "pH": (6, 8)}
# Full 2^3: all main effects + all interactions (8 runs), run order randomized
design = two_level_factorial(factors, seed=42)
# Screen 7 factors cheaply (main effects only)
many = {f"factor_{i}": (0, 1) for i in range(7)}
design = plackett_burman(many, seed=42)
# Optimize over 2 factors with curvature (response-surface)
design = central_composite(
{"temp_C": (20, 60), "conc_mM": (1, 10)},
center=(2, 2), face="inscribed", seed=42,
)
design.to_csv("experimental_runs.csv", index=False)Before running a central composite design, inspect each factor's actual minimum
and maximum. The default face="circumscribed" places axial points beyond the
supplied low/high factorial settings; those arguments are not hard operating
limits. If the stated ranges are physical limits, choose face="inscribed" or
face="faced", then recheck all combinations. Do not clip out-of-range rows:
clipping changes the design geometry and its statistical properties. See the
NIST CCD comparison.
The CCD example reserves four center runs; execute them independently to estimate pure error. The wrapper default has only one. Confirm all settings are feasible, the intended model matrix has full rank, and independent replication supplies residual degrees of freedom. Center points check aggregate curvature; they do not identify each quadratic term without axial or other suitable runs.
DOE run order is randomized by default (Latin hypercube defaults to no added
run_order) so factors are not systematically aligned with time/drift
(machine warm-up, reagent aging). See references/factorial_and_doe.md for picking
generators, reading the alias structure, and choosing resolution. These wrappers
shuffle globally: for split plots, plates, or a CCD run in separate batches, retain
block IDs and randomize only within the permitted structure.
The mistakes that ruin studies
These are structural — they can't be fixed in analysis, only in design.
Pseudoreplication. Treating repeated measurements of one unit as independent replicates: 3 mice with 100 cells each is n = 3 (mice), not n = 300 (cells), for any treatment applied to the mouse. The replicate must be at the level the treatment is randomized. This single error invalidates a large share of published experiments. Randomize and replicate at the right level; analyze with the nesting respected (mixed model). See
references/design_types.md.Confounding by a nuisance variable. Running all treatment samples on Monday and all controls on Tuesday confounds treatment with day. Randomize across, or block on, every nuisance factor you can name (batch, day, plate, technician, instrument, position).
No or broken randomization. Convenience assignment (first-come → treatment) lets confounders sneak in. Use a seeded schedule and follow it.
No proper control. Without a concurrent control (and, where relevant, a vehicle/sham and blinding), you can't separate the treatment effect from time, placebo, or handling effects.
Batch effects mistaken for biology. In omics especially, process samples in a randomized/blocked order across batches; never let batch align with the condition.
Edge/position effects on plates. Evaporation and thermal gradients make plate edges differ. Randomize or block sample positions; don't put all controls in column 1.
Aliasing ignored in fractional designs. A low-resolution fractional factorial confounds main effects with interactions; know your alias structure before concluding a factor "has no effect."
Optimizing without curvature. A two-level factorial alone cannot estimate pure quadratic terms; you'll miss an interior optimum. Use a response-surface design.
Workflow
State the question, the unit, and the response. What is randomized? What is measured? At what level is a true independent replicate? This determines everything.
List nuisance factors (batch, day, site, operator, position) — plan to block, stratify, or randomize across each.
Pick the design using the decision tree and reference files.
Decide replication at the correct level (and get n from the statistical-power skill for the chosen design).
Generate the layout with
randomization.py/doe_designs.py, seeded.Randomize run/processing order and plate/batch positions within the design restrictions; verify roster IDs, completed-block balance, range limits, and rank.
Document the design, software versions, seed, and schedule. Pre-specify the analysis; restrict access to the seed and future assignments during enrollment.
Match the analysis to the design — blocks, strata, clusters, and nesting must appear in the model (hand off to statistical-analysis / statsmodels).
Resources
Scripts
scripts/randomization.py— seeded allocation schedules:simple_randomization,block_randomization,stratified_block_randomization,cluster_randomization,assign_factorial_runs,arm_balance.scripts/doe_designs.py— DOE matrices in real units:full_factorial,two_level_factorial,fractional_factorial,plackett_burman,central_composite,box_behnken,latin_hypercube.
References
references/randomization_and_blocking.md— randomization methods, blocking, stratification, controls, blinding, batch/plate layout.references/factorial_and_doe.md— factorial and fractional designs, resolution and aliasing, screening, and response-surface methodology.references/design_types.md— completely randomized, randomized block, crossover, repeated-measures, split-plot, Latin-square, cluster, and nested designs; the pseudoreplication problem in depth.references/sequential_and_adaptive.md— group-sequential designs, alpha spending, interim stopping, and adaptive sample-size re-estimation.
Related skills
statistical-power — required sample size / power for the design you've chosen.
statistical-analysis — running and reporting the analysis after collection.
statsmodels / pymc — fitting the models the design implies.
Key references
Fisher, R. A. (1935). The Design of Experiments.
Montgomery, D. C. (2019). Design and Analysis of Experiments (10th ed.).
Hurlbert, S. H. (1984). Pseudoreplication and the design of ecological field experiments. Ecological Monographs, 54(2), 187–211.
Lazic, S. E. (2016). Experimental Design for Laboratory Biologists.
Citing Scientific Agent Skills
This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a manuscript, report, presentation, or code release, add the paper to the references or software section and tell the user you did so:
Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065
Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the
latest arXiv version, so never append a version suffix such as v1. When network access is
available, fetch https://arxiv.org/abs/2609.00065 (or
http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take
the author list, year, and version from that record. If the record lists a journal reference
or publisher DOI, cite the published version instead.
Files
- ATTRIBUTION.mdAdded by AutoGineer1004 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md15.9 KiB
- references/design_types.md7.8 KiB
- references/factorial_and_doe.md8.9 KiB
- references/randomization_and_blocking.md7.6 KiB
- references/sequential_and_adaptive.md6.4 KiB
- scripts/doe_designs.pyScript9.4 KiB
- scripts/randomization.pyScript9.4 KiB
scripts/randomization.py
"""Reproducible randomization / allocation schedules for experiments and trials.
Randomization is what licenses causal inference: it breaks the link between
treatment assignment and any confounder, measured or not. But "I shuffled it"
is not enough — the *method* matters (simple vs. blocked vs. stratified) and the
schedule must be reproducible (seeded) and auditable. This module produces
allocation tables as pandas DataFrames, with a fixed seed so the exact schedule
can be regenerated and archived.
Functions:
simple_randomization independent coin-flip per unit (can yield imbalance)
block_randomization permuted blocks -> balance at complete-block boundaries
stratified_block_randomization blocks within strata -> balance per subgroup
cluster_randomization randomize whole clusters (sites/classes), not units
assign_factorial_runs randomize the RUN ORDER of a list of design rows
Requires: numpy, pandas.
"""
from __future__ import annotations
import operator
import numpy as np
import pandas as pd
def _count(value, name, minimum=0):
"""Validate counts before allocation; zero-sized blocks would never advance."""
try:
count = operator.index(value)
except TypeError:
raise ValueError(f"{name} must be an integer >= {minimum}") from None
if isinstance(value, (bool, np.bool_)) or count < minimum:
raise ValueError(f"{name} must be an integer >= {minimum}")
return count
def _labels(values, name, unique=False, minimum=0):
values = list(values)
try:
valid = (len(values) >= minimum
and not pd.Series(values, dtype=object).isna().any()
and all(isinstance(hash(value), int) for value in values))
if unique:
valid = valid and len(set(values)) == len(values)
except (TypeError, ValueError):
valid = False
if not valid:
raise ValueError(f"{name} must contain non-missing, hashable labels"
+ (" that are unique" if unique else "")
+ f" (at least {minimum})")
return values
def _normalize_ratio(arms, ratio):
"""Turn arms + integer ratio into a block template list, e.g.
arms=['A','B'], ratio=(2,1) -> ['A','A','B']."""
arms = _labels(arms, "arms", unique=True, minimum=2)
if ratio is None:
ratio = [1] * len(arms)
if len(ratio) != len(arms):
raise ValueError("ratio must have one entry per arm")
try:
invalid = any(isinstance(r, (bool, np.bool_)) or r <= 0 or int(r) != r
for r in ratio)
except (TypeError, ValueError, OverflowError):
invalid = True
if invalid:
raise ValueError("ratio entries must be positive integers")
template = []
for arm, r in zip(arms, ratio):
template += [arm] * int(r)
return template
def simple_randomization(n, arms=("treatment", "control"), ratio=None, seed=0):
"""Independent random assignment per unit.
Simplest method; with small n it can produce noticeable arm-size imbalance
(like flipping few coins). Fine for large n. Use block_randomization when you
need tighter control of arm counts or have sequential enrollment.
"""
n = _count(n, "n")
rng = np.random.default_rng(seed)
arms = list(arms)
template = _normalize_ratio(arms, ratio)
probs = np.array([template.count(a) for a in arms], dtype=float)
probs /= probs.sum()
# Preserve labels when arms mix numeric and string values.
labels = np.empty(len(arms), dtype=object)
labels[:] = arms
assign = rng.choice(labels, size=n, p=probs)
return pd.DataFrame({"unit_id": np.arange(1, n + 1), "arm": assign})
def block_randomization(n, arms=("treatment", "control"), block_size=None,
ratio=None, seed=0):
"""Permuted-block randomization: exact ratio at complete-block boundaries.
Within each block every arm appears in the specified ratio; the order inside
a block is shuffled. block_size must be a multiple of sum(ratio). Leaving it
None picks a small valid size. Partial blocks need not balance. This helper
uses a fixed block size; it does not implement variable block sizes or
allocation concealment. Keep the seed/schedule away from enrolling staff.
"""
n = _count(n, "n")
rng = np.random.default_rng(seed)
arms = list(arms)
template = _normalize_ratio(arms, ratio)
unit = len(template)
if block_size is None:
block_size = unit * 2 # two of each ratio-unit per block
block_size = _count(block_size, "block_size", minimum=1)
if block_size % unit != 0:
raise ValueError(f"block_size ({block_size}) must be a multiple of "
f"sum(ratio)={unit}")
reps = block_size // unit
out = []
block_id = 0
while len(out) < n:
block = template * reps
rng.shuffle(block)
for a in block:
out.append((len(out) + 1, block_id, a))
block_id += 1
df = pd.DataFrame(out[:n], columns=["unit_id", "block", "arm"])
return df
def stratified_block_randomization(strata, arms=("treatment", "control"),
block_size=None, ratio=None, seed=0):
"""Block-randomize independently within each stratum.
Use when a prognostic variable (site, sex, disease stage) must be balanced
across arms. `strata` is a dict {stratum_label: n_in_that_stratum} or a
sequence of stratum labels (one per unit). Sequence inputs retain their input
order: unit_id is the original one-based position. Map real subject IDs to
these positions before use. Dict inputs produce grouped planning schedules.
Balance is exact only for complete blocks within each stratum.
"""
arms = list(arms)
_normalize_ratio(arms, ratio)
seed = _count(seed, "seed")
if isinstance(strata, dict):
_labels(strata, "strata")
items = [(label, _count(count, "stratum count"), None)
for label, count in strata.items()]
else: # sequence of labels, with original unit identities retained
labels = _labels(strata, "strata")
positions = {}
for position, label in enumerate(labels, start=1):
positions.setdefault(label, []).append(position)
items = [(label, len(ids), ids) for label, ids in positions.items()]
frames = []
next_id = 1
for i, (label, count, ids) in enumerate(items):
df = block_randomization(count, arms=arms, block_size=block_size,
ratio=ratio, seed=seed + 1 + i)
df["unit_id"] = ids if ids is not None else np.arange(next_id, next_id + count)
next_id += count
df.insert(1, "stratum", pd.Series([label] * count, dtype=object))
frames.append(df)
if not frames:
return pd.DataFrame(columns=["unit_id", "stratum", "block", "arm"])
out = pd.concat(frames, ignore_index=True)
return out.sort_values("unit_id").reset_index(drop=True)
def cluster_randomization(clusters, arms=("treatment", "control"), ratio=None,
block_size=None, seed=0):
"""Randomize whole clusters (clinics, schools, litters) to arms.
The cluster — not the individual — is the unit of randomization AND the unit
of analysis-level independence. `clusters` is a list of cluster IDs (or an int
count). Returns one row per cluster. Analyze with a method that accounts for
clustering (mixed model / GEE); treating members as independent is
pseudoreplication. Uses blocking across clusters for arm balance.
"""
if isinstance(clusters, (int, np.integer)):
clusters = [f"cluster_{i+1}" for i in range(_count(clusters, "clusters"))]
clusters = _labels(clusters, "clusters", unique=True)
df = block_randomization(len(clusters), arms=arms, ratio=ratio,
block_size=block_size, seed=seed)
df = df.drop(columns=["unit_id"])
df.insert(0, "cluster_id", clusters)
return df
def assign_factorial_runs(design_df, seed=0):
"""Randomize the execution order of a set of design runs (e.g. a DOE matrix).
Run order matters: executing a factorial design in a systematic order
confounds the factors with time/drift (the machine warms up, the reagent
degrades). Randomizing run order protects against that. Returns the design
with a 'run_order' column and rows sorted by it.
"""
rng = np.random.default_rng(seed)
df = design_df.copy().reset_index(drop=True)
order = rng.permutation(len(df)) + 1
df["run_order"] = order
return df.sort_values("run_order").reset_index(drop=True)
def arm_balance(df, arm_col="arm", by=None):
"""Quick check: counts per arm (optionally within each stratum/block)."""
if by:
return df.groupby([by, arm_col]).size().unstack(fill_value=0)
return df[arm_col].value_counts()
if __name__ == "__main__":
print("== simple (n=10) ==")
print(arm_balance(simple_randomization(10, seed=1)).to_dict())
print("\n== permuted blocks, 2:1 treatment:control, n=12 ==")
d = block_randomization(12, arms=["treatment", "control"], ratio=(2, 1), seed=1)
print(d.to_string(index=False))
print("balance:", arm_balance(d).to_dict())
print("\n== stratified by site (A=8, B=6) ==")
d = stratified_block_randomization({"siteA": 8, "siteB": 6}, seed=1)
print(arm_balance(d, by="stratum").to_string())
print("\n== cluster randomization (6 clinics) ==")
print(cluster_randomization(6, seed=1).to_string(index=False))
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Declares allowed tools, Needs network access, Needs Python
The author says: Requires Python >=3.12 with numpy, pandas, and pydoe 1.5.0 (DOE matrices). Network access is needed only to install packages; no credentials are required.
Security
What our scanner noticed· Low risk
- Instructions that use the network
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- K-Dense Inc.
- Publisher
- K-Dense (Community)
- Source
- K-Dense-AI/scientific-agent-skills · skills/experimental-design · commit a25cf9e
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by K-Dense Inc. or K-Dense.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download experimental-design.zip