[R] syntax problem with formula / nls

Journals fbjournals at gmail.com
Wed Feb 8 19:32:46 CET 2012

I run into a slight syntax proble while using nls that seems to require 
some advice from the R community

I have a nonlinear regression problem where I observe the sum of the  
responses (y) of many individuals (X1 .... Xn). The properties (x1..xn) 
of these individuals have been measured but since the response is 
nonlinear I cannot use a mean individual to estimate the mean response 
of a population.  But I have reasonable reasons to assume that all 
individuals are responding in the same way.

In other words I want to estimate a function as in the last row of the 
example below. (Note, this is an artificial example and it does not 
converge (appart from having to few observations).

data<-as.data.frame(matrix(c(1,2,3,4,5,6,7,7,9,0,1,2,3,4,6, 9), nrow=4, 

nonlin<-nls(y~a*(exp(b*x1)+exp(b*x2)+exp(b*x3))+c, start=list(a=1, b=2, 

Now my problem is that I have 500 different x variables (x1 .... x500) 
for each y variable (and a few thousand of y observations) and I am 
stuck with the syntax problem of how to pass this as a formula to nls. 
Is there any way to define a formula that is passed to nls that would 
take an array of x values.

Cheers Frank

More information about the R-help mailing list