[R] passing formula arg to mgcv::gam

Vadim Ogranovich vograno at evafunds.com
Tue Sep 28 00:23:35 CEST 2004


Hi,

I have a function, callGam, that fits a gam model to a subset of a dataframe. The argument to callGam is a formula, the subset is determined inside the function itself. My naïve approach generates and error, see below. I guess this is because 'idx' is loocked up in the environment of 'formula', but I am too ignorant about environments to be able to tell for sure. Could someone please suggest a way around?

Thanks,
Vadim

> library("mgcv")
> 
> callGam <- function(formula) {
+   idx <- seq(10)
+   gam(formula, data=data.frame(x=rnorm(100), y=rnorm(100)), subset=idx)
+ }
> 
> gam.fit <- callGam(y ~ x)
Error in eval(expr, envir, enclos) : Object "idx" not found
>




More information about the R-help mailing list