Re: [R] qr and Moore-Penrose

Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
30 Jun 1999 13:35:13 +0200

To: Torsten Hothorn <hothorn@amadeus.statistik.uni-dortmund.de>
Subject: Re: [R] qr and Moore-Penrose
From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
Date: 30 Jun 1999 13:35:13 +0200
In-Reply-To: Torsten Hothorn's message of "Wed, 30 Jun 1999 11:12:24 +0200 (MET DST)"

Torsten Hothorn <hothorn@amadeus.statistik.uni-dortmund.de> writes:

> yesterday I had a little shock using qr (or lm). having a matrix
>
> X <- cbind(1,diag(3))
> y <- 1:3
>
> the qr.coef returns one NA (because X is singular). So I computed the
> Moore-Penrose inverse of X (just from the definition) and I get a correct
> result. Whats wrong about qr in this situation?

Ummm, what exactly do you perceive as a problem here?

> X <- cbind(1, diag(3)); # singular matrix
> y <- 1:3
> Xp <- qr(X);
> b1 <- qr.coef(Xp, y); # contains NA
> b2 <- mpinv(X)%*%y # least square fit using Moore-Penrose
> X%*%b2 # == y

...and so is X[,-4] %*% b1[-4] (or, equivalently, X%*%b1 if you
replace the NA with a 0).

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


This archive was generated by hypermail 1.02.