Skip to content

Simulate a continuous trait on a FielDHub design

Source: R/sim_design.R

Generate Gaussian plot responses using the treatment and experimental units of the realized randomization. Repeated entries, including checks, share a treatment effect across plots and locations. Each draw generates new random effects. Filler plots remain in the field book with missing responses.

Usage

# S3 method for class 'FielDHub'
simulate(
  object,
  nsim = 1,
  seed = NULL,
  ...,
  trait = "YIELD",
  mean = 100,
  residual_sd = 8,
  treatment_sd = NULL,
  design_sd = NULL,
  location_sd = NULL,
  spatial = FALSE
)

Arguments

object
A FielDHub field design.
nsim
Positive number of independent trials to draw.
seed
Simulation seed. With NULL, one seed is drawn and recorded. If R is using Box-Muller normals, simulation draws from a private stream to preserve the caller's cached normal.
...
Reserved for future extensions.
trait
Name of the response column for one draw. Multiple draws use this name with a numeric suffix.
mean
Trait mean, or a named vector giving the mean for each location.
residual_sd
Nonnegative plot-error standard deviation, or a named vector giving the standard deviation for each location.
treatment_sd
Nonnegative standard deviation of the treatment signal. The default is 1.25 times the typical residual SD. For factorial treatments, its variance is divided equally among the main effects and a combination-specific interaction.
design_sd
Nonnegative standard deviation for each design term, or a named vector overriding specific terms. Omitted terms use half the typical residual SD.
location_sd
Standard deviation of independent location shifts when mean is a single unnamed value and the trial has several locations. Defaults to 0.625 times the typical residual SD.
spatial
FALSE (default), TRUE for defaults, or a named list overriding sd (half the typical residual SD), rho_row (0.5) and rho_col (0.5). The spatial effect is a separable AR1 x AR1 field with standard deviation sd: rho_row is the correlation between plots in adjacent rows of the same column, rho_col between plots in adjacent columns of the same row, and plots dr rows and dc columns apart have correlation rho_row^dr * rho_col^dc. Spatial correlation requires physical ROW and COLUMN in the field book, with unique coordinate pairs within each location. A Latin square or row-column design stores its experimental rows and columns there, so first replace its field book with the physical layout: x$fieldBook <- field_layout(x), then simulate(x, spatial = TRUE). The layout keeps the experimental axes as ROW_SQ/COLUMN_SQ or ROW_REP/COLUMN_REP, so the design effects are unchanged.

Value

A fieldhub_simulation list with the field book augmented by the responses, the input field book, the response data frame, one list of plot-aligned effect contributions per draw, and replay metadata. Standard deviations are in trait units and the Gaussian response is unbounded.

Details

The typical residual SD is the arithmetic mean of the location residual SDs. These defaults scale the trait signal and the effects of the design when the user changes the residual SD to suit a trait's units.

See also

reproduce_simulation()

Examples

x <- RCBD(t = 6, reps = 3, nrows = 3, seed = 20)
sim <- stats::simulate(x, seed = 42, mean = 6, residual_sd = 0.4,
                       treatment_sd = 0.6, design_sd = 0.3)
head(sim$field_book)
#>   ID LOCATION PLOT ROW COLUMN REP TREATMENT    YIELD
#> 1  1     loc1  101   1      1   1        T6 6.364696
#> 2  2     loc1  102   1      2   1        T3 7.193282
#> 3  3     loc1  206   2      1   1        T4 7.747832
#> 4  4     loc1  205   2      2   1        T2 5.559093
#> 5  5     loc1  301   3      1   1        T1 7.164516
#> 6  6     loc1  302   3      2   1        T5 6.642689

# Spatial simulation of a row-column design on its physical layout
rc <- row_column(t = 12, nrows = 3, reps = 2, seed = 1)
rc$fieldBook <- field_layout(rc)
sim_rc <- stats::simulate(rc, seed = 7, spatial = list(rho_row = 0.6, rho_col = 0.3))
sim_rc
#> FielDHub trait simulation (design_gaussian)
#>   Plots: 24  Locations: 1  Draws: 1  Seed: 7
#>   Trait: YIELD
#>   Mean: 100  Residual SD: 8
#>   Treatment SD: 10
#>   Design effects: replicate = 4, row = 4, column = 4
#>   Spatial: sd = 4, rho_row = 0.6, rho_col = 0.3
#>   Effects behind each draw: x$effects[[i]] (location, treatment, replicate, row, column, spatial, residual)
#> 
#>   ID LOCATION PLOT ROW COLUMN REP ROW_REP COLUMN_REP ENTRY TREATMENT    YIELD
#> 1  1        1  101   1      1   1       1          1     4       G-4 126.5555
#> 2  2        1  102   1      2   1       1          2    11      G-11 124.0128
#> 3  3        1  103   1      3   1       1          3     7       G-7 145.6308
#> 4  4        1  104   1      4   1       1          4    12      G-12 112.4280
#> 5  5        1  108   2      1   1       2          1     6       G-6 101.3339
#> 6  6        1  107   2      2   1       2          2     8       G-8 118.4606
#> ... x$field_book has 24 rows and 1 draw