# NOT RUN {
####=========================================####
#### For CRAN time limitations most lines in the
#### examples are silenced with one '#' mark,
#### remove them and run the examples
####=========================================####
data(h2)
head(h2)
####=========================================####
#### fit the mixed model and extract var.comp
####=========================================####
#ans1 <- mmer2(y~1, random=~Name + Env + Name:Env + Block,data=h2, method="NR")
#vc <- ans1$var.comp
#V_E <- vc[2,1];V_GE <- vc[3,1];V_G <- vc[1,1];Ve <- vc[5,1]
####=========================================####
#### calculate heritability
####=========================================####
#n.env <- length(levels(h2$Env))
#h2c <- V_G/(V_G + V_GE/n.env + Ve/(2*n.env)) #the 2 is a reference for block#
#h2c
####=========================================####
####=========================================####
#### using the 'mmer' function would be fitted as
####=========================================####
####=========================================####
#data(h2)
#Y <- h2$y
#Z1 <- model.matrix(~Name-1,data=h2)
#Z2 <- model.matrix(~Env-1,data=h2)
#Z3 <- model.matrix(~Name:Env-1,data=h2)
#Z4 <- model.matrix(~Block-1,data=h2)
#ETA <- list(Name=list(Z=Z1),
# Env=list(Z=Z2),
# Name.Env=list(Z=Z3),
# Block=list(Z=Z4))
#ans1 <- mmer(Y=Y,Z=ETA)
#vc <- ans1$var.comp
# }
Run the code above in your browser using DataLab