Skip to content

Using varPower in gnls, an answer of sorts.

2 messages · Setzer.Woodrow@epamail.epa.gov, Brian Ripley

#
Back on January 16, a message on R-help from Ravi Varadhan described a
problem with gnls using weights=varPower().  The problem was that the
fit failed with error

Error in eval(expr, envir, enclos) : Object "." not found

I can reliably get this error in version 2.0.1-patched 2004-12-09 on
Windows XP and 2.0.1-Patched 2005-01-26 on Linux.

The key feature of that example is that the data are being passed in the
environment.  Consider a modification of the example in the man page for
gnls:

First, something that should work:
+ start=c(Asym=16,xmid=50,scal=7),weights=varPower())
Generalized nonlinear least squares fit
  Model: weight ~ Asym/(1 + exp((xmid - Time)/scal))
  Data: Soybean
  Log-likelihood: -486.8973

Coefficients:
    Asym     xmid     scal
17.35681 51.87230  7.62052

Variance function:
 Structure: Power of variance covariate
 Formula: ~fitted(.)
 Parameter estimates:
    power
0.8815438
Degrees of freedom: 412 total; 409 residual
Residual standard error: 0.3662752

## Now, use with() to pass Soybean in the environment of gnls:
+ start=c(Asym=16,xmid=50,scal=7),weights=varPower()))

Error in eval(expr, envir, enclos) : Object "." not found

## drop the weights argument from gnls, and the error message goes away.

The problem is in a call to model.frame.  When varPower() (and
presumably other weight functions using '.' to represent a fitted model)
is used, gnls() constructs a formula argument for model.matrix that
looks like:
~.+weight+Time
This works when the data are passed in a data frame, but not when they
are in the environment.  Look at the example in the man page for
model.frame
[1] "data.frame"
Error in eval(expr, envir, enclos) : Object "." not found
[1] "data.frame"
[1] "data.frame"
Error in eval(expr, envir, enclos) : Object "." not found

I'm sending this to r-help rather to the authors of nlme because I am
not sure where the bug is: is model.frame misbehaving, or should gnls
not include '.' in its call to model.frame?

R. Woodrow Setzer, Jr.                        Phone: (919) 541-0128
Experimental Toxicology Division             Fax:  (919) 541-4284
Pharmacokinetics Branch
NHEERL B143-01; US EPA; RTP, NC 27711
#
On Wed, 2 Mar 2005 Setzer.Woodrow at epamail.epa.gov wrote:

            
[...]
'.' is only defined in a formula for model.frame() when there is a 'data' 
argument (otherwise what do you think it might mean?).  So this is not a 
problem in model.frame(), hence on your analysis in gnls() or the usage of 
it.