data(DT_h2)
DT <- DT_h2
DT=DT[with(DT, order(Env)), ]
ans1b <- mmec(y~Env,
random=~vsc( usc(rrc(Env, Name, y, nPC = 3)) , isc(Name)),
rcov=~units,
# we recommend giving more iterations to these models
nIters = 50,
# we recommend giving more EM iterations at the beggining
emWeight = c(rep(1,10),logspace(10,1,.05), rep(.05,80)),
data=DT)
summary(ans1b)$varcomp
vcd <- diag(ans1b$theta[[1]])
vcd/sum(vcd) # the 3rd PC still explains more than the 2nd
# ## Extract BLUPs
# ## extract loadings
# loadings=with(DT, rrc(Env, Name, y, returnLam = TRUE, nPC = 3))$Lam
# ## extract factor scores
# scores <- ans1b$uList[[1]];
# ## BLUPs for all environments
# E= scores t(loadings) # change space for matrix product
# ## Extract the covariance matrix
# vc <- ans1b$theta[[1]];vc
# G = loadings vc t(loadings) # change space for matrix product
# lattice::levelplot(cov2cor(G))
Run the code above in your browser using DataLab