mixle.doe.analysis module

Analysis of designed experiments: factorial effects and second-order response surfaces.

These turn the runs of a design (see mixle.doe.factorial) and their measured responses into the quantities a practitioner reads off: the effect of each factor and interaction in a two-level design, and – for a response-surface design – the fitted second-order model, its stationary point, and the canonical (eigenvalue) analysis that says whether that point is a maximum, minimum, or saddle.

class FactorialEffects(terms, coef, effects, intercept, residual_std)[source]

Bases: object

Estimated effects from a two-level factorial / fractional-factorial / Plackett-Burman design.

Parameters:
terms

term names ("intercept", "x0", "x0:x1", …).

Type:

list[str]

coef

least-squares regression coefficients in coded +/-1 units.

Type:

numpy.ndarray

effects

the classical effect per term – the change in mean response as a factor moves from its low to its high level, i.e. 2 * coef (the intercept entry is just the grand mean).

Type:

numpy.ndarray

intercept

the grand mean of the response.

Type:

float

residual_std

residual standard deviation when the design has spare runs (else None).

Type:

float | None

terms: list[str]
coef: ndarray
effects: ndarray
intercept: float
residual_std: float | None
as_dict()[source]

Map each non-intercept term to its effect.

Return type:

dict[str, float]

factorial_effects(design, y, *, interactions=True, coded=False)[source]

Estimate main effects and two-factor interactions from a two-level design.

Fits the linear model y ~ 1 + x_i (+ x_i x_j) in coded +/-1 units by least squares; the coefficients are half the classical effects. design is the (n, d) run matrix (the real factor levels, coded to +/-1 automatically – or pass coded=True if it is already +/-1), y the measured responses. Set interactions=False for a main-effects-only (e.g. screening) fit.

Parameters:
Return type:

FactorialEffects

class ResponseSurface(coef, terms, b, B, stationary_point, eigenvalues, kind, residual_std)[source]

Bases: object

A fitted second-order response surface y = b0 + b'x + x'Bx and its canonical analysis.

Parameters:
coef

full coefficient vector (intercept, linears, then the upper-triangular second-order terms).

Type:

numpy.ndarray

terms

matching term names.

Type:

list[str]

b

linear coefficient vector (d,).

Type:

numpy.ndarray

B

symmetric (d, d) matrix of quadratic coefficients (cross terms split onto both halves).

Type:

numpy.ndarray

stationary_point

x* solving grad = b + 2 B x = 0 (least-squares if B is singular).

Type:

numpy.ndarray

eigenvalues

eigenvalues of B – all negative => the stationary point is a maximum, all positive => a minimum, mixed signs => a saddle (a ridge if some are ~0).

Type:

numpy.ndarray

kind

"maximum" / "minimum" / "saddle".

Type:

str

residual_std

residual standard deviation when the design has spare runs (else None).

Type:

float | None

coef: ndarray
terms: list[str]
b: ndarray
B: ndarray
stationary_point: ndarray
eigenvalues: ndarray
kind: str
residual_std: float | None
predict(x)[source]

Predict the response at points x (m, d) from the fitted surface.

Return type:

ndarray

gradient(x)[source]

The response gradient b + 2 B x at x – its direction is the path of steepest ascent.

Return type:

ndarray

response_surface(x, y)[source]

Fit a full second-order (quadratic) response surface and analyse its stationary point.

Least-squares-fits y = b0 + sum b_i x_i + sum_{i<=j} b_{ij} x_i x_j to the design runs x (n, d) and responses y, then solves for the stationary point x* = -1/2 B^{-1} b and classifies it from the eigenvalues of the quadratic matrix B. Fit on the coded design for a well-conditioned model (the classic central-composite / Box-Behnken workflow).

Return type:

ResponseSurface

design_diagnostics(design, model, *, ref=None)[source]

Quality diagnostics for a design under a model – “is this a good design to run?”.

Builds the model matrix F = model(design) and reports, relative to a hypothetical perfectly orthogonal design (where each is 1.0):

  • d_efficiencydet(M)**(1/p) / n: overall coefficient-estimation precision;

  • a_efficiencyp / (n * trace(M^-1)): average coefficient variance;

  • g_efficiencyp / (n * max prediction variance) over ref (or the design itself);

  • condition_number of M (large => near-collinear / fragile to fit);

  • max_correlation – the largest absolute pairwise correlation among the non-intercept model columns (the aliasing check; 0 for an orthogonal design).

model is a model-matrix function such as mixle.doe.optimal.polynomial_features(). Use it on the coded design for meaningful efficiencies.

Return type:

dict