Hello all, I'm trying to perform a canonical correlations analysis that takes phylogenetic non-independence into account properly (a la what Revall 2009 did for PCA). To this effect, I've written a script to do canonical correlates in R based entirely on SVD instead of QR decomp. (because I understand SVD better) that recapitulates the cancor() function ( http://nr.com/whp/notes/CanonCorrBySVD.pdf).
The way I'm currently approaching this is, I'm centering each column of X and Y on their phylogenetic mean instead of their numeric mean, and multiplying the centered matrices by the inverse of the vcv. Is this appropriate/correct? Is there a better way? Simplified example code posted below: tree <- rtree(10) X <- replicate(5, rnorm(10)) Y <- replicate(6, rnorm(10)) rownames(X) <- rownames(Y) <- tree$tip.label C <- vcv(tree) inC <- solve(C) Ones <- rep(1, nrow(X)) PMx <- t(solve(t(Ones) %*% inC %*% Ones) %*% t(Ones) %*%inC %*% X) PMy <- t(solve(t(Ones) %*% inC %*% Ones) %*% t(Ones) %*%inC %*% Y) pcX <- invC %*% (X - Ones %*% t(PMx)) pcY <- invC %*% (Y - Ones %*% t(PMy)) #SVD of X, Y and Ux'Uy Xs <- svd(pcX) Ys <- svd(pcY) uTu <- t(Xs$u) %*% Ys$u uTus <- svd(uTu) #Canonical coefficients for X A <- Xs$v %*% solve(diag(Xs$d)) %*% uTus$u #Canonical coefficients for Y B <- Ys$v %*% solve(diag(Ys$d)) %*% uTus$v -- Jon _____ Jonathan S. Mitchell http://home.uchicago.edu/~mitchelljs/ PhD Student Committee on Evolutionary Biology The University of Chicago 1025 57th Str, Culver Hall 402 Chicago, IL 60637 Geology Department The Field Museum of Natural History 1400 S. Lake Shore Dr. Chicago, IL 60605 [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo