Skip to content

Worked example in R and Shiny · Install FielDHub

Generates a Completely Randomized Design (CRD)

Source: R/fct_CRD.R

It randomly generates a completely randomized design.

Usage

CRD(
  t = NULL,
  reps = NULL,
  plotNumber = 101,
  locationName = NULL,
  seed = NULL,
  data = NULL,
  locationNames = NULL,
  nrows = NULL,
  ncols = NULL,
  stacked = NULL
)

Arguments

t
An integer number with total number of treatments or a vector of dimension t with labels.
reps
One positive whole-number count of replicates per treatment.
plotNumber
Starting plot number. By default plotNumber = 101.
locationName
Deprecated spelling of locationNames. Existing positional calls remain supported, with a deprecation warning.
seed
(optional) Real number that specifies the starting seed to obtain reproducible designs.
data
(optional) Data frame whose first two columns contain unique treatment labels and positive whole-number replication counts. Extra columns are ignored; rows missing either selected value are omitted.
locationNames
(optional) Name of the single location. Supply only one of locationNames and locationName.
nrows, ncols
Optional positive whole numbers: the rows and columns of the field at each location. If only one is given, the other follows from the number of plots. The field book then has ROW and COLUMN, and its plots are numbered along the serpentine planting path of the whole field. See field_layout for how the design is placed.
stacked
The stacking of the replicates of the designs in blocks. A completely randomized design has no replicates to stack: giving stacked is an error.

Value

A list with three elements.

  • metadata records the design, schema/package versions, seed, random-number settings and effective input parameters.

  • infoDesign is a list with information on the design parameters.

  • fieldBook is a data frame with the CRD field book.

Details

The result records effective inputs and the resolved seed in metadata$parameters. Under the same package versions and RNG settings, rebuild a result x with do.call(CRD, x$metadata$parameters). Data inputs are recorded after the existing column selection and normalization.

References

Federer, W. T. (1955). Experimental Design. Theory and Application. New York, USA. The Macmillan Company.

Author

Didier Murillo [aut], Salvador Gezan [aut], Ana Heilman [ctb], Thomas Walk [ctb], Johan Aparicio [ctb], Richard Horsley [ctb]

Examples

# Example 1: Generates a CRD design with 10 treatments and 5 reps each.
crd1 <- CRD(
  t = 10,
  reps = 5,
  plotNumber = 101,
  seed = 1987,
  locationNames = "Fargo"
)
crd1$infoDesign
#> $numberofTreatments
#> [1] 10
#> 
#> $treatments
#>  [1] "T1"  "T2"  "T3"  "T4"  "T5"  "T6"  "T7"  "T8"  "T9"  "T10"
#> 
#> $Reps
#> [1] 5
#> 
#> $locationName
#> [1] "Fargo"
#> 
#> $seed
#> [1] 1987
#> 
#> $id_design
#> [1] 1
#> 
head(crd1$fieldBook, 10)
#>    ID LOCATION PLOT REP TREATMENT
#> 1   1    Fargo  101   1       T10
#> 2   2    Fargo  102   4        T1
#> 3   3    Fargo  103   3        T3
#> 4   4    Fargo  104   3        T9
#> 5   5    Fargo  105   4        T3
#> 6   6    Fargo  106   5        T3
#> 7   7    Fargo  107   1        T2
#> 8   8    Fargo  108   3        T4
#> 9   9    Fargo  109   1        T1
#> 10 10    Fargo  110   3        T1

# Example 2: Generates a CRD design with 15 treatments and 6 reps each.
Gens <- paste("Wheat", 1:15, sep = "")
crd2 <- CRD(
  t = Gens,
  reps = 6,
  plotNumber = 1001,
  seed = 1654,
  locationNames = "Fargo"
)
crd2$infoDesign
#> $numberofTreatments
#> [1] 15
#> 
#> $treatments
#>  [1] "Wheat1"  "Wheat2"  "Wheat3"  "Wheat4"  "Wheat5"  "Wheat6"  "Wheat7" 
#>  [8] "Wheat8"  "Wheat9"  "Wheat10" "Wheat11" "Wheat12" "Wheat13" "Wheat14"
#> [15] "Wheat15"
#> 
#> $Reps
#> [1] 6
#> 
#> $locationName
#> [1] "Fargo"
#> 
#> $seed
#> [1] 1654
#> 
#> $id_design
#> [1] 1
#> 
head(crd2$fieldBook, 10)
#>    ID LOCATION PLOT REP TREATMENT
#> 1   1    Fargo 1001   6    Wheat8
#> 2   2    Fargo 1002   2    Wheat2
#> 3   3    Fargo 1003   2    Wheat6
#> 4   4    Fargo 1004   4   Wheat11
#> 5   5    Fargo 1005   1   Wheat11
#> 6   6    Fargo 1006   1    Wheat4
#> 7   7    Fargo 1007   1   Wheat13
#> 8   8    Fargo 1008   1    Wheat1
#> 9   9    Fargo 1009   6    Wheat5
#> 10 10    Fargo 1010   4    Wheat9

# Example 3: Generates a CRD design with 12 treatments and 4 reps each.
# In this case, we show how to use the option data.
treatments <- paste("ND-", 1:12, sep = "")
treatment_list <- data.frame(list(TREATMENT = treatments, REP = 4))
head(treatment_list)
#>   TREATMENT REP
#> 1      ND-1   4
#> 2      ND-2   4
#> 3      ND-3   4
#> 4      ND-4   4
#> 5      ND-5   4
#> 6      ND-6   4
crd3 <- CRD(
  t = NULL,
  reps = NULL,
  plotNumber = 2001,
  seed = 1655,
  locationNames = "Cali",
  data = treatment_list
)
crd3$infoDesign
#> $numberofTreatments
#> [1] 12
#> 
#> $treatments
#>  [1] "ND-1"  "ND-2"  "ND-3"  "ND-4"  "ND-5"  "ND-6"  "ND-7"  "ND-8"  "ND-9" 
#> [10] "ND-10" "ND-11" "ND-12"
#> 
#> $Reps
#>  [1] 4 4 4 4 4 4 4 4 4 4 4 4
#> 
#> $locationName
#> [1] "Cali"
#> 
#> $seed
#> [1] 1655
#> 
#> $id_design
#> [1] 1
#> 
head(crd3$fieldBook, 10)
#>    ID LOCATION PLOT REP TREATMENT
#> 1   1     Cali 2001   4      ND-3
#> 2   2     Cali 2002   1      ND-7
#> 3   3     Cali 2003   2      ND-2
#> 4   4     Cali 2004   3      ND-8
#> 5   5     Cali 2005   3      ND-2
#> 6   6     Cali 2006   1     ND-10
#> 7   7     Cali 2007   3      ND-7
#> 8   8     Cali 2008   4      ND-9
#> 9   9     Cali 2009   3      ND-4
#> 10 10     Cali 2010   1      ND-3