if (FALSE) {
library(agridat)
data(vargas.wheat1.covs)
data(vargas.wheat1.traits)
libs(pls)
libs(reshape2)
# Yield as a function of non-yield traits
Y0 <- vargas.wheat1.traits[,c('gen','rep','year','yield')]
Y0 <- acast(Y0, gen ~ year, value.var='yield', fun=mean)
Y0 <- sweep(Y0, 1, rowMeans(Y0))
Y0 <- sweep(Y0, 2, colMeans(Y0)) # GxE residuals
Y1 <- scale(Y0) # scaled columns
X1 <- vargas.wheat1.traits[, -4] # omit yield
X1 <- aggregate(cbind(ANT,MAT,GFI,PLH,BIO,HID,STW,NSM,NGM,
NGS,TKW,WTI,SGW,VGR,KGR) ~ gen, data=X1, FUN=mean)
rownames(X1) <- X1$gen
X1$gen <- NULL
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 environment covariates
Y2 <- t(Y0)
X2 <- vargas.wheat1.covs
rownames(X2) <- X2$year
X2$year <- NULL
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