[Rd] Inaccurate documentation for qr.R and qr.Q (PR#8347)

2005-11-22 Thread sims
This is a multi-part message in MIME format.
--060805080907030400090708
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

The documentation in QR.Auxiliaries {base} states

|qr.Q| returns part or all of *Q*, the order-nrow(X) orthogonal 
(unitary) transformation represented by |qr|. If |complete| is |TRUE|, 
*Q* has |nrow(X)| columns. If |complete| is |FALSE|, *Q* has |ncol(X)| 
columns. When |Dvec| is specified, each column of *Q* is multiplied by 
the corresponding value in |Dvec|.
|qr.R| returns *R*, the upper triangular matrix such that |X == Q %*% R|.

This last statement is true if there has been no pivoting, but if the 
LAPACK=TRUE option is turned on or the x matrix is complex, there is 
likely to be pivoting, and in that case Q %*% R is X with columns 
reordered by the pivot.  qr.X does return the original x matrix in 
either case, but a naive user who uses R alone (e.g. thinking that 
solve(R,crossprod(Q ,y)) will give ols estimates) could be misled.

Example:

 > x <- matrix(c(1,2,3,3,6,8),ncol=2)
 > qrlin <- qr(x)
 > qrla <- qr(x,LAPACK=TRUE)
 > qr.Q(qrlin) %*% qr.R(qrlin)
 [,1] [,2]
[1,]13
[2,]26
[3,]38
 > qr.Q(qrla) %*% qr.R(qrla)
 [,1] [,2]
[1,]31
[2,]62
[3,]83
 > qr.Q(qrla) %*% qr.R(qrla)[,qrla$pivot]
 [,1] [,2]
[1,]13
[2,]26
[3,]38

--060805080907030400090708
Content-Type: text/x-vcard; charset=utf-8;
 name="sims.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="sims.vcf"

begin:vcard
fn:Chris Sims
n:Sims;Chris
org:Princeton University;Department of Economics
adr:;;Fisher Hall;Princeton;NJ;08544-1021;USA
email;internet:[EMAIL PROTECTED]
tel;work:609 258 4033
tel;fax:609 258 6419
x-mozilla-html:FALSE
url:http://www.princeton.edu/~sims
version:2.1
end:vcard


--060805080907030400090708--

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] bug in qr.coef() and (therefore) in qr.solve (PR#8476)

2006-01-11 Thread sims
(rnorm(36),12,3)
> y <- matrix(rnorm(24),12,2)
> b <- qr.coef(qr(X),y)
> qr.coef(qr(X,LAPACK=TRUE),y)-b
  [,1]  [,2]
[1,] -5.551115e-17 0.2509164
[2,]  1.110223e-16 0.1846802
[3,]  0.00e+00 1.0224349
> qr.coef(qr(X+0i),y)-b
 [,1] [,2]
[1,] -5.551115e-17+0i 0.2509164+0i
[2,]  1.110223e-16+0i 0.1846802+0i
[3,]  0.00e+00+0i 1.0224349+0i
> qr.coeffCS(qr(X+0i),y)-b
 [,1][,2]
[1,] -5.551115e-17+0i 2.775558e-17+0i
[2,]  1.110223e-16+0i 1.110223e-16+0i
[3,]  0.00e+00+0i 5.551115e-17+0i


--050206000203080003040803
Content-Type: text/x-vcard; charset=utf-8;
 name="sims.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="sims.vcf"

begin:vcard
fn:Chris Sims
n:Sims;Chris
org:Princeton University;Department of Economics
adr:;;Fisher Hall;Princeton;NJ;08544-1021;USA
email;internet:[EMAIL PROTECTED]
tel;work:609 258 4033
tel;fax:609 258 6419
x-mozilla-html:FALSE
url:http://www.princeton.edu/~sims
version:2.1
end:vcard


--050206000203080003040803--

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] follow-up on qr.coef bug (PR#8478)

2006-01-12 Thread sims
This is a multi-part message in MIME format.
--090308090600080800090200
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

The bug I submitted yesterday (It's not entered in the bug data base, so 
I have no ID for it) included a suggested fix that
is not correct.  It worked for the examples I gave because there was no 
pivoting in fact, or only pivot permutations that were
idempotent.   A correction that works in general on the examples I gave 
makes these two changes in qr.coef():

## coef[qr$pivot, ] <- .Call("qr_coef_cmplx", qr, y, PACKAGE = 
"base")[1:p]
coef[qr$pivot,] <- .Call("qr_coef_cmplx", qr, y, PACKAGE = 
"base")[1:p,]

##coef[qr$pivot,] <- .Call("qr_coef_real", qr, y, PACKAGE = 
"base")[1:p]
coef[qr$pivot,] <- .Call("qr_coef_real", qr, y, PACKAGE = 
"base")[1:p,]

I'm not sure why the [1:p,] on the right is needed.  For my examples, it 
works without this extraction operation, but maybe there is some case in 
which the output of qr_coef_real or qr_coef_cmplx could have more than p 
rows.



--090308090600080800090200
Content-Type: text/x-vcard; charset=utf-8;
 name="sims.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="sims.vcf"

begin:vcard
fn:Chris Sims
n:Sims;Chris
org:Princeton University;Department of Economics
adr:;;Fisher Hall;Princeton;NJ;08544-1021;USA
email;internet:[EMAIL PROTECTED]
tel;work:609 258 4033
tel;fax:609 258 6419
x-mozilla-html:FALSE
url:http://www.princeton.edu/~sims
version:2.1
end:vcard


--090308090600080800090200--

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel