[R] anova.gls from nlme on multiple arguments within a function fails
Spencer Graves
spencer.graves at pdf.com
Sun Nov 27 23:44:43 CET 2005
You've posed an excellent question with simple and elegant,
reproducible example. I've seen no replies, so I will attempt a partial
response. RSiteSearch("lexical scoping") produced some potentially
useful comments (e.g.,
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/37769.html), but nothing
that allowed me to work around the problem.
The following modification of your example makes it clear that
"anova.lme" (called by "anova.gls") choked on the second argument not
the first:
> dummy2 <- function(obj)
+ {
+ obj2 <- obj[[2]]
+ anova(obj[[1]], obj2)
+ }
> dummy2(list(fm1, fm2))
Error in anova.lme(object = obj[[1]], obj2) :
object "obj2" not found
The following helped isolate this further to "dots <- list(...)", the
second line in "anova.lme":
debug(anova.lme)
dummy2(list(fm1, fm2))
I don't know why your example fails, especially "anova.lm" worked.
Also, there should be a way to use something like "assign" to work
around this problem, but nothing I tried worked.
I know this is not a complete reply, but I hope it helps.
spencer graves
Markus Jantti wrote:
> Dear All --
>
> I am trying to use within a little table producing code an anova
> comparison of two gls fitted objects, contained in a list of such
> object, obtained using nlme function gls.
> The anova procedure fails to locate the second of the objects.
>
> The following code, borrowed from the help page of anova.gls,
> exemplifies:
> --------------- start example code ---------------
> library(nlme)
>
> ## stolen from example(anova.gls)
> # AR(1) errors within each Mare
> fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary,
> correlation = corAR1(form = ~ 1 | Mare))
> anova(fm1)
> # variance changes with a power of the absolute fitted values?
> fm2 <- update(fm1, weights = varPower())
> anova(fm1, fm2)
>
> ## now define a little function
> dummy <- function(obj)
> {
> anova(obj[[1]], obj[[2]])
> }
> dummy(list(fm1, fm2))
>
> ## compare with what happens in anova.lm:
>
> lm1 <- lm(follicles ~ sin(2*pi*Time), Ovary)
> lm2 <- lm(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary)
> dummy(list(lm1, lm2))
> ------------- end example code ------------------
>
> It is not the end of the world: I can easily work around this.
> But it would be nice to know why this does not work.
>
> Digging around using options(error=recover) did not help my much, I'm
> afraid.
>
> Best,
>
> Markus
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
More information about the R-help
mailing list