R-beta: lsfit error in R 0.16.1

Stephen Shiboski steve at chanane.ucsf.edu
Sun Apr 6 19:50:28 CEST 1997


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 at 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 at stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



More information about the R-help mailing list