Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with local variables and gbm formula interface #82

Open
patr1ckm opened this issue May 6, 2016 · 1 comment
Open

problem with local variables and gbm formula interface #82

patr1ckm opened this issue May 6, 2016 · 1 comment

Comments

@patr1ckm
Copy link

patr1ckm commented May 6, 2016

I ran into the following problem where gbm does not find a predictor in the local environment:

do.gbm <- function(y,x){
  require(gbm)
  l <- x
  o <- gbm(y~l)
}

x <- rnorm(100)
y <- x^2
do.gbm(y,x)

Produces

 Error in eval(expr, envir, enclos) : object 'l' not found 

It occurs at the following line (456), which looks for the variables within data rather than parent.frame():

   x <- model.frame(terms(reformulate(var.names)),
                    data,
                    na.action=na.pass,
                    subset=subset)

A proposed solution could be to just select the predictors from mf using var.names computed the line before. mf should have all variables either in data or parent.frame. I've not tested this extensively.

x <- mf[,var.names,drop=F]
@pdmetcalfe
Copy link
Member

Yes. It also has problems with gbm((fred > 0) ~ ., data=stuff). Fixing this is (in my head) kind of tied in with refactoring the R code to remove all the if else from gbm, gbm.fit, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants