Skip to content

Nonlinear regression and categories

3 messages · Jonathan Greenberg, Peter Dalgaard, Brian Ripley

#
Hi there:

    I'm trying to run a large number of nonlinear regressions on a time
series dataset, where the data will be formatted something to the effect of:

ObservationID,time,dependentvar

I'll have a number of time and dependentvars for each observation, and I
want to apply a nonlinear regression to one ObservationID at a time, and I
want to have a dataset that is the parameter estimates of the equation for
each observation (as opposed to running them one at a time -- I have several
million I need to do).  Is there a way to get R to run a nonlinear
regression based on the above or similar data structure, and return a
database of ObservationID, parameter1, parameter2, parameter3 for each
observation?

Thanks!

--j
#
Jonathan Greenberg <greenberg at ucdavis.edu> writes:
Have a look at nlsList in the nlme package. You might want to have the
book by Pinheiro+Bates handy to see how the pieces fit together.

In general, R is a programming language, so it's fairly easy to do
this kind of thing even when there is no canned implememntation.
Notice in particular the use of implicit loops and their associated
collection of results. For instance, if you want to avoid nlsList's
habit of storing all the fitted models, you could use by()
constructions instead.

Stuff like

example(nlsList)
do.call("rbind",lapply(fm1,coef)) 

# or, using the same data and model

lst <- by(CO2, CO2$Plant, function(x)coef(nls(uptake~SSasympOff(conc,
          Asym, lrc, c0),data=x, start = c(Asym = 30, lrc = -4.5, c0 = 52)))) 
do.call("rbind", lst)

(if the nls() call can fail, you may need a try() construct)
#
Check out nlsList in package nlme, although don't expect to be able to do
several million at once.
On Sat, 9 Nov 2002, Jonathan Greenberg wrote: