From mulakken1 at llnl.gov  Tue Jun 14 21:01:45 2005
From: mulakken1 at llnl.gov (mulakken1@llnl.gov)
Date: Tue, 14 Jun 2005 21:01:45 +0200 (CEST)
Subject: [Rd] wrong environment in anova call inside function (PR#7937)
Message-ID: <20050614190145.14BD5A223@slim.kubism.ku.dk>

Hi,

I am working with R version 2.1.0, and I seem to have run into a bug. I get 
the same bug when I run R on Windows as well as when I run it on Linux.

When I call anova to do a LR test from inside a function, I get an error. 
The same call works outside of a function. I have provided the code below.

Thanks,
Nisha Mulakken

############################

myFunction <- function(myDataFrame) {

  # Less restricted
  fit1 <- gls(y ~ dose,
              weights=varIdent(form=~1|dose),
              data=myDataFrame)

  # more restricted
  fit2 <- gls(y ~ dose,
              data=myDataFrame)

  anova.results <- anova(fit1, fit2)
  anova.results
}

df <- data.frame( y=c(12,3,45,1,53,6),
                   dose=c(0,10,200,0,10,200),
                   time=c("4.00 hrs", "4.00 hrs", "6.00 hrs", "6.00 hrs", 
"8.00 hrs", "8.00 hrs"),
                   time.hours=c(4, 4, 6, 6, 8, 8),
                   rep=rep("a", 6)
                 )

## This leads to the following error:
##     Error in anova.lme(object = fit1, fit2) : Object "fit2" not found
results <- myFunction(myDataFrame=df)

#####################################################
## The same thing outside of a function

# Less restricted
fit3 <- gls(y ~ dose,
              weights=varIdent(form=~1|dose),
              data=df)

# more restricted
fit4 <- gls(y ~ dose,
             data=df)

## This works:
anova(fit3, fit4)

## The results:
## > anova(fit3, fit4)
##     Model df      AIC      BIC    logLik   Test L.Ratio p-value
## fit3     1  5 57.98998 54.92145 -23.99499
## fit4     2  3 55.75284 53.91172 -24.87642 1 vs 2 1.76286  0.4142



[Rd] wrong environment in anova call inside function (PR#7937)
mulakken1@llnl.gov