Re: R-alpha: optimization

Douglas Bates (
Tue, 3 Sep 96 09:22 CDT

Message-Id: <>
Date: Tue, 3 Sep 96 09:22 CDT
From: Douglas Bates <>
To: Jim Lindsey <>
Subject: Re: R-alpha: optimization
In-Reply-To: <>

>>>>> "Jim" == Jim Lindsey <> 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

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

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

r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: