Thomas Lumley <[EMAIL PROTECTED]> writes:

> The other approach is to set the environment of the formula to be the 
> current environment. This will work as long as the formula doesn't refer 
> to any variables in its original environment
> 
>     environment(model)<-environment()
>     w<-runif(nrow(data))
>     lm(model,data=data, weights=w)

The cleanest way I can think of is

e <- new.env(parent=environment(model))
assign(".weight.", whatever, envir=e)
environment(model) <- e
lm(model, data=data, weights=.weight.)

(You could assign directly into environment(model), but that might
have side effects. Use a "strange" name so as not to clash with
variables in "data", or in environment(model))

-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])                  FAX: (+45) 35327907

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to