From berwin at maths.uwa.edu.au  Wed May 26 11:44:27 2004
From: berwin at maths.uwa.edu.au (Berwin A Turlach)
Date: Wed May 26 11:44:37 2004
Subject: [Rd] Bug in update()? (PR#6902)
In-Reply-To: <Pine.LNX.4.44.0405242018170.31253-100000@gannet.stats>
References: <20040521072200.A1F9C1058F@slim.kubism.ku.dk>
	<Pine.LNX.4.44.0405242018170.31253-100000@gannet.stats>
Message-ID: <16564.26363.769976.68479@bossiaea.maths.uwa.edu.au>

Dear Brian,

>>>>> "BDR" == Prof Brian Ripley <ripley@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?


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