Looks for data in global environment
stanstrup opened this issue · 0 comments
stanstrup commented
This works:
mod <- glm(cbind(y, n-y) ~ ldose, data = beetle,
family = binomial(link = "cloglog"))
invest(mod, y0 = 0.5)
While this does not:
test_fun <- function(){
dat <- beetle
glm(cbind(y, n-y) ~ ldose, data = dat,
family = binomial(link = "cloglog"))
}
mod <- test_fun()
invest(mod, y0 = 0.5)
It fails with:
Error in eval(object$call$data, envir = parent.frame()) :
object 'dat' not found
It seems like it is looking in the global env for the object that was used to generate the model.
This is problematic if you generate the model in functions or create the model on subset data that you don't keep around.
Instead I believe it should use mod$data
if it needs to original data.