Factorial designs: principles and applications

Experimental Design in Python

James Chapman

Curriculum Manager, DataCamp

Understanding factorial design

 

  • Study multiple independent variables/factors in one experiment
  • Test every combination of factor levels
  • Discover direct effects and interactions between factors

An experiment showing how light conditions and fertilizer type affects plant growth.

1 Image Generated with DALL·E 3
Experimental Design in Python

Factorial design data example

  • Factor 1 (Light_Condition) - two levels: Full Sunlight and Partial Shade
  • Factor 2 (Fertilizer_Type) - two levels: Synthetic and Organic
  • Numeric response/dependent/outcome variable: Growth_cm
plant_growth_data.head()
   Plant_ID  Light_Condition  Fertilizer_Type  Growth_cm
0         1    Full Sunlight        Synthetic  16.489735
1         2    Partial Shade          Organic  18.361689
2         3    Full Sunlight        Synthetic  18.039459
3         4    Full Sunlight          Organic  12.682425
4         5    Full Sunlight          Organic  21.480601
Experimental Design in Python

Organizing data to visualize interactions

plant_growth = pd.pivot_table(plant_growth_data, 
                              values='Growth_cm',
                              index='Light_Condition',
                              columns='Fertilizer_Type', 
                              aggfunc='mean')

plant_growth
Light_Condition     Organic   Synthetic
Full Sunlight       20.602       19.869
Partial Shade       20.246       20.326
Experimental Design in Python

Visualize interactions with heatmap

import seaborn as sns
import matplotlib.pyplot as plt
sns.heatmap(plant_growth, 
            annot=True, 
            cmap='coolwarm',
            fmt='g')
plt.show()

Plant Growth Heatmap

Experimental Design in Python

Interpreting interactions

Light_Condition     Organic   Synthetic
Full Sunlight       20.602       19.869
Partial Shade       20.246       20.326
  • Interactions: how the effect of one factor varies with the level of another factor
  • Significant interaction → factors do not work independently
Experimental Design in Python

Factorial designs vs. randomized block designs

  • Multiple treatments and interactions
  • Dissect complex multi-variable effects and interactions
  • Can require more subjects

An experiment showing how light conditions and fertilizer type affects plant growth.

  • Group similar subjects in randomized designs
  • Control within-block variance
  • Each treatment is tested within every block

Two blocks containing cube with randomly assigned colors.

1 Images Generated with DALL·E 3
Experimental Design in Python

Let's practice!

Experimental Design in Python

Preparing Video For Download...