if (FALSE) {
library(agridat)
data(vargas.txe.covs)
data(vargas.txe.yield)
libs(reshape2)
libs(lattice)
redblue <- colorRampPalette(c("firebrick", "lightgray", "#375997"))
Z <- vargas.txe.yield
Z <- acast(Z, year ~ trt, value.var='yield')
levelplot(Z, col.regions=redblue,
main="vargas.txe.yield", xlab="year", ylab="treatment",
scales=list(x=list(rot=90)))
# Double-centered like AMMI
Z <- sweep(Z, 1, rowMeans(Z))
Z <- sweep(Z, 2, colMeans(Z))
# Vargas figure 1
biplot(prcomp(Z, scale.=FALSE), main="vargas.txe.yield")
# Now, PLS relating the two matrices
U <- vargas.txe.covs
U <- scale(U) # Standardized covariates
libs(pls)
m1 <- plsr(Z~U)
# Vargas Fig 2, flipped vertical/horizontal
biplot(m1, which="x", var.axes=TRUE)
}
Run the code above in your browser using DataLab