[R] canonical variates

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Feb 24 18:28:23 CET 2000


> Date: Thu, 24 Feb 2000 16:46:59 +0100 (MET)
> From: Mauro Andrea Cremonini <mac at foodsci.unibo.it>
> 
> Dear all, I am a new R user so forgive my perhaps naive question.
> 
> I am looking for a R canonical variates routine, which as far as I
> understand it is not contained in the mva multivariate package.
> Anybody has already written this routine? And where can I find it?

Not that I know of, but it is fairly simple. 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
(unlike S-PLUS).

I have only done some simple checks, but this seems to agree with
S-PLUS up to the different normalizations.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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