Leverage Analysis

Leverage describes how strongly a factor setting can influence the estimated model coefficients. It is determined by the experimental design and the terms in the configured model matrix; it does not depend on measured responses. You can therefore examine leverage before importing results or fitting a response model.

For the model-matrix row \(x_i\) corresponding to run \(i\) and the full model matrix \(X\), doetools computes

\[h_i = x_i^{\mathsf{T}} (X^{\mathsf{T}}X)^{+} x_i,\]

where \(+\) denotes the Moore–Penrose pseudoinverse. The leverage values sum to the rank of \(X\), and their average is \(\operatorname{rank}(X)/n\) for \(n\) runs.

Interpretation

Higher leverage means that a setting has greater influence on coefficient estimation. Interpret values relative to the other points in the same design and for the same model terms: changing the model changes the leverages. A high-leverage point is not necessarily erroneous or an outlier.

Leverage values are directly related to model uncertainty. The variance of the predicted response at setting \(x_0\) is proportional to the square root of the leverage \(\sqrt{h_0}\) of that setting.

Obtain and plot leverage

Design.get_leverages()

Return leverage values for the configured model matrix.

Return type:

DataFrame

GraphsMixin.plot_leverage(ax1, ax2, ax3=None, constant_levels=None, resolution=100, x_min=-1.0, x_max=1.0, y_min=-1.0, y_max=1.0, coded=False, show_title=True, show_legend=True, show_summary=True, colorscale=None, domain='full')[source]

Visualize leverage values across the design space.

Leverage measures the influence of design points on model predictions. High leverage points are candidates for replication to improve precision.

Parameters:
  • ax1 (str) – First free factor.

  • ax2 (str) – Second free factor.

  • ax3 (str) – Third free mixture component for a ternary plot.

  • constant_levels (dict[str, float]) – Actual-unit levels at which to hold all remaining factors.

  • resolution (int) – Number of grid points per process axis, or the mixture-grid resolution.

  • x_min (float) – Lower bound for ax1 in coded units.

  • x_max (float) – Upper bound for ax1 in coded units.

  • y_min (float) – Lower bound for ax2 in coded units.

  • y_max (float) – Upper bound for ax2 in coded units.

  • coded (bool) – Whether to display coded rather than actual units.

  • show_title (bool) – Whether to display the generated title.

  • show_legend (bool) – Whether to display the legend.

  • show_summary (bool) – Whether to display the fixed-level and leverage-range annotation.

  • colorscale (str | list | None) – Plotly colorscale applied to the contour and surface traces.

  • domain (Literal['full', 'allowed']) – Plotting domain. "allowed" applies saved process domain filters or restricts a mixture plot to its allowed hull.

Returns:

Contour and three-dimensional surface figures.

Return type:

tuple[Figure, Figure]

Notes

Leverage is computed as x.T @ (X.T @ X)^+ @ x, where + denotes the Moore-Penrose pseudoinverse. A model matrix must have been defined, but response results and a fitted model are not required.

Example

Define the model terms first. Imported responses and a fitted model are not required.

from doetools import ModelTerms

design.set_model_terms(
    ModelTerms(
        intercept=True,
        pro_main="all",
        pro_int2=None,
        pro_quadratic=None,
    )
)

# One leverage value for each experimental run
leverages = design.get_leverages()

# Leverage across a two-factor slice of the design space
contour, surface = design.plot_leverage(
    ax1="Temperature",
    ax2="Pressure",
    constant_levels={"Time": 30.0},
    coded=False,
    domain="allowed",
)

ax1 and ax2 are the free factors. For mixture surfaces, pass the third free component as ax3. Use constant_levels to fix factors that are not shown; its values are expressed in actual units. The grid bounds remain coded, while coded controls whether plot labels use coded or actual units. domain="allowed" applies saved process-domain filters or restricts a mixture plot to its allowed hull.