############################################
############################################
# breeding values with 3 variance components
# for hybrid prediction
############################################
############################################
data(cornHybrid)
hybrid2 <- cornHybrid$hybrid # extract cross data
A <- cornHybrid$K
y <- hybrid2$Yield
K1 <- A[levels(hybrid2$GCA1), levels(hybrid2$GCA1)]; dim(K1)
# Realized IBS relationships for set of parents 1
K2 <- A[levels(hybrid2$GCA2), levels(hybrid2$GCA2)]; dim(K2)
# Realized IBS relationships for set of parents 2
S <- kronecker(K1, K2) ; dim(S)
rownames(S) <- colnames(S) <- levels(hybrid2$SCA)
#head(hybrid2)
#ans <- mmer2(Yield ~ Location, random = ~ GCA1 + GCA2 + SCA,
# G=list(GCA1=K1, GCA2=K2, SCA=S),data=hybrid2, method="AI" )
#ans$var.comp
#summary(ans)
## please remember THIS FUNCTION IS LIMITED since the matrices for random
## effects are built based on a dataframe provided, for more general models
## including the genomic analysis please use the 'mmer' function which
## works directly with matrices and is more flexible
###############################################################
## comparison with lmer, install 'lme4' and run the code below
###############################################################
# lmer cannot use var-cov matrices so we will not use them
# in this comparison example
#library(lme4)
#library(sommer)
#fm1 <- lmer(Yield ~ Location + (1|GCA1) + (1|GCA2) + (1|SCA),
# data=hybrid2 )
#out <- mmer2(Yield ~ Location, random = ~ GCA1 + GCA2 + SCA,
# data=hybrid2, method="AI", draw=FALSE )
#summary(fm1)
#summary(out)
#plot(out$cond.residuals, residuals(fm1))
#plot(out$u.hat[[1]], ranef(fm1)$GCA1[,1])
#plot(out$u.hat[[2]], ranef(fm1)$GCA2[,1])
#vv=which(abs(out$u.hat[[3]]) > 0)
#plot(out$u.hat[[3]][vv,], ranef(fm1)$SCA[,1])
###############################################################
## second example against 'lme4', run the code below
###############################################################
#library(lme4)
#data(sleepstudy)
#fm1 <- lmer(Reaction ~ Days + (1 | Subject), sleepstudy)
#summary(fm1)
#out <- mmer2(Reaction ~ Days, random = ~ Subject, data=sleepstudy, draw=FALSE )
#summary(out) #or summary.mmer(out)
# plot(out$cond.residuals, residuals(fm1))
# plot(out$u.hat[[1]], ranef(fm1)[[1]][,1])
Run the code above in your browser using DataLab