Skip to content

Design an experiment

Vary factors together rather than one at a time, and use fractions, resolution and randomization to get the most from a limited number of runs.

Applied ~13 min10 steps

What runs in CodeSplash

You will be able to

  • Say why a factorial beats changing one factor at a time
  • Read a fraction's resolution and alias structure
  • Use center points, replicates, blocks and randomization for what each one protects against
01

One factor at a time

Read

You want to improve a process with temperature, pressure and catalyst, each at two settings. The careful-sounding plan is to change one thing, keep the best, and change the next.

02

How many runs?

Predict

Predict first

A full factorialFactorial designAn experiment that varies several factors together, so it can estimate their interactions efficiently. tests every combination of those three factors at two levels each. How many runs does that take?

4 runs, the same as one at a time8 runs16 runs
Reveal

23=2^3 = 8 runs. Each main effect then compares four runs with the other four, so every run is used to estimate every effect. One at a time spends its runs on one comparison each, and it can't see an interaction at all.

03

See an interaction

Explore

An interaction means one factor's effect depends on another's setting.

DExplorable · Interactions and simple slopes

When the effect of x depends on a moderator, where is it actually different from zero?

What is the slope of x at this moderator value?

0.0
How sure?
0.50
120
0.0

Centering: with a mean far from zero, the coefficient on x describes a moderator value no one has.

1.0
no effectJ–NJ–N

Where the band excludes zero, the slope of x is significant at that moderator value. Johnson–Neyman (J–N) marks the boundaries.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Raise the true interaction, and watch the slope of x change with the moderator. In a factorial, that's the same idea with two settings of each factor. What would changing x alone have told you, and at which setting of the moderator would it hold?

04

Too many factors

Predict

Predict first

Six factors at two levels would take 262^6, or 64, runs. A resolution IV fraction runs a quarter of those, plus 3 center points. How many runs is that?

64198
Reveal

19 runs: 16 plus 3 center points. A fractional factorialFractional factorialA subset of a factorial's runs that trades some interactions for far fewer runs; resolution says which effects get mixed up. works because the highest-order interactions are usually small. You pay for the saving in aliasing: some effects can't be told apart.

05

Resolution

Read

The fraction's resolution says what gets mixed up:

ResolutionMain effects are aliased withUse it for
IIITwo-factor interactionsScreening many factors
IVThree-factor interactionsScreening, when main effects must be clean
VFour-factor interactionsEstimating two-factor interactions too

Your design here: A 2^(6−2) fractional factorial design, at resolution IV. Its alias list reads like A = BCE = DEF: the estimate for A also contains those three-factor interactions.

06

Read a design

In the app
Design an experiment (factorial, screening, response surface, Latin hypercube)Recorded · Python and R agreeRecorded 2026-11-17 · 15 values compared
R

A 2^(6−2) fractional factorial design for 6 factors in 19 runs (resolution IV), randomized.

Factors
6
Runs
19
Blocks
1
Center points
3
Resolution
4

Run sheet

RunStd orderPoint typeABCDEF
16factorial2011.50010034
211factorial1020.500020061
312factorial2020.500020031
49factorial1010.500020034
518center151.50011504.5002.500
64factorial2020.500010034
710factorial2010.500020064
819center151.50011504.5002.500
916factorial2021.50020064
105factorial1011.50010064
118factorial2021.50010061
123factorial1020.500010064
1315factorial1021.50020034
147factorial1021.50010031
1514factorial2011.50020031
1617center151.50011504.5002.500
172factorial2010.500010061
1813factorial1011.50020061
191factorial1010.500010031

Alias structure (main effects and two-factor interactions, up to three-factor aliases)

Aliases
A = BCE = DEF
B = ACE = CDF
C = ABE = BDF
D = AEF = BCF
E = ABC = ADF
F = ADE = BCD
AB = CE
AC = BE
AD = EF
AE = BC = DF
AF = DE
BC = AE = DF
BD = CF
BE = AC
BF = CD
CD = BF
CE = AB
CF = BD
DE = AF
DF = AE = BC
EF = AD

Defining relation

WordLength
I = ABCE4
I = ADEF4
I = BCDF4
  • Standard order: the first factor changes fastest. Coded units: low = −1, high = +1.
The exact R script · R R version 4.5.1 (2025-06-13)
# Design an experiment (factorial, screening, response surface, Latin hypercube)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method doe.design 1.0.1 · spec 17a25220dbeb1a17
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_doe_build(): twin of codesplash.quality.design (identical run sheets in Python)

# Classic equivalents: FrF2::FrF2(), FrF2::pb(), rsm::ccd(), rsm::bbd(), lhs::maximinLHS() — they order and
# randomize runs differently, so the twin builds the design that both engines share.

# %% Design
factors <- cs_doe_parse_factors("A: 10, 20; B: 1, 2; C: 0.5, 1.5; D: 100, 200; E: 3, 6; F: 1, 4")
reserved <- c("Run", "Std order", "Block", "Point type")
for (f in factors) if (f$name %in% reserved) stop(sprintf("“%s” is a run-sheet column name; rename the factor.", f$name), call. = FALSE)
d <- cs_doe_build(
  factors, "fractional_factorial",
  runs = NULL,
  min_resolution = 4,
  generators = "",
  center_points = 3,
  replicates = 1,
  block_replicates = FALSE,
  ccd_type = "circumscribed",
  ccd_blocks = FALSE,
  lhs_criterion = "maximin",
  lhs_iterations = 50,
  seed = 42,
  randomize = TRUE
)
k <- length(d$factors)
n_runs <- nrow(d$coded)
n_blocks <- length(unique(d$block))
n_center <- sum(d$point_type == "center")
actual <- cs_doe_actual(d)

# %% Run sheet (in run order) — written for the studio and for data entry
ord <- order(d$run_order, method = "radix")
sheet <- data.frame(Run = d$run_order[ord], `Std order` = d$std_order[ord], Block = d$block[ord],
                    `Point type` = d$point_type[ord], check.names = FALSE, stringsAsFactors = FALSE)
for (j in seq_len(k)) sheet[[d$factors[[j]]$name]] <- actual[[j]][ord]
out <- "target/academy-parity/run-84541/doe.design/fraction-res4-centre/out-r"
if (is.null(out)) out <- if (nzchar(Sys.getenv("CS_OUT_DIR"))) Sys.getenv("CS_OUT_DIR") else "outputs"
dir.create(out, recursive = TRUE, showWarnings = FALSE)
design_path <- file.path(out, "design.parquet")
nanoparquet::write_parquet(sheet, design_path)

# %% Result
warnings <- as.list(d$notes)
shown <- utils::head(sheet, 1000)
columns <- list(list(key = "run", label = "Run", type = "integer"), list(key = "std", label = "Std order", type = "integer"))
if (n_blocks > 1) columns[[length(columns) + 1]] <- list(key = "block", label = "Block", type = "integer")
columns[[length(columns) + 1]] <- list(key = "ptype", label = "Point type", type = "string")
for (j in seq_len(k)) columns[[length(columns) + 1]] <- list(key = paste0("f", j - 1), label = d$factors[[j]]$name,
                                                         type = if (d$factors[[j]]$numeric) "number" else "string")
rows <- lapply(seq_len(nrow(shown)), function(i) {
  row <- list(run = shown$Run[i], std = shown$`Std order`[i], block = shown$Block[i], ptype = shown$`Point type`[i])
  for (j in seq_len(k)) row[[paste0("f", j - 1)]] <- shown[[d$factors[[j]]$name]][i]
  row
})
tables <- list(list(key = "runs", title = "Run sheet", columns = columns, rows = rows,
                    note = if (nrow(sheet) <= 1000) NULL else sprintf("First 1,000 of %s runs shown; the full sheet is in the design file.", format(nrow(sheet), big.mark = ","))))
if (length(d$aliases)) tables[[length(tables) + 1]] <- list(
  key = "aliases", title = "Alias structure (main effects and two-factor interactions, up to three-factor aliases)",
  columns = list(list(key = "alias", label = "Aliases", type = "string")),
  rows = lapply(d$aliases, function(a) list(alias = a)))
if (length(d$words)) tables[[length(tables) + 1]] <- list(
  key = "defining", title = "Defining relation",
  columns = list(list(key = "word", label = "Word", type = "string"), list(key = "length", label = "Length", type = "integer")),
  rows = lapply(d$words, function(w) list(word = paste("I =", w), length = nchar(w))))
charts <- list()
if (k >= 2 && d$kind %in% c("ccd", "box_behnken", "lhs")) {
  charts[[1]] <- cs_chart(
    "space", "scatter", sprintf("Design points: %s × %s (coded)", d$factors[[1]]$name, d$factors[[2]]$name),
    list(x = cs_col(paste(d$factors[[1]]$name, "(coded)"), d$coded[, 1]),
         y = cs_col(paste(d$factors[[2]]$name, "(coded)"), d$coded[, 2]),
         color = cs_col("Point type", d$point_type, "categorical")),
    controls = list(fit = "none"))
}
roman <- cs_doe_roman(d$resolution)
values <- list(
  k = k, runs = n_runs, n_blocks = n_blocks, n_center = n_center, design_label = d$label,
  resolution = d$resolution, resolution_roman = roman, alpha = d$alpha,
  generators = I(d$generators), words = I(d$words), aliases = I(d$aliases),
  run_order = I(d$run_order), point_type = I(d$point_type), block = I(d$block),
  coded = d$coded
)
summary <- sprintf("%s for %d factor%s in %d runs", d$label, k, if (k != 1) "s" else "", n_runs)
if (!is.na(d$resolution)) summary <- paste0(summary, sprintf(" (resolution %s)", roman))
summary <- paste0(summary, if (TRUE) ", randomized" else ", in standard order")
if (n_blocks > 1) summary <- paste0(summary, sprintf(" in %d blocks", n_blocks))
summary <- paste0(summary, ".")
stats_list <- list(list(key = "k", label = "Factors", value = k, format = "integer"),
                   list(key = "runs", label = "Runs", value = n_runs, format = "integer"),
                   list(key = "n_blocks", label = "Blocks", value = n_blocks, format = "integer"),
                   list(key = "n_center", label = "Center points", value = n_center, format = "integer"))
if (!is.na(d$resolution)) stats_list[[length(stats_list) + 1]] <- list(key = "resolution", label = "Resolution", value = d$resolution, format = "integer")
cs_publish(list(
  method = "doe.design",
  methodVersion = "1.0.1",
  title = "Design an experiment (factorial, screening, response surface, Latin hypercube)",
  engine = cs_engine_info("codesplashr", "nanoparquet"),
  summary = summary,
  statistics = stats_list,
  tables = tables,
  charts = charts,
  warnings = warnings,
  notes = list("Standard order: the first factor changes fastest. Coded units: low = −1, high = +1."),
  values = values,
  artifacts = list(list(key = "design", path = design_path, format = "parquet", title = "Run sheet"))
))
Python

A 2^(6−2) fractional factorial design for 6 factors in 19 runs (resolution IV), randomized.

Factors
6
Runs
19
Blocks
1
Center points
3
Resolution
4

Run sheet

RunStd orderPoint typeABCDEF
16factorial2011.50010034
211factorial1020.500020061
312factorial2020.500020031
49factorial1010.500020034
518center151.50011504.5002.500
64factorial2020.500010034
710factorial2010.500020064
819center151.50011504.5002.500
916factorial2021.50020064
105factorial1011.50010064
118factorial2021.50010061
123factorial1020.500010064
1315factorial1021.50020034
147factorial1021.50010031
1514factorial2011.50020031
1617center151.50011504.5002.500
172factorial2010.500010061
1813factorial1011.50020061
191factorial1010.500010031

Alias structure (main effects and two-factor interactions, up to three-factor aliases)

Aliases
A = BCE = DEF
B = ACE = CDF
C = ABE = BDF
D = AEF = BCF
E = ABC = ADF
F = ADE = BCD
AB = CE
AC = BE
AD = EF
AE = BC = DF
AF = DE
BC = AE = DF
BD = CF
BE = AC
BF = CD
CD = BF
CE = AB
CF = BD
DE = AF
DF = AE = BC
EF = AD

Defining relation

WordLength
I = ABCE4
I = ADEF4
I = BCDF4
  • Standard order: the first factor changes fastest. Coded units: low = −1, high = +1.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Design an experiment (factorial, screening, response surface, Latin hypercube)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method doe.design 1.0.1 · spec 17a25220dbeb1a17
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import os

import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.quality import design as doe  # twin of codesplashr::cs_doe_build (identical run sheets in R)

# Classic equivalent: pyDOE3 (ff2n / fracfact / pbdesign / ccdesign / bbdesign / lhs) — its row order and
# randomization differ, so the twin builds the design that both engines share.

# %% Design
factors = doe.parse_factors("A: 10, 20; B: 1, 2; C: 0.5, 1.5; D: 100, 200; E: 3, 6; F: 1, 4")
for f in factors:
    if f.name in doe.RESERVED:
        raise ValueError(f"“{f.name}” is a run-sheet column name; rename the factor.")
d = doe.build(
    factors,
    "fractional_factorial",
    runs=None,
    min_resolution=4,
    generators="",
    center_points=3,
    replicates=1,
    block_replicates=False,
    ccd_type="circumscribed",
    ccd_blocks=False,
    lhs_criterion="maximin",
    lhs_iterations=50,
    seed=42,
    randomize=True,
)
k = len(d.factors)
n_runs = d.coded.shape[0]
n_blocks = len(set(d.block))
n_center = sum(1 for t in d.point_type if t == "center")
actual = doe.actual(d)

# %% Run sheet (in run order) — written for the studio and for data entry
order = np.argsort(np.asarray(d.run_order), kind="stable")
sheet = pd.DataFrame({
    "Run": [d.run_order[i] for i in order],
    "Std order": [d.std_order[i] for i in order],
    "Block": [d.block[i] for i in order],
    "Point type": [d.point_type[i] for i in order],
})
for f, col in zip(d.factors, actual):
    sheet[f.name] = [col[i] for i in order]
out = "target/academy-parity/run-84541/doe.design/fraction-res4-centre/out-python" or os.environ.get("CS_OUT_DIR") or "outputs"
os.makedirs(out, exist_ok=True)
design_path = os.path.join(out, "design.parquet")
sheet.to_parquet(design_path, index=False)

# %% Result
warnings = list(d.notes)
shown = sheet.head(1000)
columns = [
    {"key": "run", "label": "Run", "type": "integer"},
    {"key": "std", "label": "Std order", "type": "integer"},
]
if n_blocks > 1:
    columns.append({"key": "block", "label": "Block", "type": "integer"})
columns.append({"key": "ptype", "label": "Point type", "type": "string"})
rows = []
for _, r in shown.iterrows():
    row = {"run": int(r["Run"]), "std": int(r["Std order"]), "block": int(r["Block"]), "ptype": r["Point type"]}
    for j, f in enumerate(d.factors):
        row[f"f{j}"] = r[f.name] if not f.numeric or isinstance(r[f.name], str) else float(r[f.name])
    rows.append(row)
for j, f in enumerate(d.factors):
    columns.append({"key": f"f{j}", "label": f.name, "type": "number" if f.numeric else "string"})
tables = [{"key": "runs", "title": "Run sheet", "columns": columns, "rows": rows,
           "note": None if len(sheet) <= 1000 else f"First 1,000 of {len(sheet):,} runs shown; the full sheet is in the design file."}]
if d.aliases:
    tables.append({
        "key": "aliases", "title": "Alias structure (main effects and two-factor interactions, up to three-factor aliases)",
        "columns": [{"key": "alias", "label": "Aliases", "type": "string"}],
        "rows": [{"alias": a} for a in d.aliases],
    })
if d.words:
    tables.append({
        "key": "defining", "title": "Defining relation",
        "columns": [{"key": "word", "label": "Word", "type": "string"}, {"key": "length", "label": "Length", "type": "integer"}],
        "rows": [{"word": "I = " + w, "length": len(w)} for w in d.words],
    })
charts = []
if k >= 2 and d.kind in ("ccd", "box_behnken", "lhs"):
    charts.append(cs.chart(
        "space", "scatter", f"Design points: {d.factors[0].name} × {d.factors[1].name} (coded)",
        {"x": cs.col(f"{d.factors[0].name} (coded)", d.coded[:, 0].tolist()),
         "y": cs.col(f"{d.factors[1].name} (coded)", d.coded[:, 1].tolist()),
         "color": cs.col("Point type", list(d.point_type), "categorical")},
        controls={"fit": "none"},
    ))
roman = doe.ROMAN.get(d.resolution) if d.resolution else None
values = {
    "k": k, "runs": n_runs, "n_blocks": n_blocks, "n_center": n_center, "design_label": d.label,
    "resolution": d.resolution, "resolution_roman": roman, "alpha": d.alpha,
    "generators": list(d.generators), "words": list(d.words), "aliases": list(d.aliases),
    "run_order": list(d.run_order), "point_type": list(d.point_type), "block": list(d.block),
    "coded": d.coded.tolist(),
}
summary = f"{d.label} for {k} factor{'s' if k != 1 else ''} in {n_runs} runs"
if d.resolution:
    summary += f" (resolution {roman})"
summary += ", randomized" if True else ", in standard order"
if n_blocks > 1:
    summary += f" in {n_blocks} blocks"
summary += "."
cs.publish({
    "title": "Design an experiment (factorial, screening, response surface, Latin hypercube)",
    "engine": cs.engine_info("numpy", "pandas"),
    "summary": summary,
    "statistics": [
        {"key": "k", "label": "Factors", "value": k, "format": "integer"},
        {"key": "runs", "label": "Runs", "value": n_runs, "format": "integer"},
        {"key": "n_blocks", "label": "Blocks", "value": n_blocks, "format": "integer"},
        {"key": "n_center", "label": "Center points", "value": n_center, "format": "integer"},
    ] + ([{"key": "resolution", "label": "Resolution", "value": d.resolution, "format": "integer"}] if d.resolution else []),
    "tables": tables,
    "charts": charts,
    "warnings": warnings,
    "notes": ["Standard order: the first factor changes fastest. Coded units: low = −1, high = +1."],
    "values": values,
    "artifacts": [{"key": "design", "path": design_path, "format": "parquet", "title": "Run sheet"}],
})

The card lists the generators, the alias structure and the randomized run sheet. Look for where each factor's main effect is aliased.

A 12-run Plackett–Burman design goes further, with 11 factors in 12 runs, at resolution III. It finds the vital few, and you follow up on them.

07

Protect the comparison

Read

Four options protect different things:

  • Randomize the run order: so a slow drift, like a warming machine, doesn't line up with a factor.
  • Center points: runs at the middle of every numeric factor, which detect curvatureCenter pointsRuns at the middle of every numeric factor, which test for curvature and estimate noise without changing the effect estimates. and estimate pure error.
  • Replicates: repeat the whole design, for a better estimate of noise.
  • Blocks: when runs span days or batches, keep those differences out of the factor effects.
08

Check your understanding

Checkpoint

Check yourself

You have 7 factors and can afford 8 runs, which gives resolution III. A main effect looks large. What must you keep in mind?

Show the answer

Answer: b

Resolution III mixes main effects with two-factor interactions. Screening shows where to look, and a follow-up separates the two.

Check yourself

For convenience, you run all the low-temperature settings in the morning and all the high ones in the afternoon. What's the problem?

Show the answer

Answer: b

Randomizing protects against drifts you can't see. If some factors are hard to change, plan for that deliberately, and say so.

Check yourself

What can center points show that the corner runs of a two-level design can't?

Show the answer

Answer: b

Two levels can only draw straight lines. If the middle isn't where the corners predict, the response is curved.

09

Try it

In the app

In the Quality studio, choose Screening experiment or Full factorial. Enter your factors on the Factors & design step, then fill in responses on the Run sheet step, in the randomized order it gives you.

Python
from itertools import product

import numpy as np
import pandas as pd

# A 2^(6-2) fraction: E = ABC, F = BCD, plus 3 center points
base = np.array(list(product([-1, 1], repeat=4)))
a, b, c, d = base.T
design = pd.DataFrame({"A": a, "B": b, "C": c, "D": d, "E": a * b * c, "F": b * c * d})
centre = pd.DataFrame(np.zeros((3, 6), dtype=int), columns=design.columns)
design = pd.concat([design, centre], ignore_index=True)

run_sheet = design.sample(frac=1, random_state=1)  # randomized order
print(len(run_sheet))
R
library(FrF2)

# A 2^(6-2) fraction with the generators E = ABC, F = BCD
design <- FrF2(16, 6, generators = c("ABC", "BCD"), ncenter = 3, randomize = TRUE, seed = 1)
nrow(design)
design.info(design)$aliased

These scripts randomize with each language's own generator, so their run orders differ from CodeSplash's.

10

Recap

Recap
  • A factorial uses every run for every effect, and it can see interactions.
  • Fractions save runs by aliasing effects, and resolution says which.
  • Randomize the order. Add center points, replicates or blocks for what you need to protect.

Concepts in this lesson