[R] model.frame.default problem in function definition

Darryl Greig darryl at hpli.hpl.hp.com
Mon Mar 3 10:51:04 CET 2003


Thanks, the new stepAIC does the job.

-----Original Message-----
From: r-help-admin at stat.math.ethz.ch
[mailto:r-help-admin at stat.math.ethz.ch]On Behalf Of
ripley at stats.ox.ac.uk
Sent: Sunday, March 02, 2003 6:14 PM
To: Darryl Greig
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] model.frame.default problem in function definition


This works in R-devel, for which NEWS says

    o   step(), add1.default() and drop1.default() now work somewhat
        better if called from a function.

It's mainly a scoping problem, related to changes made way back in 1.2.x.

However, it is also an bad example, as z is really excluded in the fit.
stepAIC in the latest MASS (VR_7.0-11) will work, but warns about this.
I hope that this is just an over-simplification of the real problem.

On Sun, 2 Mar 2003, Darryl Greig wrote:

> Could someone point me in the right direction for the following issue:
> 
> A function is defined as follows:
> 
> 	tfun <- function(dat)
> 	  {
> 	    fmla <- as.formula("y~x+z")
> 	    dat2 <- dat
> 	    mdl <- lm(fmla,dat2)
> 	    mdl <- step(mdl)
> 	  }
> 
> Then the following code
> 
> 	dat <- data.frame(x=1:10,z=1:10,y=(1:10)^2+10*(1:10))
> 	tfun(dat)
> 
> generates the output
> 
> 	Start:  AIC= 43.67
> 	 y ~ x + z
> 
> 	Error in model.frame.default(formula = y ~ z, data = dat2,
> drop.unused.levels = TRUE) :
> 		Object "dat2" not found
> 
> Any help or pointers gratefully accepted.
> 
> Thanks,
> Darryl Greig (darryl at hpli.hpl.hp.com)
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list