Calculates a balance score that measures how evenly treatments are distributed across spatial factors in an experimental design. Lower scores indicate better balance.
Value
Numeric value representing the total balance score. Lower values indicate better balance of treatments across spatial factors.
Examples
layout_df <- data.frame(
row = rep(1:3, each = 3),
col = rep(1:3, times = 3),
treatment = rep(letters[1:3], 3)
)
calculate_balance_score(layout_df, "treatment", c("row", "col"))
#> [1] 9