Skip to content

Scoping problem

3 messages · Kjetil Halvorsen, Thomas Lumley

#
Hola!

I have the following simple function:
function(pow){
           ob <- glm(Pound~CG+Age+Vage,data=car,weights=No,
                     subset=No>0,family=quasi(link=power(pow),var=mu^2))

           deviance(ob)
}
But trying to run it gives:
Error in power(pow) : Object "pow" not found

I have tried to use debug on testcar, but what I can find out is only
that pow
is invisible from within glm. Is there a way to find in which
environment
pow belongs, so as to get at it with "get" inside power?

Kjetil Halvorsen


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 5 Jul 2000, halvorsen wrote:

            
'pow' isn't found because quasi() is looking for it in a strange place.  
Normally you would expect this sort of syntax to work, but the family
functions do some tricky things to allow you to specify things with or
without quotes and without or without parentheses.

I suspect this might count as a bug.

In any case, you can fix it by doing
eval(substitute(glm(Pound~CG+Age+Vage,data=car,weights=No subset=No>0, 
family=quasi(link=power(pow),var=mu^2))))

You could also use power(get(pow,env=parent.frame(2))), but that is more
complicated and more likely to break if something changes.


	-thomas

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 5 Jul 2000, Thomas Lumley wrote:

            
As an additional note. This probably won't work if the argument to testcar
is a variable.

A more reliable version is 
 eval(substitute(glm(Pound~CG+Age+Vage,data=car,weights=No subset=No>0, 
 family=quasi(link=power(pow),var=mu^2)),list(pow=pow)))


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._