How to create a central composite design (CCD) with python
The basics about Central Composite Design (CCD)
If you’re diving into Design of Experiments (DOE), the Central Composite Design (CCD) is a powerful tool to have in your toolbox. What makes CCD so effective is its ability to estimate curvature in your response surface. This means you can identify maxima, minima, or saddle points—essentially, the sweet spots in your process. It builds upon a factorial design by adding center points and star points (or axial points).
In this blog post, I’ll guide you through how to create a Central Composite Design using Python. Don’t worry; it’s simpler than it sounds.
The pyDOE package
As previously, we are going to use the pyDOE package. But this time we use pyDOE3, which is just the newer version of pyDOE2 that we used in earlier blog posts. The functionality hasn’t changed. Just the name. Plus, it works with newer Python versions (≥ 3.12). So let’s start by installing the package. You can do this using pip:
pip install pyDOE3
Creating a Central Composite Design
Let’s create a CCD for an experiment with three factors: Temperature (T), Pressure (P), and Concentration (C).
Step 1: Import the necessary libraries
Start by importing the libraries we’ll need:
import pyDOE3
import pandas as pd
We’re using pandas to organize the design matrix into a readable format later.
Step 2: Generate the Design Matrix
Define the number of factors in your experiment and use the ccdesign function to create the CCD:
# Number of factors
num_factors = 3
# Generate the design matrix
design_matrix = pyDOE3.ccdesign(num_factors, center=(4, 4))
Here’s what’s happening:
- num_factors: The number of factors (independent variables) in your experiment. In this case, T, P, and C.
- center: A tuple that specifies the number of center points for the factorial and axial portions of the design. More center points can improve the robustness of your design but also increase the number of experiments you need to run.
Experiment with these parameters to see how they affect your design. For example, increasing the center points can be useful when you need more replicates to assess variability.
Step 3: Organize the Design for Better Readability
To make the design matrix more interpretable, we’ll convert it into a DataFrame and add column names for our factors:
# Define factor names
factor_names = ['T', 'P', 'C']
df = pd.DataFrame(design_matrix, columns=factor_names)
# Display the design matrix
print("Central Composite Design Matrix:")
print(df)
Saving the Design Matrix
You can save the design matrix to an Excel file if you want:
# Save the design matrix to an Excel file
df.to_excel('central_composite_design.xlsx', index=False)
Your turn
Creating a central composite design with Python and the pyDOE3
package is a straightforward and efficient process. It allows you to explore quadratic relationships and optimize processes with fewer experiments than traditional three-level factorial designs.
Number of Factors | 3-Level Full Factorial Runs | Central Composite Design (CCD) Runs |
---|---|---|
2 | 9 | 16 |
3 | 27 | 22 |
4 | 81 | 32 |
5 | 243 | 50 |
Why not give it a try yourself? Or read my next blog post to learn about the next generation of DOE that will take all our jobs in the future.