[S] model.frame()

Adrian Baddeley (adrian@maths.uwa.edu.au)
Tue, 3 Nov 1998 19:06:45 +0800


Forgive me if this is a FAQ:
try <- function(fmla, data, wt) {
lm(fmla, data = data, weights = wt)
}
looks for the object 'wt' in the frame that called try(),
rather than using the 'wt' argument in the function.
(transcript below.)

Is this really the intention?

The same behaviour occurs with glm() and gam() instead of lm(),
and if 'wt' is an object computed inside the function
rather than being an argument of the function.

The frame-searching seems to happen in model.frame() which is
called by lm(), glm() and gam().

Help please!!

What is the recommended workaround?
I have been using
assign(".wt", wt, sys.parent())

tia
----
Adrian Baddeley, Mathematics & Statistics, University of Western Australia
<http://maths.uwa.edu.au/~adrian/>
------------------------------------------------------------------------

S-PLUS Version 3.4 Release 1 for Silicon Graphics Iris, IRIX 5.3 : 1996
> xx <- seq(0,1,by=0.01)
> yy <- xx + rnorm(101)
> dd <- data.frame(x=xx,y=yy)
> try<- function(fmla, data, wt) { lm(fmla, data = data, weights = wt) }
> ww <- rep(1,length(xx))
> rm(wt)
> try(y ~ x, dd, ww)
Error in try(y ~ x, dd, ww): Object "wt" not found
> wt <- 1:37
> try(y ~ x, dd, ww)
Error in try(y ~ x, dd, ww):
Length of variable 3 is 37 != length of row names (101)
> wt <- ww
> try(y ~ x, dd, NULL)
Call:
lm(formula = fmla, data = data, weights = wt)

Coefficients:
(Intercept) x
-0.1108736 1.391442

(..etc..)


-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news