Experimental design
Agricolae builds more experimental designs used in agricultural research. The design includes the randomization of treatments in the experimental units according to the conditions of the design and prepare the field book and sketches of treatments according to the conditions of the design.
Complete
Randomized Design (crd)
Treatments fixed with equal or different replications.
> library(agricolae)
> cipnumber <-c("CIP-101","CIP-201","CIP-301","CIP-401","CIP-501")
> rep <-c(4,3,5,4,3)
> # seed = 12543
> outdesign1 <-design.crd(cipnumber,rep,serie=2,seed=12543,"Mersenne-Twister")
> crd1 <- outdesign1$book
> crd1
plots cipnumber r
1 101 CIP-301 1
2 102 CIP-401 1
.....
19 119 CIP-401 4
> # no seed
> outdesign2 <-design.crd(cipnumber,rep,serie=2)
> crd2 <- outdesign2$book
> crd2
plots cipnumber r
1 101 CIP-501 1
2 102 CIP-301 1
....
19 119 CIP-401 4
Randomized
complete block design
treatment and block fixed (4 treatments with 5 blocks).
> library(agricolae)
> # 4 treatments and 5 blocks
> trt<-c("A","B","C","D")
>
outdesign <-design.rcbd(trt,5,serie=2,45,"Super-Duper") # seed = 45
>
rcbd <- outdesign$book
> rcbd # field book
plots block trt
1 101 1 C
2 102 1 B
....
20 120 5 B
> plots <-as.numeric(rcbd[,1])
> trt <-as.character(rcbd[,3])
> dim(plots)<-c(4,5)
> dim(trt) <-c(4,5)
> print(t(plots))
[,1] [,2] [,3] [,4]
[1,] 101 102 103 104
[2,] 105 106 107 108
[3,] 109 110 111 112
[4,] 113 114 115 116
[5,] 117 118 119 120
> print(t(trt))
[,1] [,2] [,3] [,4]
[1,] "C" "B" "D" "A"
[2,] "B" "D" "C" "A"
[3,] "A" "B" "C" "D"
[4,] "B" "A" "D" "C"
[5,] "D" "C" "A" "B"
> book<-zigzag(outdesign)
> print(t(matrix(book$plots,c(4,5))))
[,1] [,2] [,3] [,4]
[1,] 101 102 103 104
[2,] 204 203 202 201
[3,] 301 302 303 304
[4,] 404 403 402 401
[5,] 501 502 503 504
> print(t(matrix(book$trt,c(4,5))))
[,1] [,2] [,3] [,4]
[1,] "A" "B" "C" "D"
[2,] "B" "D" "C" "A"
[3,] "A" "B" "C" "D"
[4,] "B" "A" "D" "C"
[5,] "D" "C" "A" "B"
Latin square design
treatment fixed (4 trt).
> library(agricolae)
> varieties<-c("perricholi","yungay","maria bonita","tomasa")
> outdesign <-design.lsd(varieties,serie=3,seed=23)
> lsd <- outdesign$book
> lsd # print field book.
plots row col varieties
1 1001 1 1 perricholi
2 1002 1 2 yungay
.....
16 1016 4 4 tomasa
> plots <-as.numeric(lsd[,1])
> trt <-as.character(lsd[,4])
> dim(plots)<-c(4,4)
> dim(trt) <-c(4,4)
> print(t(plots))
[,1] [,2] [,3] [,4]
[1,] 1001 1002 1003 1004
[2,] 1005 1006 1007 1008
[3,] 1009 1010 1011 1012
[4,] 1013 1014 1015 1016
> print(t(trt))
[,1] [,2] [,3] [,4]
[1,] "perricholi" "yungay" "tomasa" "maria bonita"
[2,] "maria bonita" "tomasa" "yungay" "perricholi"
[3,] "tomasa" "perricholi" "maria bonita" "yungay"
[4,] "yungay" "maria bonita" "perricholi" "tomasa"
> book<-zigzag(outdesign)
> print(t(matrix(book$plots,c(4,4))))
[,1] [,2] [,3] [,4]
[1,] 1001 1002 1003 1004
[2,] 2004 2003 2002 2001
[3,] 3001 3002 3003 3004
[4,] 4004 4003 4002 4001
> print(t(matrix(book$varieties,c(4,4))))
[,1] [,2] [,3] [,4]
[1,] "perricholi" "yungay" "maria bonita" "tomasa"
[2,] "yungay" "maria bonita" "tomasa" "perricholi"
[3,] "tomasa" "perricholi" "yungay" "maria bonita"
[4,] "maria bonita" "tomasa" "perricholi" "yungay"
Graeco
design
Two treatments differente applied orthogonally, example four levels each
factor.
>
library(agricolae)
> T1<-c("a","b","c","d")
> T2<-c("v","w","x","y")
> greco <- design.graeco(T1,T2,number=101)
> outdesign <- design.graeco(T1,T2,serie=2)
> greco <- outdesign$book # field book
> greco
plots row col T1 T2
1 101 1 1 d y
2 102 1 2 b w
....
15 115 4 3 b y
16 116 4 4 d w
> trt <- paste(greco[,4],greco[,5])
> print(t(matrix(book$plots,c(4,4))))
[,1] [,2] [,3] [,4]
[1,] 101 102 103 104
[2,] 105 106 107 108
[3,] 109 110 111 112
[4,] 113 114 115 116
> print(t(matrix(trt,c(4,4))))
[,1] [,2] [,3] [,4]
[1,] "d y" "b w" "c v" "a x"
[2,] "b x" "d v" "a w" "c y"
[3,] "c w" "a y" "d x" "b v"
[4,] "a v" "c x" "b y" "d w"
> book<-zigzag(outdesign)
> print(t(matrix(book$plots,c(4,4))))
[,1] [,2] [,3] [,4]
[1,] 101 102 103 104
[2,] 204 203 202 201
[3,] 301 302 303 304
[4,] 404 403 402 401
Balanced
incomplete block design
Treatment fixed and number by blocks (4 treatments and 3 plots by block).
>
library(agricolae)
> # 4 treatments and k=3 size block
> trt<-c("A","B","C","D")
> k<-3
> outdesign <-design.bib(trt,k,serie=2,seed =41,kinds ="Super-Duper") #
seed = 37
Parameters BIB
==============
Lambda : 2
treatmeans : 4
Block size : 3
Blocks : 4
Replication: 3
Efficiency factor 0.8888889
<<< Book >>>
> bib <- outdesign$book # field book
> print(bib)
plots block trt
1 101 1 D
2 102 1 C
. . .
12 403 4 D
> t(matrix(bib$plots,c(3,4)))
[,1] [,2] [,3]
[1,] 101 102 103
[2,] 201 202 203
[3,] 301 302 303
[4,] 401 402 403
> t(matrix(bib$trt,c(3,4)))
[,1] [,2] [,3]
[1,] "D" "C" "A"
[2,] "C" "B" "D"
[3,] "C" "A" "B"
[4,] "A" "B" "D"
Alpha Design (0,1)
Treatments fixed applied in different blocks with two, three or four
replications (example 12 levels of treatments).
> # Example two
> trt<-letters[1:12]
> t <- length(trt)
> k<-3
> r<-3
> s<-t/k
> outdesign <- design.alpha(trt,k,r)
alpha design (0,1) - Serie III
Parameters Alpha design
=======================
treatmeans : 12
Block size : 3
Blocks : 4
Replication: 3
Efficiency factor
(E ) 0.7096774
<<< Book >>>
>
book<-outdesign$book
> book
plots cols block trt replication
1 101 1 1 h 1
2 102 2 1 e 1
3 103 3 1 b 1
4 104 1 2 d 1
5 105 2 2 g 1
6 106 3 2 j 1
...
35 311 2 12 k 3
36 312 3 12 b 3
> plots<-book[,1]
> dim(plots)<-c(k,s,r)
> for (i in 1:r) print(t(plots[,,i]))
[,1] [,2] [,3]
[1,] 101 102 103
[2,] 104 105 106
[3,]
107 108 109
[4,]
110 111 112
[,1] [,2] [,3]
[1,]
201 202 203
[2,]
204 205 206
[3,]
207 208 209
[4,]
210 211 212
[,1] [,2] [,3]
[1,]
301 302 303
[2,]
304 305 306
[3,]
307 308 309
[4,]
310 311 312
>
outdesign$sketch
$rep1
[,1] [,2] [,3]
[1,] "h" "e" "b"
[2,] "d" "g" "j"
[3,] "i" "a" "k"
[4,] "l" "c" "f"
$rep2
[,1] [,2] [,3]
[1,] "e" "k" "c"
[2,] "g" "i" "b"
[3,] "a" "j" "l"
[4,] "h" "d" "f"
$rep3
[,1] [,2] [,3]
[1,] "h" "i" "c"
[2,] "f" "g" "a"
[3,] "l" "d" "e"
[4,] "j" "k" "b"
Lattice design
Treatments fixed one square perfect (9, 16, 25, 36, .... treatments). The
treatments are apply in two or three replications
> # lattice
3x3 for 9 treatments
> library(agricolae)
> letters[1:9] -> trt
> output<-design.lattice(trt, r=3)
Lattice design, triple 3 x 3
Efficiency factor
(E ) 0.7272727
<<< Book >>>
> book<-output$book
plots cols block trt
replication
1 101 1 1 h 1
2 102 2 1 i 1
3 103 3 1 b 1
4 104 1 2 a 1
...
26 308 2 9 f 3
27 309 3 9 b 3
>
outdesign$sketch
$rep1
[,1] [,2] [,3]
[1,] "h" "i" "b"
[2,] "a" "g" "d"
[3,] "f" "e" "c"
$rep2
[,1] [,2] [,3]
[1,] "d" "h" "e"
[2,] "i" "f" "a"
[3,] "b" "c" "g"
$rep3
[,1] [,2] [,3]
[1,] "a" "h" "c"
[2,] "e" "g" "i"
[3,] "d" "f" "b"
Cyclic design
(trt = 8)
> # block size = 2, replication = 6
> library(agricolae)
> trt<-letters[1:8]
>
outdesign <- design.cyclic(trt,k=2, r=6)
cyclic design
Generator block basic:
1 2
1 4
1 3
Parameters
===================
treatmeans : 8
Block size : 2
Replication: 6
> names(outdesign)
[1] "parameters"
"sketch" "book"
> # groups 1,2,3
> outdesign$sketch[[1]]
[,1] [,2]
[1,] "c" "d"
[2,] "e" "d"
[3,] "g" "f"
[4,] "c" "b"
[5,] "g" "h"
[6,] "a" "b"
[7,] "e" "f"
[8,] "a" "h"
> outdesign$sketch[[2]]
[,1] [,2]
[1,] "g" "b"
[2,] "e" "b"
[3,] "a" "d"
[4,] "f" "a"
[5,] "e" "h"
[6,] "d" "g"
[7,] "f" "c"
[8,] "c" "h"
> outdesign$sketch[[3]]
[,1] [,2]
[1,] "g" "e"
[2,] "c" "e"
[3,] "h" "b"
[4,] "f" "d"
[5,] "g" "a"
[6,] "a" "c"
[7,] "h" "f"
[8,] "b" "d"
> book<-outdesign$book
> book
plots group block trt
1 101 1 1 c
2 102 1 1 d
3 103 1 2 e
4 104 1 2 d
5 105 1 3 g
...
47 315 3 24 b
48 316 3 24 d
Cyclic design with row-column design (rowcol = TRUE), trt
= 9
> # block size = 2, replication = 6
> library(agricolae)
> trt<-letters[1:9]
> outdesign <- design.cyclic(trt,k=3, r=9, rowcol=TRUE)
cyclic design
Generator block basic:
1 2 4
1 3 7
1 2 6
Parameters
===================
treatmeans : 9
Block size : 3
Replication: 9
outdesign$sketch[[1]]
[,1] [,2] [,3]
[1,] "e" "f" "h"
[2,] "f" "g" "i"
[3,] "i" "a" "c"
[4,] "g" "h" "a"
[5,] "h" "i" "b"
[6,] "b" "c" "e"
[7,] "c" "d" "f"
[8,] "d" "e" "g"
[9,] "a" "b" "d"
> outdesign$sketch[[2]]
[,1] [,2] [,3]
[1,] "h" "a" "e"
[2,] "a" "c" "g"
[3,] "i" "b" "f"
[4,] "g" "i" "d"
[5,] "d" "f" "a"
[6,] "f" "h" "c"
[7,] "e" "g" "b"
[8,] "b" "d" "h"
[9,] "c" "e" "i"
> outdesign$sketch[[3]]
[,1] [,2] [,3]
[1,] "g" "h" "c"
[2,] "i" "a" "e"
[3,] "c" "d" "h"
[4,] "h" "i" "d"
[5,] "a" "b" "f"
[6,] "e" "f" "a"
[7,] "b" "c" "g"
[8,] "d" "e" "i"
[9,] "f" "g" "b"
Factorial in experimental design n^k, k factors with n-levels by factor.
>
library(agricolae)
> level<- 2; factors<-3 ; blocks <- 4
> fact.nk(level,factors,blocks)
plots blocks A B C
1 1 1 1 0 0
2 2 1 1 0 1
....
32 32 4 0 0 0
> # factorial 2^5 in 4 blocks
> fact.nk(2,5,4)
plots blocks A B C D E
1 1 1 0 0 1 1 1
2 2 1 1 1 0 0 0
....
128 128 4 1 0 0 0 1
> # factorial two factors in 3 levels for 4 blocks
> fact.nk(3,2,4,seed=100,kinds="Mersenne-Twister")
plots blocks A B
1 1 1 1 0
2 2 1 0 1
....
36 36 4 2 2
> # factorial 4x4 = 4^2 in 3 blocks
> fact.nk(4,2,3)
plots blocks A B
1 1 1 0 3
2 2 1 0 0
....
48 48 3 2 2
Factorial pxq (2 factors
in blocks)
> # factorial 3 x 3 with 5 replications
> # 3 varieties from potato and nitrogen in the fertilization, kg/ha
> library(agricolae)
> variety <- c("perricholi","canchan","tomasa")
> nitrogen <- c(40,80,120) # level of nitrogen
> trt<-c(3,3)
> outdesign <-design.ab(trt, r=5, serie=3)
> book <-
outdesign$book
> book$A<-variety[book$A]
> book$B<-nitrogen[book$B]
> names(book)[3:4]<-c("variety","nitrogen")
> book
plots block variety nitrogen
1 1001 1 perricholi 40
2 1002 1 perricholi 80
3 1003 1 perricholi 120
4 1004 1 canchan 40
5 1005 1 canchan 80
. . .
44 5008 5 canchan 40
45 5009 5 perricholi 120
>