From tlumley at uw.edu  Mon Jun  6 22:16:21 2011
From: tlumley at uw.edu (Thomas Lumley)
Date: Tue, 7 Jun 2011 08:16:21 +1200
Subject: [Rd] Possible bug in termplot function (stats package) ?
In-Reply-To: <BANLkTi=3HyRwGXTEp2mTv=kZS-oy64ctTw@mail.gmail.com>
References: <BANLkTikkDxdR_1+TJNX5LMkr23spvOJ4+A@mail.gmail.com>
	<9B2E15B5-AE4F-4849-96D5-A5DE8896DC80@gmail.com>
	<BANLkTi=uHfZ62TSfLa-a+E-n9RU47_vS5A@mail.gmail.com>
	<94E402C0-10C7-4770-9AB0-B1E33A1779E1@gmail.com>
	<BANLkTi=3HyRwGXTEp2mTv=kZS-oy64ctTw@mail.gmail.com>
Message-ID: <BANLkTin_-qZ8nmC2GCmKPa-HFC0XAd4Xuw@mail.gmail.com>

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

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland



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