bug on cancor (PR#116)
Prof Brian D Ripley
Tue, 9 Feb 1999 08:07:57 +0000 (GMT)
On 9 Feb 1999, Peter Dalgaard BSA wrote:
> email@example.com writes:
> > When I use the function cancor of mva package, I found that it doesn't
> > work when one of the matrix has only one column, or both have only
> > one column. The function in Splus 5 with the same name works under those
> > situations.
Yes, it does, but whether this makes statistical sense is debatable:
you are then doing regression in a roundabout way. (Least-squares
regression maximizes the correlation of y with a linear combination of the
cols of X.)
> Just for those who wondered: I resent the message to R-bugs, making it
> appear on R-devel for the 2nd time but with a PR#. (Resending - in my
> mailer at least - leaves the original author as sender, which I think
> is desirable. It also came out with a double R-devel signature, but
> that probably can't be helped).
> This is clearly a bug:
> > cancor(1:10,1:10)
> Error in qr.qty(qx, qr.qy(qy, diag(1, nr, dy)))[1:dx, , drop = FALSE]
> : incorrect number of dimensions
> Probably a dimension getting dropped somewhere...
Nope. As someone who has suffered here before, I saw it is that pesky
mat.or.vec construction that someone in R likes to use. Function
qr.qr returns a vector when given an n x 1 y, by design. So
qr.qy(qy, diag(1, nr, dy))
qr.qty(qx, qr.qy(qy, diag(1, nr, dy)))
are vectors. So this is an R design decision.
To work around this in cancor, use
zz <- qr.qty(qx, qr.qy(qy, diag(1, nr, dy)))
z <- svd(as.matrix(zz)[1:dx, , drop=FALSE], dx, dy)
BTW, the help page for qr.qy says the value is
The QR decomposition of the matrix as computed by LIN-
PACK. The components in the returned value correspond
directly to the values returned by DQRDC.
which is nonsense for 8 of the 9 functions documented on that page.
I was using 0.63.2, in case anything has been altered since.
It may be too late to change this design decision (I know of quite a few
workarounds in other code) but it will come back to haunt users. At least
it could be documented!
Brian D. Ripley, firstname.lastname@example.org
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-devel 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: email@example.com