# NOT RUN {
####=========================================####
#### For CRAN time limitations most lines in the
#### examples are silenced with one '#' mark,
#### remove them and run the examples
####=========================================####
data(h2example)
head(h2example)
####=========================================####
#### fit the mixed model (very heavy model)
####=========================================####
# ans1 <- mmer2(y~Env,
# random=~at(Env):Name + at(Env):Block,
# rcov=~at(Env):units,
# data=h2example)
# summary(ans1)
####=========================================####
#### calculate heritability
####=========================================####
# length(levels(h2example$Env)) # number of environment
# 2 # number of blocks
# # using the pin function
# pin(ans1,h2example~(V1+(V3/15))/(V1+(V3/15)+(V5/(2*15))))
# # using the
# h2.fun(ans1, h2example, gTerm = "Name", eTerm = "Env")
####=========================================####
####=========================================####
#### using the 'mmer' function would be fitted as
####=========================================####
####=========================================####
#data(h2example)
#Y <- h2example$y
#Z1 <- model.matrix(~Name-1,data=h2example)
#Z2 <- model.matrix(~Env-1,data=h2example)
#Z3 <- model.matrix(~Name:Env-1,data=h2example)
#Z4 <- model.matrix(~Block-1,data=h2example)
#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