## Reduced example from Smith et al. (2015)
## Generate two-phase design
mill.fac <- fac.gen(list(Mrep = 2, Mday = 2, Mord = 3))
field.lay <- fac.gen(list(Frep = 2, Fplot = 4))
field.lay$Variety <- factor(c("D","E","Y","W","G","D","E","M"),
levels = c("Y","W","G","M","D","E"))
start.design <- cbind(mill.fac, field.lay[c(3,4,5,8,1,7,3,4,5,8,6,2),])
rownames(start.design) <- NULL
## Set gammas
terms <- c("Variety", "Frep", "Frep:Fplot", "Mrep", "Mrep:Mday", "Mrep:Mday:Mord")
gammas <- c(1, 0.1, 0.2, 0.3, 0.2, 1)
names(gammas) <- terms
## Specify matrices to calculate the variance matrix of the predicted fixed Variety effects
Vu <- with(start.design, fac.vcmat(Mrep, gammas["Mrep"]) +
fac.vcmat(fac.combine(list(Mrep,Mday)), gammas["Mrep:Mday"]) +
fac.vcmat(Frep, gammas["Frep"]) +
fac.vcmat(fac.combine(list(Frep,Fplot)), gammas["Frep:Fplot"]))
## Calculate the variance matrix of the predicted random Variety effects using formulae
Vu <- mat.random(random = ~ -1 + Mrep/Mday + Frep/Fplot,
G = as.list(gammas[c(4,5,2,3)]),
design = start.design)
Run the code above in your browser using DataLab