[R] Function environments lm() weights

From: Tobias Muhlhofer <t.muhlhofer_at_lse.ac.uk>
Date: Fri 27 May 2005 - 21:38:00 EST


I am writing a function of weighted regression, as a procedure for heteroskedasticity.

The function runs an auxiliary regression whose fitted values I assign to fit, and then I go:

     w <- 1/(exp(fit/2))

     ## Rerun the old regression ##
     if(gls) {
       wtd.model <- glm(model, weights=w)

}
if(!gls) { wtd.model <- lm(model, weights=w, x=TRUE)
}

In this version, R complains that it can't find w. How can I tell it to look for w in the function's environment, rather than in environment 1 or whatever?

An easy workaround, of course, is to superassign w and remove it afterwards, but that's a little messy, in case the user already has a variable called w in his environment.

Thanks,

        Tobias Muhlhofer



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri May 27 21:46:52 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:08 EST