{ "cells": [ { "cell_type": "markdown", "id": "cc02f682", "metadata": {}, "source": [ "# Multi-Factor / DOE Plots\n", "\n", "Multi-factor EDA analyses designed experiments (DOE) where multiple\n", "factors are varied simultaneously. Pass named factor arrays via the\n", "`factors` dict to `EDAData`.\n", "\n", "The plots answer: *which factors drive location or spread,\n", "and what does the response surface look like?*\n", "\n", "Reference: [NIST Handbook Chapter 5](https://www.itl.nist.gov/div898/handbook/pri/pri.htm)" ] }, { "cell_type": "code", "execution_count": null, "id": "e4a73452", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from drippy import EDAData\n", "from drippy import (\n", " doe_scatter_plot,\n", " doe_mean_plot,\n", " doe_sd_plot,\n", " contour_plot,\n", ")\n", "\n", "rng = np.random.default_rng(42)\n", "\n", "# 2-factor full-factorial DOE — 16 runs\n", "# Factor A: temperature (+1 = high, −1 = low)\n", "# Factor B: pressure (+1 = high, −1 = low)\n", "# Response: process yield\n", "A = np.tile([-1, 1], 8)\n", "B = np.repeat([-1, 1], 8)\n", "y = 2.0 * A + 1.5 * B + 0.5 * A * B + rng.normal(scale=0.3, size=16)\n", "data = EDAData(y=y, factors={\"Temperature\": A, \"Pressure\": B})" ] }, { "cell_type": "markdown", "id": "50699343", "metadata": {}, "source": [ "## DOE Scatter Plot\n", "\n", "One subplot per factor. Scatters `y` against each factor's coded\n", "level to reveal the raw relationship before any modelling." ] }, { "cell_type": "code", "execution_count": null, "id": "8b426789", "metadata": {}, "outputs": [], "source": [ "fig, axes = doe_scatter_plot(data)\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "f9dfe065", "metadata": {}, "source": [ "## DOE Mean Plot\n", "\n", "For each factor, plots the mean response at each level and draws\n", "the grand mean as a reference. Steep slopes signal large main effects." ] }, { "cell_type": "code", "execution_count": null, "id": "b8ac321f", "metadata": {}, "outputs": [], "source": [ "fig, axes = doe_mean_plot(data)\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "f6c3ec2e", "metadata": {}, "source": [ "Temperature has a larger slope than Pressure, indicating a stronger\n", "effect on yield.\n", "\n", "## DOE SD Plot\n", "\n", "Like the mean plot but for within-level standard deviations.\n", "Detects factors that affect process *variability*, not just location." ] }, { "cell_type": "code", "execution_count": null, "id": "4ae339a6", "metadata": {}, "outputs": [], "source": [ "fig, axes = doe_sd_plot(data)\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "3f054e93", "metadata": {}, "source": [ "## Contour Plot (NIST 1.3.3.10)\n", "\n", "Interpolates a contour surface over the 2-factor design space.\n", "Requires exactly two factors. Optimal conditions appear as\n", "peaks or ridges in the surface." ] }, { "cell_type": "code", "execution_count": null, "id": "91c3831a", "metadata": {}, "outputs": [], "source": [ "fig, ax = contour_plot(data)\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "9dd9996f", "metadata": {}, "source": [ "Overlay the actual design points:" ] }, { "cell_type": "code", "execution_count": null, "id": "cdaa0434", "metadata": {}, "outputs": [], "source": [ "fig, ax = contour_plot(data, doe=True)\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.12.0" } }, "nbformat": 4, "nbformat_minor": 5 }