[Rd] Bug in update()? (PR#6902)

Berwin A Turlach berwin at maths.uwa.edu.au
Wed May 26 11:44:27 CEST 2004


Dear Brian,

>>>>> "BDR" == Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

    BDR> The problem is not in update but in glm itself: take a look
    BDR> at fm$formula after the first fit.  fm$terms has the right
    BDR> formula, but formula() extracts the $formula component first.
O.k., I see what you mean.

    BDR> I am not currently sure what the right fix is, so will not
    BDR> try to fix this in R-patched/1.9.1.
This may be naive, but I noticed the following at the end of the glm
function (starting line 76, in src/library/stats/R/glm.R):

    fit <- c(fit, list(call = call, formula = formula,
		       terms = mt, data = data,
		       offset = offset, control = control, method = method,
		       contrasts = attr(X, "contrasts"),
                       xlevels = .getXlevels(mt, mf)))

That is, the component "formula" in the object that is returned is
explicitly set to the "formula" argument with which glm was called.
The function "lm" does not do this.  And if I change this `line' to

    fit <- c(fit, list(call = call, 
		       terms = mt, data = data,
		       offset = offset, control = control, method = method,
		       contrasts = attr(X, "contrasts"),
                       xlevels = .getXlevels(mt, mf)))

then fm$formula for the first fit in my example looks o.k.  

But I don't know if this will break anything else.

Cheers,

        Berwin

PS:  I noticed that both `glm' and 'lm' now do essentially the
following manipulations early on:

    mf <- match.call(expand.dots = FALSE)
    m <- match(c("formula", "data", "subset", "weights", "na.action", 
        "offset"), names(mf), 0)
    mf <- mf[c(1, m)]
    mf$drop.unused.levels <- TRUE
    mf[[1]] <- as.name("model.frame")
    mf <- eval(mf, parent.frame())

Is this the preferred idiom to be used in R 1.9.x and later for
modelling functions?



More information about the R-devel mailing list