# NOT RUN {
## For best results, the number of searches may need to be increased.
## 4 replicates of 12 treatments with 16 nested blocks of size 3
## giving a rectangular lattice: see Plan 10.10 Cochran and Cox 1957.
blocks = data.frame(Main = gl(4,12), Sub = gl(16,3))
treatments = data.frame(treatments = gl(12,1,48))
Z=design(treatments, blocks)
print(Z)
## 3 replicates of 15 treatments in 3 main blocks with two sets of
## nested blocks and one control treatment
# }
# NOT RUN {
blocks=data.frame( Main = gl(3,18,54),Sub1 = gl(9,6,54),Sub2 = gl(27,2,54))
treatments=factor(rep(c(1:15,rep("control",3)),3))
Z=design(treatments,blocks)
print(Z)
incid1=table(interaction(Z$Design$Main,Z$Design$Sub1,lex.order = TRUE),Z$Design$treatments)
crossprod(incid1) # print pairwise concurrences within Sub1 blocks
incid2=table(interaction(Z$Design$Main,Z$Design$Sub2,lex.order = TRUE),Z$Design$treatments)
crossprod(incid2) # print pairwise concurrences within Sub2 blocks
# }
# NOT RUN {
## 4 x 12 design for 4 replicates of 12 treatments with 3 plots in each intersection block
## and 3 sub-columns nested within each main column. The optimal row-and column design
## is Trojan with A-efficiency = 22/31 for the intersection blocks
# }
# NOT RUN {
blocks = data.frame(Rows = gl(4,12), Cols = gl(4,3,48), subCols = gl(12,1,48))
treatments = data.frame(treatments =gl(12,1,48))
Z=design(treatments,blocks)
print(Z)
incid=table(interaction(Z$Design$Rows,Z$Design$Cols,lex.order = TRUE),Z$Design$treatments)
crossprod(incid) # print pairwise concurrences within blocks
# }
# NOT RUN {
## 4 x 13 Row-and-column design for 4 replicates of 13 treatments
## Youden design Plan 13.5 Cochran and Cox (1957).
# }
# NOT RUN {
blocks = data.frame(Rows = gl(4,13), Cols = gl(13,1,52))
treatments = data.frame(treatments= gl(13,1,52))
Z=design(treatments,blocks,searches = 700)
print(Z)
incid=table(Z$Design$Cols,Z$Design$treatments)
crossprod(incid) # print pairwise concurrences of treatments within column blocks (BIB's)
# }
# NOT RUN {
## 48 treatments in 2 replicate blocks with 2 nested rows in each replicate and 3 main columns
blocks = data.frame(Reps = gl(2,48), Rows = gl(4,24,96), Cols = gl(3,8,96))
treatments = data.frame(treatments=gl(48,1,96))
Z=design(treatments,blocks,searches=5)
print(Z)
## 48 treatments in 2 replicate blocks with 2 main columns
## The default weighting gives non-estimable Reps:Cols effects due to inherent aliasing
## Increased weighting gives estimable Reps:Cols effects but non-orthogonal main effects
# }
# NOT RUN {
blocks = data.frame(Rows = gl(2,48), Cols = gl(2,24,96))
Z1=design(treatments=gl(48,1,96),blocks,searches=5)
print(Z1)
Z2=design(treatments=gl(48,1,96),blocks,searches=5,weighting=.9)
print(Z2)
# }
# NOT RUN {
## Equireplicate balanced designs with unequal block sizes. Gupta & Jones (1983).
## Check for equality of D and A-efficiency in optimized design
t=factor(c(rep(1:12,each=7)))
b=factor(c(rep(1:12,each=6),rep(13:18,each=2)))
Z=design(t,b,searches=100)$Blocks_model # max efficiency = 6/7
print(Z)
# }
# NOT RUN {
t=factor(c(rep(1:14,each=8)))
b=factor(c(rep(1:14,each=4),rep(15:21,each=8)))
Z=design(t,b,searches=500)$Blocks_model # max efficiency = 7/8
print(Z)
# }
# NOT RUN {
t=factor(c(rep(1:16,each=7)))
b=factor(c(rep(1:16,each=4),rep(17:22,each=8)))
Z=design(t,b,searches=1000)$Blocks_model # max efficiency = 6/7
print(Z)
# }
# NOT RUN {
t=factor(c(rep(1:18,each=7)))
b=factor(c(rep(1:18,each=6),rep(19:24,each=3)))
Z=design(t,b,searches=500)$Blocks_model # max efficiency = 6/7
print(Z)
# }
# NOT RUN {
## Factorial treatment designs defined by a factorial treatment model
## Main effects of five 2-level factors in a half-fraction in 2/2/2 nested blocks design
## The algorithmic search method is likely to require a very long search time to reach the
## known orthogonal solution for this regular fractional factorial design
# }
# NOT RUN {
treatments = list(F1 = gl(2,1), F2 = gl(2,1),F3 = gl(2,1), F4 = gl(2,1), F5 = gl(2,1))
blocks = data.frame(b1 = gl(2,8),b2 = gl(4,4),b3 = gl(8,2))
model= ~ F1 + F2 + F3 + F4 + F5
repeat {Z = design(treatments,blocks,treatments_model=model,searches=50)
if ( isTRUE(all.equal(Z$Blocks_model[3,3],1) ) ) break }
print(Z)
# }
# NOT RUN {
# Second-order model for five qualitative 2-level factors in 4 randomized blocks with two
# nested sub-blocks in each main plot
treatments = list(F1 = gl(2,1), F2 = gl(2,1),F3 = gl(2,1), F4 = gl(2,1), F5 = gl(2,1))
blocks = data.frame(main = gl(4,8),sub=gl(8,4))
model = ~ (F1 + F2 + F3 + F4 + F5)^2
Z=design(treatments,blocks,treatments_model=model,searches = 10)
print(Z)
# Main effects of five 2-level factors in a half-fraction of a 4 x 4 row-and column design
# }
# NOT RUN {
treatments = list(F1 = gl(2,1), F2 = gl(2,1),F3 = gl(2,1), F4 = gl(2,1), F5 = gl(2,1))
blocks = data.frame(rows = gl(4,4), cols = gl(4,1,16))
model = ~ F1 + F2 + F3 + F4 + F5
repeat {Z = design(treatments,blocks,treatments_model=model,searches=50)
if ( isTRUE(all.equal(Z$Blocks_model[2,3],1) ) ) break}
print(Z)
# }
# NOT RUN {
# Quadratic regression for three 3-level numeric factor assuming a 10/27 fraction
treatments = list(A = 1:3, B = 1:3, C = 1:3)
blocks=factor(rep(1,10))
model = ~ ( A + B + C)^2 + I(A^2) + I(B^2) + I(C^2)
Z=design(treatments,blocks,treatments_model=model,searches=10)
print(Z)
## response surface designs with doubled treatment candidate sets
## allowing duplicated design points
## two treatment factor design showing double replication on the
## four corner points and double replication on the centre point
treatments = list( V1 = 1:3, V2 = rep(1:3,2))
blocks=factor(rep(1,14))
model = ~ (V1 + V2)^2 + I(V1^2) + I(V2^2)
design(treatments,blocks,treatments_model=model,searches=10)
## three treatment factor design with eight corner points, 12 edge points and 1 centre
## point. All 21 design points are accounted for leaving nothing for extra replication.
treatments = list( V1 = 1:3, V2 = 1:3, V3 = rep(1:3,2))
blocks=factor(rep(1,21))
model = ~ (V1 + V2 + V3)^2 + I(V1^2) + I(V2^2) + I(V3^2)
design(treatments,blocks,treatments_model=model,searches=20)
## as above but with extra replication on each corner point and on the centre point
treatments = list( V1 = 1:3, V2 = 1:3, V3 = rep(1:3,2))
blocks=factor(rep(1,30))
model = ~ (V1 + V2 + V3)^2 + I(V1^2) + I(V2^2) + I(V3^2)
design(treatments,blocks,treatments_model=model,searches=20)
## Factorial treatment designs defined by sequentially fitted factorial treatment models
## 4 varieties by 3 levels of N by 3 levels of K assuming degree-2 treatment
## interaction effects and two blocks of 12 plots
## the single stage model gives an unequal split for the replication of the four varieties
## which may be undesirable whereas the two stage model forces an equal split of 6 plots
## per variety. The single stage model is slightly more efficient than the two stage model
## (1.052045 versus 0.9761135 standardized relative to the full factorial design) but
## in this example global D-optimality does not give the most suitable design structure.
# }
# NOT RUN {
treatments = list(Variety = factor(1:4), N = 1:3, K = 1:3)
blocks = data.frame(main=gl(2,12))
treatments_model = ~ (Variety + N + K)^2 + I(N^2) + I(K^2)
Z1 = design(treatments,blocks,treatments_model=treatments_model,searches=10)
print(Z1)
treatments_model = list( ~ Variety , ~ Variety + (Variety + N + K)^2 + I(N^2) + I(K^2))
Z2 = design(treatments,blocks,treatments_model=treatments_model,searches=10)
print(Z2)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab