# NOT RUN {
data(vargas.wheat1)
# }
# NOT RUN {
gvals <- vargas.wheat1$genvals
evals <- vargas.wheat1$envvals
require(pls)
# Yield as a function of gen variates
require(reshape2)
gv <- melt(gvals, id.var=c('gen','rep','year'))
Y0 <- subset(gv, variable=="yield")
Y0 <- acast(Y0, gen~year, mean)
Y0 <- sweep(Y0, 1, rowMeans(Y0))
Y0 <- sweep(Y0, 2, colMeans(Y0)) # GxE residuals
Y1 <- scale(Y0) # scaled columns
X1 <- subset(gv, variable!="yield")
X1 <- acast(X1, gen~variable, mean)
X1 <- scale(X1) # scaled columns
m1 <- plsr(Y1~X1)
loadings(m1)[,1,drop=FALSE] # X loadings in Table 1 of Vargas
biplot(m1, cex=.5, which="x", var.axes=TRUE,
main="vargas.wheat1 - gen ~ trait") # Vargas figure 2a
# Yield as a function of env variates
Y2 <- t(Y0)
X2 <- vargas.wheat1$envvals
rownames(X2) <- X2$year
X2 <- as.matrix(X2[,-1])
Y2 <- scale(Y2)
X2 <- scale(X2)
m2 <- plsr(Y2~X2)
loadings(m2)[,1,drop=FALSE] # X loadings in Table 2 of Vargas
# }
Run the code above in your browser using DataLab