D-Optimal Design (Constrained Process Domain)¶
This tutorial investigates the applicability of D-optimal design in scenarios where the experimental region cannot be described by a regular rectangular domain and where both continuous and categorical factors are present. Such situations arise frequently in practice, as process constraints and heterogeneous variable types may prevent the use of classical factorial or response surface designs.
The factors under investigation are:
Temperature, :math:`T`: continuous factor, ranging from \(15\) to \(40^\circ\mathrm{C}\);
Relative humidity, :math:`H`: continuous factor, ranging from \(15\%\) to \(75\%\);
Batch type, :math:`B`: categorical factor with two levels, A and B.
In addition to the factor bounds, two process constraints are imposed:
at a relative humidity of \(15\%\), the minimum feasible temperature is \(30^\circ\mathrm{C}\);
at a temperature of \(15^\circ\mathrm{C}\), the minimum feasible relative humidity is \(45\%\).
These conditions define the following linear feasibility constraint:
As a result, the experimental space is no longer rectangular but corresponds to an irregular constrained domain. In particular, combinations involving low values of both temperature and relative humidity are excluded from the set of feasible candidate experiments.
Model specification¶
Let:
\(X_1\) represent temperature;
\(X_2\) represent relative humidity;
\(X_3\) represent batch type.
The two continuous factors are described using a second-order polynomial model, while the categorical factor is represented only through its linear contribution. Interactions between all pairs of factors are also included.
The resulting model is:
where:
\(\beta_0\) is the intercept;
\(\beta_1\) and \(\beta_2\) describe the linear effects of temperature and relative humidity;
\(\beta_3\) describes the effect of batch type;
\(\beta_{12}\) describes the interaction between temperature and relative humidity;
\(\beta_{13}\) and \(\beta_{23}\) describe how the effects of temperature and relative humidity vary between the two batch types;
\(\beta_{11}\) and \(\beta_{22}\) describe the quadratic effects of the continuous factors;
\(\varepsilon\) represents the experimental error.
The model therefore contains nine coefficients:
one intercept;
three main effects;
three two-factor interactions;
two quadratic terms.
No quadratic term is included for batch type because it is a two-level categorical factor. The coexistence of continuous and categorical factors, together with the irregular experimental domain, makes a standard response surface design unsuitable. A D-optimal approach is therefore used to select the subset of feasible candidate points that provides the most informative estimation of the specified model for a given experimental effort.
This example is adapted from Leardi (2018), D-Optimal Designs, in the Encyclopedia of Analytical Chemistry, DOI: 10.1002/9780470027318.a964
[1]:
# This is needed to display plotly figures in the Jupyter notebook, not for the library itself
import plotly.io as pio
pio.renderers.default = "notebook"
# Fundamental imports
from doetools import CategoricalFactor, ContinuousFactor, DOptDesign, ModelTerms
Define Factors, Filters and Instantiate the Design¶
[2]:
# Define factors, filter function, and instantiate design object
factors = {
"T" : ContinuousFactor(n_levels=6, lower_bound=15, upper_bound=40),
"H" : ContinuousFactor(n_levels=13, lower_bound=15, upper_bound=75),
"Type" : CategoricalFactor(levels=["A", "B"], reference_level="A")
}
def filter(df):
return df["H"] >= -2*df["T"] + 75
# Instantiate design object, use a grid for process factors, and apply the filter function to the candidate set
design = DOptDesign(factors=factors, process_strategy="grid", filters=[filter])
[3]:
# Inspect candidate points
fig_0 = design.plot_candidate_set(ax1="T", ax2="H", ax3="Type")
fig_0.show()
Set model terms and Compute D-Optimal Solutions¶
[4]:
# Define model terms
model_terms = ModelTerms(intercept=True,
pro_main="all",
pro_int2="all",
pro_quadratic=["T", "H"])
design.set_model_terms(model_terms)
[5]:
# D-optimal design computation between 9 and 20 runs, and visualize the results
fig1 = design.compute_d_optimal(n_min=9, n_max=20)
fig1.show()
[6]:
# Select the design with the desired number of runs
design.select_design(n=13)
# Display the selected design
fig2 = design.plot_design(ax1="T", ax2="H", ax3="Type")
fig2.show()
Show leverage on a constrained design¶
[7]:
# Plot leverage values for the selected design
fig3, fig4 = design.plot_leverage(ax1="T", ax2="H", domain="allowed")
fig3.show()