Factor¶
The Factor class represents a single factor (variable) in a design of experiments, with support for both numerical and categorical levels.
Overview¶
A Factor defines one dimension of your experimental space. It can represent:
- Numerical factors: Temperature, pressure, concentration, etc.
- Categorical factors: Machine type, operator, material grade, etc.
The Factor class automatically handles:
- Level ordering (numerical factors are sorted)
- Central point calculation (for numerical factors)
- Categorical detection (when string levels are present)
- Code generation for experimental designs
Basic Usage¶
Numerical Factors¶
import daspi as dsp
# Temperature factor with two levels
temperature = dsp.Factor('Temperature', (150, 200))
# Pressure factor with three levels
pressure = dsp.Factor('Pressure', (10, 12, 15))
print(f"Temperature levels: {temperature.levels}")
print(f"Temperature central point: {temperature.central_point}")
print(f"Is categorical: {temperature.is_categorical}")
Categorical Factors¶
# Catalyst type (categorical)
catalyst = dsp.Factor('Catalyst', ('A', 'B', 'C'), is_categorical=True)
# Machine operator (automatically detected as categorical)
operator = dsp.Factor('Operator', ('John', 'Jane', 'Bob'))
print(f"Catalyst levels: {catalyst.levels}")
print(f"Has central point: {catalyst.central_point is not None}")
Key Properties¶
- name: The factor name (used in design matrices)
- levels: Tuple of factor levels (sorted for numerical factors)
- n_levels: Number of levels in the factor
- is_categorical: Whether the factor is categorical
- central_point: Central value for numerical factors (None for categorical)
- corrected_levels: Encoded levels used internally in designs
Advanced Features¶
Automatic Categorical Detection¶
When string levels are detected, the factor is automatically treated as categorical:
# This triggers a warning and sets is_categorical=True
material = dsp.Factor('Material', ('Steel', 'Aluminum'))
# To avoid the warning, explicitly set is_categorical
material = dsp.Factor('Material', ('Steel', 'Aluminum'), is_categorical=True)
Coded Levels¶
For design generation, factors use coded levels internally:
factor = dsp.Factor('pH', (6.5, 7.0, 7.5))
print(f"Original levels: {factor.levels}")
print(f"Coded levels: {factor.corrected_levels}")
print(f"Level mapping: {factor.corrected_level_map}")
This produces coded levels like (-1, 0, 1) for internal calculations while maintaining the mapping to original values.
API Reference¶
daspi.doe.Factor(name, levels, is_categorical=False)
¶
Represents a factor in a design of experiments.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the factor.
TYPE:
|
levels
|
Levels of the factor (numeric or categorical).
TYPE:
|
is_categorical
|
Whether the factor is categorical. This is automatically inferred from the levels if not specified. Categorical factors are assumed to be unordered and have no central point.
TYPE:
|
n_levels
property
¶
Return number of levels (read-only).
name
property
¶
Name of the factor (read-only).
is_categorical
property
¶
Return whether the factor is categorical (read-only).
levels
property
¶
Levels of the factor (read-only).
central_point
property
¶
Central point of the factor (read-only).
is_centralized
property
¶
Check if the corrected levels are centered around 0 (read-only).
corrected_central_points
property
¶
Corrected central points as tuple, used for float-coded designs (read-only).
If the factor has a central point, it returns a tuple with the central coded value, otherwise it returns the corrected levels.
Notes
If this property is accessed, it will also update the
corrected_level_map.
corrected_levels
property
¶
Corrected levels for float-coded designs (read-only).
corrected_level_map
property
¶
Mapping from float or int codes to their corresponding factor levels (read-only).