Re: R-alpha: optimization

Douglas Bates (bates@stat.wisc.edu)
Tue, 3 Sep 96 09:22 CDT


Message-Id: <m0uxwNP-0000ULC@franz.stat.wisc.edu>
Date: Tue, 3 Sep 96 09:22 CDT
From: Douglas Bates <bates@stat.wisc.edu>
To: Jim Lindsey <jlindsey@luc.ac.be>
Subject: Re: R-alpha: optimization
In-Reply-To: <9609020945.AA06445@alpha.luc.ac.be>

>>>>> "Jim" == Jim Lindsey <jlindsey@luc.ac.be> writes:

  Jim> Following Douglas Bates' error in dqrsl.c, I have realized that
  Jim> solve() will not invert a 1x1 matrix but now gives the error,
  Jim> Error: nonpositive extents to matrix.  This can easily be
  Jim> handled by R coding for each case, but it would be nice if it
  Jim> could be corrected in the function itself.

Maybe we could phrase that as "the error in dqrsl.c reported by
Douglas Bates"?  :-)

The problem is that qr.coef drops the array attributes from the
solution when there is only one column.  Perhaps a better course would
be to return a matrix when y is a matrix and to return a vector when y
is a vector.
 > qr.coef
 function (qr, y) 
 {
 ...
	 if (ncol(y) == 1) 
		 dim(coef) <- NULL
	 return(coef)
 }

This is what happens
> solve(diag(2))   # returns a matrix
     [,1] [,2]
[1,]    1    0
[2,]    0    1
> solve(diag(1))   # returns a vector
[1] 1
> as.matrix(solve(diag(1)))  # this is always be a matrix
     [,1]
[1,]    1

Thus you can use as.matrix(solve(my.mat)) if you want a temporary
workaround.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-