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

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed May 26 12:46:17 CEST 2004


On Wed, 26 May 2004, Berwin A Turlach wrote:

> 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.  

You won't have a formula component at all (lm objects do not).
What I have done is alter the formula methods to pick up the formula from 
the terms component but the environment from the formula componet (if 
present).

> 
> 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?

Rather than removing components, by setting to NULL, yes.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list