[Rd] weights in lm, glm (PR#9023)
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Jun 23 01:02:53 CEST 2006
Thomas Lumley <tlumley at u.washington.edu> 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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-devel
mailing list