From p.dalgaard at biostat.ku.dk  Fri Jun 23 01:02:53 2006
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 23 Jun 2006 01:02:53 +0200
Subject: [Rd] weights in lm, glm (PR#9023)
In-Reply-To: <Pine.LNX.4.64.0606221443320.31244@homer23.u.washington.edu>
References: <20060622193830.B53FF19A72@slim.kubism.ku.dk>
	<Pine.LNX.4.64.0606221443320.31244@homer23.u.washington.edu>
Message-ID: <x21wtgiyjm.fsf@turmalin.kubism.ku.dk>

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



[Rd] weights in lm, glm (PR#9023)
Peter Dalgaard