[R] Multivariate function from univariate functions

physicistintheory physicistintheory at gmail.com
Sun Mar 25 05:04:49 CEST 2012

I'm relatively new to R and I'm stuck.

I'm trying to construct a surface to optimize from a multivariate dataset. 
The dataset contains the response of a system to various stimuli.  I am
trying to optimize the mix of stimuli to maximize the response.  To do so,
I've interpolated the various datasets of type response vs. stimuli and I
now have an array of functions "interps" whose length is the length of the
array of the names of the various stimuli.  I've also created a vector
containing names for the stimuli, vars = x.1, x.2, x.3...

Anyway, each of the functions in interps depends only on one variable
(obviously).  I would like to construct a function, call it, "surface" which
is essentially: surface(vars) = interps[[1]]vars[[1]] +

I've tried constructing surface recursively in a for loop:  
surface <- function(vars){0}
for(i in 1:length(vars)){
surface <- function(vars){surface(vars) + interps[[i]](vars[[i]])}

This results in an infinite recursion error...which I think I understand. 
Essentially, I'm trying to do the analog of something like i = i+1, but
instead of adding integers, I want to add terms to a function.

Any help is appreciated.

View this message in context: http://r.789695.n4.nabble.com/Multivariate-function-from-univariate-functions-tp4502670p4502670.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list