[Rd] lm.fit peak memory usage

Laurens Leerink Laurens.Leerink@tudor.com
Fri Jan 3 22:22:03 2003


Hi,

I've been running out of memory while using the lm.fit function - have
solved the problem and thought there might be interest in incorporating some
of the changes.  Looked at the source and changed the following lines

    storage.mode(x) <- "double"
    storage.mode(y) <- "double"
    z <- .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")

to

    if (storage.mode(x) != "double")
        storage.mode(x) <- "double"
    if (storage.mode(y) != "double")
        storage.mode(y) <- "double"
    z <- .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", DUP=F)

and I'm now able to call the function with data that is more than 4x larger
than before.  Have read the manuals and am aware of the dangers of DUP=F,
but thought that if there was ever a fortran function that has been well
debugged this is a likely candidate.  Will leave that up to the judgment of
those of you who actually know how it works.

The tests for storage.mode are probably less controversial, and actually
make a big difference in peak memory usage when the matrices are large.

Regards,
Laurens Leerink