[Rd] wrong environment in anova call inside function (PR#7937)
mulakken1@llnl.gov
mulakken1 at llnl.gov
Tue Jun 14 21:01:45 CEST 2005
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
More information about the R-devel
mailing list