Skip to content

bug on cancor (PR#116)

4 messages · Kenny Ye, Peter Dalgaard, Brian Ripley +1 more

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

The version of R I am using is 0.63.2 (released on Jan., 1999) on Solaris.

Kenny Ye
Assistant Professor
Department of Applied Math and Statistics
SUNY at  Stony Brook
Stony Brook, New York 11794-3600
(516)632 9344


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
kye@ams.sunysb.edu writes:
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:
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...
#
On 9 Feb 1999, Peter Dalgaard BSA wrote:

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

Value:

     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!
#
In the ``release-patch'' aka 0.63.3  version, the  functions
qr.xxx  *have* changed about 10 days ago.

NEWS has

    o	backsolve(), qr.solve... now return a vector when x (or y) is a vector.


In today's snapshot,

  > library(mva)
  > str(cancor(1:9,c(1:4,6:10)))
  List of 5
   $ cor    : num 0.997
   $ xcoef  : num 0.129
   $ ycoef  : num 0.110
   $ xcenter: num 5
   $ ycenter: num 5.56

However, 
I'm not sure if this addresses all issues (apart from docu)
that Prof Ripley has addressed. 

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._