R-beta: lsfit error in R 0.16.1

Stephen Shiboski (steve@chanane.ucsf.edu)
Sun, 6 Apr 97 10:50:28 -0700

```Date: Sun, 6 Apr 97 10:50:28 -0700
From: Stephen Shiboski <steve@chanane.ucsf.edu>
Message-Id: <9704061750.AA12763@chanane.ucsf.edu>
To: r-testers@stat.math.ethz.ch
Subject: R-beta: lsfit error in R 0.16.1

In playing around with an IRLS operation I noticed that
calling lsfit with a weight vector containing no zeros leads to
the following error:

> lsfit(rnorm(100),rnorm(100),abs(rnorm(100)))
Error in xzero %*% z\$coefficients : non-conformable arguments

By contrast, if there are some zero weights, no errors are generated:

> lsfit(rnorm(100),rnorm(100),round(abs(rnorm(100)),0))\$coef
Intercept          X
-0.1007470  0.1072742

The problem is with the following part of the function:

if (!is.null(wt)) {
if (ncx == 1)
fitted.zeros <- xzero * z\$coefficients
else fitted.zeros <- xzero %*% z\$coefficients
z\$residuals[wt == 0, ] <- yzero - fitted.zeros
z\$residuals <- z\$residuals * invmult
}

This only works if NROW(xzero) >= 1, where xzero is defined as
xzero <- as.matrix(x)[wt == 0, ] .

An easy workaround is to use

if (!is.null(wt)) {
if (NROW(xzero) >= 1) {
if (ncx == 1)
fitted.zeros <- xzero * z\$coefficients
else fitted.zeros <- xzero %*% z\$coefficients
z\$residuals[wt == 0, ] <- yzero - fitted.zeros
}
z\$residuals <- z\$residuals * invmult
}

--
Stephen Shiboski  <steve@biostat.ucsf.edu>
Division of Biostatistics
University of California, San Francisco
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
```