Calculates the adjacency score for a given experimental design. The adjacency score represents the number of adjacent plots with the same treatment. Lower scores indicate better separation of treatments.
Examples
# Example 1: Design with no adjacencies
design_no_adj <- data.frame(
row = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
col = c(1, 2, 3, 1, 2, 3, 1, 2, 3),
treatment = c("A", "B", "A", "B", "A", "B", "A", "B", "A")
)
# Gives 0
calculate_adjacency_score(design_no_adj, "treatment")
#> [1] 0
# Example 2: Design with adjacencies
design_with_adj <- data.frame(
row = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
col = c(1, 2, 3, 1, 2, 3, 1, 2, 3),
treatment = c("A", "A", "A", "B", "B", "B", "A", "A", "A")
)
# Gives value 6
calculate_adjacency_score(design_with_adj, "treatment")
#> [1] 6