[R] anova.lme error

From: Nisha Mulakken <mulakken1_at_llnl.gov>
Date: Wed 15 Jun 2005 - 10:14:35 EST


Hi,

I am working with R version 2.1.0, and I seem to have run into what looks like a bug. I get the same error message 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. It appears to not find the right environment when called from inside 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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jun 15 10:18:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:38 EST