[Rd] Possible bug in termplot function (stats package) ?

Thomas Lumley tlumley at uw.edu
Mon Jun 6 22:16:21 CEST 2011

On Tue, Jun 7, 2011 at 7:30 AM, Joris Meys <jorismeys at gmail.com> wrote:
> On Mon, Jun 6, 2011 at 9:15 PM, peter dalgaard <pdalgd at gmail.com> wrote:
>> I'd say that the burden of proof is really on your side, but how hard can it be:
>>> x <- 1:10
>>> y <- rnorm(10)
>>> m <- lm(y~x)
>>> m$call
>> lm(formula = y ~ x)
>>> m$call$data
> I see... indeed, thx for the answer and sorry for my stupidity. Should
> have thought about that case. Still, I wonder why it is necessary to
> go look for the data in a calling environment if it should be
> contained in the model frame of the fitted object. Or am I again wrong
> in assuming that's always the case?

You are again wrong.   Life would be much simpler if the data were
always available like that, but there are at least two problems.

1) There need not be a model frame in the fitted object. (it's optional)

2) More importantly, if you have y~sin(x), the model frame will
contain sin(x), not x. For what termplot() does, it has to be able to
reconstruct 'x', which isn't possible without the original data.

It's quite possible that termplot() could be rewritten to be simpler
and more general, but I don't think minor editing will do it.


Thomas Lumley
Professor of Biostatistics
University of Auckland

More information about the R-devel mailing list