[Rd] buglet in weighted.residuals(mlmObject)

William Dunlap wdunlap at tibco.com
Wed Jan 19 23:58:36 CET 2011


When weighted.residuals() is given a fitted model
object with several responses (class mlm) and some
zero weights it returns a vector instead of a matrix.
It looks like it is doing
   resids[ weights != 0 ]
instead of
   resids[ weights != 0, , drop=FALSE] 
in the multi-response case.

E.g.,

> d4 <- data.frame(y1=1:4, y2=2^(0:3), wt=log(1:4),
fac=LETTERS[c(1,1,2,2)])
> fit <- lm(data=d4, cbind(y1,y2)~fac, weights=wt)
> weighted.residuals(fit) # expect 3x2 matrix
[1]  1.407294e-16 -5.847465e-01  5.205496e-01  5.950102e-16
-2.338986e+00
[6]  2.082198e+00
> weighted.residuals(fit, drop0=FALSE)
             y1            y2
1  0.000000e+00  0.000000e+00
2  1.407294e-16  5.950102e-16
3 -5.847465e-01 -2.338986e+00
4  5.205496e-01  2.082198e+00

This is in R 2.12.0.  I haven't upgraded yet.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 



More information about the R-devel mailing list