Ben Bond-Lamberty
2010-Oct-04 12:37 UTC
[R] Force evaluation of variable when calling partialPlot
Dear R Users, I'm using the randomForest package and would like to generate partial dependence plots, one after another, for a variety of variables: m <- randomForest( s, ... ) varnames <- c( "var1", "var2", "var3", "var4" ) # var1..4 are all in data frame s for( v in varnames ) { partialPlot( x=m, pred.data=s, x.var=v ) } ...but this doesn't work, with partialPlot complaining that it can't find the variable "v". I think I need to force the evaluation of the loop variable v so that partialPlot sees the correct variable names, but am stumped after trying eval and similar functions. Any suggestions on how to do this? Googling has not turned up anything very useful. Thanks, Ben
Liaw, Andy
2010-Oct-04 12:55 UTC
[R] Force evaluation of variable when calling partialPlot
The plot titles aren't pretty, but the following works for me: R> library(randomForest) randomForest 4.5-37 Type rfNews() to see new features/changes/bug fixes. R> set.seed(1004) R> iris.rf <- randomForest(iris[-5], iris[[5]], ntree=1001) R> par(mfrow=c(2,2)) R> for (i in 1:4) partialPlot(iris.rf, iris, names(iris)[i]) Andy From: Ben Bond-Lamberty> > Dear R Users, > > I'm using the randomForest package and would like to generate partial > dependence plots, one after another, for a variety of variables: > > m <- randomForest( s, ... ) > varnames <- c( "var1", "var2", "var3", "var4" ) # var1..4 are all in > data frame s > for( v in varnames ) { > partialPlot( x=m, pred.data=s, x.var=v ) > } > > ...but this doesn't work, with partialPlot complaining that it can't > find the variable "v". I think I need to force the evaluation of the > loop variable v so that partialPlot sees the correct variable names, > but am stumped after trying eval and similar functions. Any > suggestions on how to do this? Googling has not turned up anything > very useful. > > Thanks, > Ben > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Notice: This e-mail message, together with any attachme...{{dropped:11}}