[R] canonical variates

Kaspar Pflugshaupt pflugshaupt at geobot.umnw.ethz.ch
Wed Mar 8 17:03:19 CET 2000

> I am looking for R code to perform canonical variates analysis on a matrix
> of data. Has anybody already developed such a code? Is it available
> somewhere?

Hello Mauro,

there's the function cancor in library mva. Additionally, Brian Ripley
provided his own inplementation lately on this list:

---start quote---
Suppose you have data matrices
A and B on the same observations. Then

cancor <- function(A, B)
   Ap <- prcomp(scale(A, T, F), retx=T)
   Apc <- Ap$x %*% diag(1/Ap$sdev)
   Bp <- prcomp(scale(B, T, F), retx=T)
   Bpc <- Bp$x %*% diag(1/Bp$sdev)
   Sigma <- crossprod(Apc, Bpc)/(nrow(A) - 1)
   s <- svd(Sigma, ncol(A), ncol(B))
   return(list(cor=s$d, canvar.x=Apc %*% s$u, canvar.y=Bpc %*% s$v))
should do the trick. The canonical variates are zero-mean, unit-variance
---end quote---




Kaspar Pflugshaupt
Geobotanisches Institut
Zuerichbergstr. 38
CH-8044 Zuerich

Tel. ++41 1 632 43 19
Fax  ++41 1 632 12 15

mailto:pflugshaupt at geobot.umnw.ethz.ch
privat:pflugshaupt at mails.ch

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list