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, se, aliases, estimable_contrasts)[source]
Bases:
objectEstimated effects from a two-level factorial / fractional-factorial / Plackett-Burman design.
Only estimable quantities are reported as effects. When the design cannot separate two or more terms – classical aliasing/confounding, including a factor that never varies – those individual terms have no unique estimate: their entries in
coef/effectsarenan.aliasessays which terms are aliased with which;estimable_contrastsgives the one well-defined combined quantity the data actually supports for each such group.- Parameters:
- coef
least-squares regression coefficients in coded
+/-1units (nanfor a term that is aliased with another and so has no individual estimate).- Type:
- 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:
- intercept
the grand mean of the response (
nanif the intercept itself is aliased, e.g. with a factor that never varies).- Type:
- residual_std
residual standard deviation when the design has spare runs (else
None).- Type:
float | None
- se
standard error of each entry of
effects.Nonethroughout when the design has no spare degrees of freedom to estimate a residual variance (e.g. a saturated design); individual entries arenanwherevereffectsis (aliased terms).- Type:
numpy.ndarray | None
- aliases
for each term, the other term names it is aliased with (empty list if the term is uniquely estimable).
- estimable_contrasts
for each alias group of two or more terms, keyed by its member term names joined by their signed defining relation (for example
"x0-x1"for opposite columns), the(effect, se)of the exact combined quantity that is estimable – empty when the design has no aliasing.
- 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+/-1units by least squares; the coefficients are half the classical effects.designis the(n, d)run matrix (the real factor levels, coded to+/-1automatically – or passcoded=Trueif it is already coded, in which case every entry must be exactly-1.0or1.0),ythe measured responses. Setinteractions=Falsefor a main-effects-only (e.g. screening) fit.Rejects designs that cannot support the requested model outright: non-finite values, fewer runs than model parameters, and (for
coded=True) levels other than+/-1. A design that has enough runs but still cannot separate every term – aliasing, including a factor that never varies – is not rejected: the aliased terms come back asnanincoef/effects, with the one combined quantity the data does support reported inestimable_contrasts(seeFactorialEffects). That automatic resolution only covers the classical case where the aliasing is exact term-for-term confounding, as in any standard fractional-factorial / Plackett-Burman alias structure; a design that is rank-deficient for some other reason (e.g. too few runs and not a clean fractional design) raises instead of guessing which contrasts might be estimable.
- class ResponseSurface(coef, terms, b, B, stationary_point, eigenvalues, kind, residual_std, model_rank, n_parameters, degrees_of_freedom, estimable)[source]
Bases:
objectA fitted second-order response surface
y = b0 + b'x + x'Bxand its canonical analysis.- Parameters:
- coef
full coefficient vector (intercept, linears, then the upper-triangular second-order terms).
- Type:
- b
linear coefficient vector
(d,).- Type:
- B
symmetric
(d, d)matrix of quadratic coefficients (cross terms split onto both halves).- Type:
- stationary_point
x*solving the stationarity equationB x* = -b/2, orNonewhen no such point exists – i.e. the gradientb + 2 B xis never zero anywhere, which can only happen whenBis singular (kind == "no_stationary_point"; see below).- Type:
numpy.ndarray | None
- eigenvalues
eigenvalues of
B– all negative => a maximum, all positive => a minimum, mixed signs => a saddle; any eigenvalue ~0 (with a genuine stationary point) => a ridge, a whole line/subspace of equally-stationary points, of whichstationary_pointis one representative (the minimum-norm) point.- Type:
- kind
"maximum"/"minimum"/"saddle"/"ridge"/"no_stationary_point". The last case is distinct from a ridge: a ridge is a genuine (degenerate) stationary subspace, while"no_stationary_point"means the stationarity equation has no solution at all (e.g. the exact surfacey = x0**2 + x1, whose gradient’s second component is always exactly1).- Type:
- residual_std
residual standard deviation when the design has spare runs (else
None).- Type:
float | None
- model_rank
rank of the fitted quadratic model matrix.
- Type:
- n_parameters
number of quadratic coefficients requested.
- Type:
- degrees_of_freedom
residual degrees of freedom,
n_runs - n_parameters.- Type:
- estimable
whether every requested coefficient is identified. Construction refuses a non-estimable fit, so returned surfaces always report
True.- Type:
- predict(x)[source]
Predict the response at points
x(m, d)from the fitted surface.- Return type:
- 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_jto the design runsx(n, d)and responsesy, then solves the stationarity equationB x* = -b/2for the stationary point and classifies it from the eigenvalues of the quadratic matrixB. WhenBis singular a solution only exists if-b/2lies in its range, which is checked explicitly via the residual of the stationarity equation – a least-squares “solution” that does not actually zero the gradient is reported askind="no_stationary_point"rather than a fake stationary point (seeResponseSurface). 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 is1.0):d_efficiency–det(M)**(1/p) / n: overall coefficient-estimation precision;a_efficiency–p / (n * trace(M^-1)): average coefficient variance;g_efficiency–p / (n * max prediction variance)overref(or the design itself);condition_numberofM(large => near-collinear / fragile to fit;Nonewhen the requested model is rank-deficient), plus a finiteeffective_condition_numberwithin the estimable subspace and explicitrank/full_rankfields;max_correlation– the largest absolute pairwise correlation among the non-intercept model columns (the aliasing check;0for an orthogonal design).
modelis a model-matrix function such asmixle.doe.optimal.polynomial_features(). Use it on the coded design for meaningful efficiencies.ref– when given – is a reference design: raw candidate points in the same(m, d)raw-factor-column form asdesign(e.g. a finer grid over the same region, or a wider region to probe extrapolation risk), not a pre-built model matrix. It is passed through the samemodelused to build the design’s own model matrix before its prediction variance is computed, sog_efficiencycompares like with like; arefwhose raw column count does not matchdesign’s raises.g_efficiencyis guaranteed to fall on the documented(0, 1]scale only for the self-referential case (ref=None, orrefequal todesignitself) – a reference set concentrated in a lower-variance region than the design’s own points (e.g. just its centre) can legitimately score above1.0.The raw design and every transformed model matrix must be nonempty, two-dimensional, finite, and preserve the run axis. A rank-zero model is rejected. A partially estimable model reports zero full-model efficiencies,
condition_number=None, and its finite effective condition number rather than publishing NaN/Inf quality evidence.- Return type: