This vignette covers advanced and complex experimental designs that are used in specialised agricultural research contexts. These designs are particularly useful for plant breeding programs, large-scale variety trials, and situations where standard complete block designs are impractical due to resource constraints or the nature of the treatments.
Building on the foundational designs covered in the Common Agricultural Experimental Designs vignette, these complex designs offer solutions for challenging experimental scenarios while maintaining statistical rigour through spatial optimisation with the speed package.
library(speed)
library(patchwork) # For combining plotsSplit-split plot designs extend the hierarchical structure of split-plot designs to accommodate three factors with different levels of experimental difficulty or practical constraints. This creates a three-level hierarchy of experimental units.
Complex error structure with multiple error terms:
Consider a complex agricultural trial examining Tillage System × Nitrogen Rate × Variety interactions with three hierarchical levels.
splits <- list(
subsubplot = list(items = c("x", "y", "z"), nrows = 1, ncols = 1),
subplot = list(items = c("a", "b", "c", "d"), nrows = 1, ncols = 3),
wholeplot = list(items = c("A", "B", "C"), nrows = 4, ncols = 3),
block = list(nrows = 4, ncols = 9)
)
split_split_df <- initialise_split_design_df(splits = splits, rep_dim = c(4, 1))This shows the initial split-split plot design with three-level hierarchical structure.
optimise <- list(
wp = list(
swap = "wholeplot_treatment",
swap_within = "block",
iterations = 2000,
early_stop_iterations = 1000,
swap_all = TRUE
),
sp = list(
swap = "subplot_treatment",
swap_within = "wholeplot",
iterations = 5000,
early_stop_iterations = 3000,
swap_all = TRUE
),
ssp = list(
swap = "subsubplot_treatment",
swap_within = "subplot",
iterations = 20000,
early_stop_iterations = 5000
)
)
result_ss <- speed(split_split_df, optimise = optimise, seed = 42)## row and col are used as row and column, respectively.
## Optimising level: wp
## Level: wp Iteration: 1000 Score: 252 Best: 252 Since Improvement: 972
## Early stopping at iteration 1028 for level wp
## Optimising level: sp
## Level: sp Iteration: 1000 Score: 132 Best: 132 Since Improvement: 594
## Level: sp Iteration: 2000 Score: 132 Best: 132 Since Improvement: 1594
## Level: sp Iteration: 3000 Score: 132 Best: 132 Since Improvement: 2594
## Early stopping at iteration 3406 for level sp
## Optimising level: ssp
## Level: ssp Iteration: 1000 Score: 16 Best: 16 Since Improvement: 120
## Level: ssp Iteration: 2000 Score: 12 Best: 12 Since Improvement: 349
## Level: ssp Iteration: 3000 Score: 11 Best: 11 Since Improvement: 553
## Level: ssp Iteration: 4000 Score: 11 Best: 11 Since Improvement: 1553
## Level: ssp Iteration: 5000 Score: 10 Best: 10 Since Improvement: 925
## Level: ssp Iteration: 6000 Score: 10 Best: 10 Since Improvement: 1925
## Level: ssp Iteration: 7000 Score: 9 Best: 9 Since Improvement: 19
## Level: ssp Iteration: 8000 Score: 9 Best: 9 Since Improvement: 1019
## Level: ssp Iteration: 9000 Score: 9 Best: 9 Since Improvement: 2019
## Level: ssp Iteration: 10000 Score: 7 Best: 7 Since Improvement: 985
## Level: ssp Iteration: 11000 Score: 7 Best: 7 Since Improvement: 1985
## Level: ssp Iteration: 12000 Score: 7 Best: 7 Since Improvement: 2985
## Level: ssp Iteration: 13000 Score: 7 Best: 7 Since Improvement: 3985
## Level: ssp Iteration: 14000 Score: 7 Best: 7 Since Improvement: 4985
## Early stopping at iteration 14015 for level ssp
result_ss## Optimised Experimental Design
## ----------------------------
## Score: 391
## Iterations Run: 18452
## Stopped Early: TRUE TRUE TRUE
## Treatments:
## wp: A, B, C
## sp: a, b, c, d
## ssp: x, y, z
## Seed: 42
res1 <- autoplot(result_ss, treatments = "wholeplot_treatment") + ggplot2::labs(title = "Whole plot Treatments")
res2 <- autoplot(result_ss, treatments = "subplot_treatment") + ggplot2::labs(title = "Sub-plot Treatments")
res3 <- autoplot(result_ss, treatments = "subsubplot_treatment") + ggplot2::labs(title = "Sub-sub-plot Treatments")
res1 + res2 + res3 +
plot_layout(ncol = 2) +
plot_annotation(title = "Optimised Split-Split Plot Design")Above is the final output of this design. Note that there are some adjacent pairs of treatments in the sub-sub-plots. This is quite difficult to avoid in these situations, however adjusting some of the optimisation parameters may help with this. For further information, see the vignette about changing optimisation parameters for speed.
Strip-plot designs are extensions of split-plot designs used when both treatment factors are difficult to apply to small areas. Treatments are arranged in strips that cross each other, creating a grid pattern where intersections represent treatment combinations.
Consider an experiment testing 3 tillage methods and 4 planting dates where both factors require large application areas.
df_strip <- data.frame(
row = rep(1:12, each = 6), # 12 rows total (4 rows per block x 6 blocks)
col = rep(1:6, times = 12), # 6 columns
block = rep(rep(1:2, each = 3), times = 4) + rep(0:2*2, each = 24), # 6 blocks, 12 plots each
# Horizontal strips (3 levels, applied to rows within each block)
vertical_treatment = rep(rep(LETTERS[1:3], times = 2), times = 12), # A, B, C
# Vertical strips (4 levels, applied to columns within each block)
horizontal_treatment = rep(rep(letters[1:4], each = 6), times = 3), # a, b, c, d
# Plot identifier within each block
plot_in_block = rep(1:12, times = 6)
)This shows the initial strip-plot layout with horizontal and vertical strips before optimisation.
strip_result <- speed(df_strip,
swap = list(ht = "horizontal_treatment", vt = "vertical_treatment"),
swap_within = list(ht = "block", vt = "block"),
swap_all = TRUE)## row and col are used as row and column, respectively.
## Optimising level: ht
## Level: ht Iteration: 1000 Score: 84 Best: 84 Since Improvement: 961
## Level: ht Iteration: 2000 Score: 84 Best: 84 Since Improvement: 1961
## Early stopping at iteration 2039 for level ht
## Optimising level: vt
## Level: vt Iteration: 1000 Score: 54 Best: 54 Since Improvement: 878
## Level: vt Iteration: 2000 Score: 54 Best: 54 Since Improvement: 1878
## Early stopping at iteration 2122 for level vt
strip_result## Optimised Experimental Design
## ----------------------------
## Score: 138
## Iterations Run: 4163
## Stopped Early: TRUE TRUE
## Treatments:
## ht: a, b, c, d
## vt: A, B, C
## Seed: -2124829786
autoplot(strip_result, treatments = "horizontal_treatment") + ggplot2::labs(title = "Tillage Treatments")autoplot(strip_result, treatments = "vertical_treatment") + ggplot2::labs(title = "Planting Date Treatments")An optimised strip-plot design with well-arranged treatment combinations!
When the number of treatments is large, complete blocks may be impractical due to field size or resource constraints. Incomplete block designs use smaller blocks where not all treatments appear in each block, while still maintaining good statistical properties.
The most restrictive but statistically optimal incomplete block design.
What may become apparent from the characteristics and parameters listed above is that these designs are not trivial, and there are specific and limited combinations that will work. In the case of speed, a custom objective function is required to ensure that each pair of treatments appear the same number of times. For an example and further discussion, see the vignette on custom objective functions.
More flexible incomplete block designs where blocks can be grouped into complete replications.
Relaxes the balance requirements of BIBD while maintaining good statistical properties.
Consider a trial with 15 treatments where complete blocks would be too large for field homogeneity. We’ll use an incomplete block design with blocks of size 5.
Firstly we need to create a data frame representing the incomplete block design. Here we will use a systematic approach to generate the blocks and treatment combinations.
# Create the data frame
ribd_df <- data.frame(
row = rep(1:3, 6), # Row within each block
col = rep(1:6, each = 3), # Column corresponds to block
replicate = rep(1:3, each = 6), # 3 replicates, 6 observations each
block = rep(1:6, each = 3), # 6 blocks total, 3 treatments per block
treatment = paste0("V", rep(1:6, times = 3)) # Treatment assignments
)
# View the design
head(ribd_df)## row col replicate block treatment
## 1 1 1 1 1 V1
## 2 2 1 1 1 V2
## 3 3 1 1 1 V3
## 4 1 2 1 2 V4
## 5 2 2 1 2 V5
## 6 3 2 1 2 V6
Figure 4 shows the systematic resolvable incomplete block layout before optimisation. Note that replicates are made of two blocks, in each of which half the treatments will appear, and replicates are made up of pairs of blocks. The treatments can be swapped between blocks, but need to remain within their replicate.
ribd_result <- speed(ribd_df,
swap = "treatment",
swap_within = "replicate",
seed = 42) ## row and col are used as row and column, respectively.
## Optimising level: single treatment within replicate
## Optimal score reached at iteration 474 for level single treatment within replicate
ribd_result## Optimised Experimental Design
## ----------------------------
## Score: 1.8
## Iterations Run: 474
## Stopped Early: TRUE
## Treatments: V1, V2, V3, V4, V5, V6
## Seed: 42
str(ribd_result)## List of 9
## $ design_df :Classes 'design' and 'data.frame': 18 obs. of 5 variables:
## ..$ row : int [1:18] 1 1 1 1 1 1 2 2 2 2 ...
## ..$ col : int [1:18] 1 2 3 4 5 6 1 2 3 4 ...
## ..$ replicate: int [1:18] 1 1 2 2 3 3 1 1 2 2 ...
## ..$ block : int [1:18] 1 2 3 4 5 6 1 2 3 4 ...
## ..$ treatment: chr [1:18] "V3" "V2" "V1" "V4" ...
## $ score : num 1.8
## $ scores : num [1:474] 9 7.4 5.8 6.8 5.4 4.6 4.2 4.2 4.2 4.2 ...
## $ temperatures : num [1:474] 100 99 98 97 96.1 ...
## $ iterations_run: num 474
## $ stopped_early : logi TRUE
## $ treatments : chr [1:6] "V1" "V2" "V3" "V4" ...
## $ seed : num 42
## $ metadata :List of 6
## ..$ levels : chr "single treatment within replicate"
## ..$ row_column: chr "row"
## ..$ col_column: chr "col"
## ..$ grid_by : NULL
## ..$ per_level :List of 1
## .. ..$ single treatment within replicate:List of 13
## .. .. ..$ swap : chr "treatment"
## .. .. ..$ spatial_factors :Class 'formula' language ~row + col
## .. .. .. .. ..- attr(*, ".Environment")=<environment: 0x00000202dcfaf188>
## .. .. ..$ spatial_cols : chr [1:2] "row" "col"
## .. .. ..$ adj_weight : num 1
## .. .. ..$ bal_weight : num 1
## .. .. ..$ iterations : num 10000
## .. .. ..$ start_temp : num 100
## .. .. ..$ cooling_rate : num 0.99
## .. .. ..$ obj_function :function (layout_df, swap, spatial_cols, adj_weight = 1, bal_weight = 1,
## row_column = "row", col_column = "col", current_score_obj = NULL, swapped_items = NULL,
## ...)
## .. .. .. ..- attr(*, "srcref")= 'srcref' int [1:8] 43 23 107 1 23 1 43 107
## .. .. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x00000202d6f188c8>
## .. .. ..$ final_score : num 1.8
## .. .. ..$ final_components: Named num [1:2] 0 1.8
## .. .. .. ..- attr(*, "names")= chr [1:2] "adjacency" "balance"
## .. .. ..$ optimal_score : num 1.8
## .. .. ..$ stop_reason : chr "optimal"
## ..$ call : language speed(data = ribd_df, swap = "treatment", swap_within = "replicate", seed = 42)
## - attr(*, "class")= chr [1:2] "design" "list"
autoplot(ribd_result)We see that each block by itself only contains half the treatments, but when combined, the pairs have a full replicate. The algorithm has also spatially optimised the treatments across rows and columns, giving a nicely optimised resolvable incomplete block design.
P-rep designs are a modern approach to plant breeding trials where a subset of entries (typically checks and selected test lines) are replicated while the majority of test entries appear only once. This provides a balance between statistical power and resource efficiency.
Consider a breeding trial with 140 entries where 40 key entries (checks and promising lines) are replicated twice while others appear once. This is a single site design with two blocks.
prep_design <- data.frame(
row = rep(1:14, each = 10),
col = rep(1:10, times = 14),
block = rep(rep(1:2, each = 5), 14),
entry = c(paste0("V", rep(1:40, 2)), paste0("V", 41:100)) # 100 varieties, 40 duplicated
)
# Create an indicator for the duplicated entries
prep_design$duplicated <- duplicated(prep_design$entry) | duplicated(prep_design$entry, fromLast = TRUE)
head(prep_design)## row col block entry duplicated
## 1 1 1 1 V1 TRUE
## 2 1 2 1 V2 TRUE
## 3 1 3 1 V3 TRUE
## 4 1 4 1 V4 TRUE
## 5 1 5 1 V5 TRUE
## 6 1 6 2 V6 TRUE
This shows the initial p-rep design with duplicated entries distributed systematically. Once we have set up the data frame, the speed() optimisation call is quite straight-forward. Note that we have added block into the spatial_factors argument, to attempt to balance the replicated treatments between blocks as well. Typically with larger designs, we may also want to increase the number of iterations and early_stop_iterations to allow more swapping to take place, however in this case it is not necessary due to the low replication.
prep_result <- speed(prep_design,
swap = "entry",
spatial_factors = ~ block + row + col,
seed = 42)## row and col are used as row and column, respectively.
## Optimising level: single entry within whole design
## Level: single entry within whole design Iteration: 1000 Score: 2.993939 Best: 2.993939 Since Improvement: 5
## Optimal score reached at iteration 1183 for level single entry within whole design
prep_result## Optimised Experimental Design
## ----------------------------
## Score: 2.913131
## Iterations Run: 1183
## Stopped Early: TRUE
## Treatments: V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, V41, V42, V43, V44, V45, V46, V47, V48, V49, V50, V51, V52, V53, V54, V55, V56, V57, V58, V59, V60, V61, V62, V63, V64, V65, V66, V67, V68, V69, V70, V71, V72, V73, V74, V75, V76, V77, V78, V79, V80, V81, V82, V83, V84, V85, V86, V87, V88, V89, V90, V91, V92, V93, V94, V95, V96, V97, V98, V99, V100
## Seed: 42
str(prep_result)## List of 9
## $ design_df :Classes 'design' and 'data.frame': 140 obs. of 5 variables:
## ..$ row : int [1:140] 1 1 1 1 1 1 1 1 1 1 ...
## ..$ col : int [1:140] 1 2 3 4 5 6 7 8 9 10 ...
## ..$ block : int [1:140] 1 1 1 1 1 2 2 2 2 2 ...
## ..$ entry : chr [1:140] "V100" "V16" "V38" "V37" ...
## ..$ duplicated: logi [1:140] TRUE TRUE TRUE TRUE TRUE TRUE ...
## $ score : num 2.91
## $ scores : num [1:1183] 4.53 4.49 4.45 4.37 4.37 ...
## $ temperatures : num [1:1183] 100 99 98 97 96.1 ...
## $ iterations_run: num 1183
## $ stopped_early : logi TRUE
## $ treatments : chr [1:100] "V1" "V2" "V3" "V4" ...
## $ seed : num 42
## $ metadata :List of 6
## ..$ levels : chr "single entry within whole design"
## ..$ row_column: chr "row"
## ..$ col_column: chr "col"
## ..$ grid_by : NULL
## ..$ per_level :List of 1
## .. ..$ single entry within whole design:List of 13
## .. .. ..$ swap : chr "entry"
## .. .. ..$ spatial_factors :Class 'formula' language ~block + row + col
## .. .. .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
## .. .. ..$ spatial_cols : chr [1:3] "block" "row" "col"
## .. .. ..$ adj_weight : num 1
## .. .. ..$ bal_weight : num 1
## .. .. ..$ iterations : num 10000
## .. .. ..$ start_temp : num 100
## .. .. ..$ cooling_rate : num 0.99
## .. .. ..$ obj_function :function (layout_df, swap, spatial_cols, adj_weight = 1, bal_weight = 1,
## row_column = "row", col_column = "col", current_score_obj = NULL, swapped_items = NULL,
## ...)
## .. .. .. ..- attr(*, "srcref")= 'srcref' int [1:8] 43 23 107 1 23 1 43 107
## .. .. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x00000202d6f188c8>
## .. .. ..$ final_score : num 2.91
## .. .. ..$ final_components: Named num [1:2] 0 2.91
## .. .. .. ..- attr(*, "names")= chr [1:2] "adjacency" "balance"
## .. .. ..$ optimal_score : num 2.91
## .. .. ..$ stop_reason : chr "optimal"
## ..$ call : language speed(data = prep_design, swap = "entry", spatial_factors = ~block + row + col, seed = 42)
## - attr(*, "class")= chr [1:2] "design" "list"
Ideally here we would also like to see an even distribution of the duplicated entries between each block.
prep_result$design_df$duplicated <- duplicated(prep_result$design_df$entry) | duplicated(prep_result$design_df$entry, fromLast = TRUE)
sum(prep_result$design_df$duplicated[prep_result$design_df$block==1])## [1] 40
any(duplicated(prep_result$design_df$entry[prep_result$design_df$block==1]))## [1] FALSE
With 40 duplicated varieties in this block, we know we also have 40 in the other block.
autoplot(prep_result, treatments = "entry")An optimised p-rep design with strategic replication and spatial distribution. Note that because the treatments column is not called “treatment”, we need to specify the treatments argument in the autoplot() function.
Advanced row-column designs incorporate additional blocking structures to control for multiple sources of variation simultaneously. These designs are particularly useful for large, complex experiments where variation occurs in multiple dimensions.
Consider a large field trial with 40 varieties each replicated 10 times, requiring both row blocks and column blocks.
blocking_2d_design <- data.frame(row = rep(1:20, each = 20),
col = rep(1:20, 20),
treatment = rep(paste("V", 1:40, sep = ""), 10),
rowBlock = rep(1:10, each = 40),
colBlock = rep(rep(1:10, each = 2), 20))
head(blocking_2d_design)## row col treatment rowBlock colBlock
## 1 1 1 V1 1 1
## 2 1 2 V2 1 1
## 3 1 3 V3 1 2
## 4 1 4 V4 1 2
## 5 1 5 V5 1 3
## 6 1 6 V6 1 3
This shows the initial row-column design with hierarchical blocking structure.
Now we will use the speed() function to optimise this design. We will swap treatments within row blocks, while also considering column blocks as a spatial factor. Note that we also set some optimisation parameters to allow for more swaps, as this is a larger design with more treatments.
optimise_params <- optim_params(swap_count = 5, swap_all_blocks = TRUE, adaptive_swaps = TRUE)
blocking_2d_result <- speed(blocking_2d_design,
swap = "treatment",
swap_within = "rowBlock",
spatial_factors = ~ colBlock,
iterations = 150000,
early_stop_iterations = 50000,
optimise_params = optimise_params,
seed = 42, quiet = TRUE)blocking_2d_result## Optimised Experimental Design
## ----------------------------
## Score: 0
## Iterations Run: 39972
## Stopped Early: TRUE
## Treatments: V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40
## Seed: 42
An optimised row-column design with blocking in two directions.
Complex experimental designs offer powerful solutions for challenging agricultural research scenarios. The speed package provides essential tools for optimising these designs spatially, ensuring that the statistical advantages of sophisticated designs are fully realised in practice.
Key benefits of using complex designs with spatial optimisation include:
When selecting and implementing complex designs, researchers should carefully balance statistical efficiency, practical constraints, and research objectives. The spatial optimisation capabilities of speed ensure that these sophisticated designs achieve their full potential in real-world applications.
This vignette demonstrates advanced applications of the speed package for complex experimental designs. For foundational designs, see the “Common Agricultural Experimental Designs” vignette. For specific implementation details, consult the package documentation and function help files.