[R] qr decomposition issue inside lm

Horace Tso Horace.Tso at pgn.com
Tue Mar 6 22:45:28 CET 2007


Dear list,

It's never happened to me before in such a simple exercise but is not going away and I've checked my data are good. I want a simple lm model with one response and one predictor, where N is about 4,200 * data set not exactly small. Both x and y are nice, continuous variables having NA filtered out with a call to na.omit. So I did

mod = lm( y ~ x, data=x1)

Then the error,

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
        NA/NaN/Inf in foreign function call (arg 4)

I did a trace back and it turned out it's an error thrown by the Fortran subroutine that seems to be trying a QR decomposition,

traceback()
3: .Fortran("dqrls", qr = x, n = n, p = p, y = y, ny = ny, tol = as.double(tol), 
       coefficients = mat.or.vec(p, ny), residuals = y, effects = y, 
       rank = integer(1), pivot = 1:p, qraux = double(p), work = double(2 * 
           p), PACKAGE = "base")
2: lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
1: lm(log.p.sales ~ log.mktcap, data = x1)

My question is why would QR fail since the default in lm.fit is 'singular.ok' ? Furthermore, is there a way to get around presumably a singularity in my design matrix? 

Thanks in advance.

Horace W. Tso



More information about the R-help mailing list