From owner-r-help@stat.math.ethz.ch Thu Feb 24 12:52:00 2000 Return-Path: Received: from stat.math.ethz.ch (majordom@hypatia.ethz.ch [129.132.58.23]) by t2.mscf.uky.edu (8.9.3/8.8.7) with ESMTP id MAA08449 for ; Thu, 24 Feb 2000 12:51:59 -0500 Received: by stat.math.ethz.ch (8.9.1/8.9.1) id SAA17902 for r-help-gang-use; Thu, 24 Feb 2000 18:28:32 +0100 (MET) Received: (from daemon@localhost) by stat.math.ethz.ch (8.9.1/8.9.1) id SAA17896 for ; Thu, 24 Feb 2000 18:28:29 +0100 (MET) Received: from toucan.stats.ox.ac.uk(163.1.20.20) via SMTP by hypatia, id smtpdAAAa004NV; Thu Feb 24 18:28:25 2000 Received: from toucan.stats (toucan.stats [163.1.20.20]) by toucan.stats.ox.ac.uk (8.9.0/8.9.0) with SMTP id RAA01662; Thu, 24 Feb 2000 17:28:23 GMT Message-Id: <200002241728.RAA01662@toucan.stats.ox.ac.uk> Date: Thu, 24 Feb 2000 17:28:23 +0000 (GMT) From: Prof Brian Ripley Reply-To: Prof Brian Ripley Subject: Re: [R] canonical variates To: r-help@stat.math.ethz.ch, mac@foodsci.unibo.it MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii Content-MD5: 06CrzrhnYa575rg5B485Sg== X-Mailer: dtmail 1.2.1 CDE Version 1.2.1 SunOS 5.6 sun4m sparc Sender: owner-r-help@stat.math.ethz.ch Precedence: bulk Status: OR > Date: Thu, 24 Feb 2000 16:46:59 +0100 (MET) > From: Mauro Andrea Cremonini > > 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@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@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._