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 Graduate Group in Ecology, U.C. Davis http://www.cstars.ucdavis.edu/~jongreen http://www.cstars.ucdavis.edu AIM: jgrn307 or jgrn3007 MSN: jgrn307 at msn.com or jgrn3007 at msn.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jonathan Greenberg <greenberg at ucdavis.edu> writes:> 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?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) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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:> 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?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._