data(aastveit.barley)
# First, PCA of each matrix separately
Z <- aastveit.barley$height
Z <- sweep(Z, 1, rowMeans(Z))
Z <- sweep(Z, 2, colMeans(Z)) # Double-centered
sum(Z^2)*4 # Total SS
sv <- svd(Z)$d
round(100 * sv^2/sum(sv^2),1) # Prop of variance each axis
biplot(prcomp(Z)) # Aastveit Figure 1. PCA of height
U <- aastveit.barley$covs
U <- scale(U) # Standardized covariates
sv <- svd(U)$d
round(100 * sv^2/sum(sv^2),1) # Prop variance each axis
# Now, PLS relating the two matrices
require(pls)
m1 <- plsr(Z~U)
loadings(m1)
# Aastveit Fig 2a (genotypes), not rotated as they did
biplot(m1, which="y", var.axes=TRUE)
# Fig 2b, 2c (not rotated)
biplot(m1, which="x", var.axes=TRUE)Run the code above in your browser using DataLab