Skip to content
svgmain-effects

Main effects

How does the mean response change across each factor's levels?

Demo data · seed 20261101 · 8 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read each panel as one factor: mean response at each level.
  2. Steeper lines mean larger main effects.
  3. Compare with the dashed grand mean.
  1. Callout 1: A steep line: a large effect.
  2. Callout 2: A shallow line: a small effect.
  3. Callout 3: The grand mean.

Watch out

  • If factors interact, a main effect alone can mislead: check the interaction plot too.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Levels are drawn in the order sent (coded low → high); the y axis is shared across a response's panels so slopes compare. The dashed line is the grand mean of the first factor's level means.
  • Main effects can mislead when interactions are large — check the interaction plot and the effects screening first.
# Main effects — Codesplash Chart Lab (recipe "main-effects")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("main-effects-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["factor"] = pd.Categorical(df["factor"].astype("string"), categories=["Temperature", "Pressure", "Concentration", "Stirring"])
df["level"] = pd.Categorical(df["level"].astype("string"), categories=["low", "high"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
F = "factor"
L = "level"
M = "mean filtration rate"
RESP = None
factors = levels_of(df[F])
fig, axes = plt.subplots(1, len(factors), figsize=(2.2 * len(factors) + 1, 3.6), sharey=True, squeeze=False)
grand = df[df[F].astype(str) == str(factors[0])][M].mean()
for ax, f in zip(axes[0], factors):
    d = df[df[F].astype(str) == str(f)]
    ax.plot(d[L].astype(str), d[M], marker="o", color=PALETTE[0], linewidth=1.8)
    ax.axhline(grand, color=REF, linestyle="--", linewidth=1)
    ax.set_title(str(f), fontsize=10, loc="left")
axes[0, 0].set_ylabel(M)
plt.show()

Needs pandas, numpy, matplotlib · reads main-effects-demo.csv · app theme from the optional codesplash helper