Hi fellow R users, I'm trying to fit a model using nls with the following model definition: y(t+1)=(th1*x1 + R1*x2) * exp(a1*x3) + (1-th1*x1 + R1*x2)*y(t) y is the dependent variable (note on both sides of eq) and the x's represent the regressors. th1, R1 and a1 are parameters to be estimated. The problem is non- linear and hence why I'm trying to fit using the well used "nls" function. To fit the model I would like to be able to use the formula interface rather than build my own ugly function definition. Any ideas if this is achievable and if not any ideas on how to fit this model? Many thanks, Wayne ---------------------------------------------------------------------------------------- Wayne Jones Statistics & Chemometrics Shell Global Solutions (UK) Shell Technology Centre Thornton P.O. Box 1, Chester CH1 3SH, United Kingdom Tel: +44 (0) 151 373 5977 Mobile: +44 (0) 7896 536026 Email: Wayne.W.Jones@shell.com<mailto:Wayne.W.Jones@shell.com> Intranet: Statistics and Chemometrics - Shell Wiki<http://sww.wiki.shell.com/wiki/index.php/Statistics_and_Chemometrics> Internet: Shell Global Solutions<http://www.shell.com/globalsolutions> Shell Global Solutions (UK) is a division of Shell Research Limited which has its Registered Office at Shell Centre, London SE1 7NA and is registered in England & Wales with No.539964. [[alternative HTML version deleted]]
Because you have y on both sides, and at different times, I think you are going to have to bite the bullet and write down a residual function. Suggestion: write it as res[t+1] = (th1*x1 + R1*x2) * exp(a1*x3) + (1-th1*x1 + R1*x2)*y(t) - y[t+1] (cleaning up the indices -- they are surely needed for the x's too). This way you can compute derivatives without sign issue if you decide to do so rather than relying on numeric Jacobian. nlmrt or minpack.lm will give more stable computations that nls(). Both have either formula or functional versions of the NLLS minimizer. nlfb() from nlmrt does bounds constraints and also fixed parameters (masks). JN On 13-10-23 06:00 AM, r-help-request at r-project.org wrote:> Message: 37 > Date: Tue, 22 Oct 2013 17:52:28 +0000 > From: <Wayne.W.Jones at shell.com> > To: <R-help at r-project.org> > Subject: [R] nls model definition help > Message-ID: > <823FB8AD8FD2F44A92284630A4AADF7E2F1B5B2D at seacmw-s-53401.europe.shell.com> > > Content-Type: text/plain > > Hi fellow R users, > > I'm trying to fit a model using nls with the following model definition: > > y(t+1)=(th1*x1 + R1*x2) * exp(a1*x3) + (1-th1*x1 + R1*x2)*y(t) > > y is the dependent variable (note on both sides of eq) and the x's represent the regressors. > th1, R1 and a1 are parameters to be estimated. The problem is non- linear and hence why I'm trying to fit using the well used "nls" function. > > To fit the model I would like to be able to use the formula interface rather than build my own ugly function definition. > Any ideas if this is achievable and if not any ideas on how to fit this model? > > > Many thanks, > > Wayne
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Wayne.W.Jones at shell.com > Sent: 22 October 2013 18:52 > To: R-help at r-project.org > Subject: [R] nls model definition help > > Hi fellow R users, > > I'm trying to fit a model using nls with the following model > definition: > > y(t+1)=(th1*x1 + R1*x2) * exp(a1*x3) + (1-th1*x1 + R1*x2)*y(t) > > ... > > Any ideas if this is achievable and if not any ideas on how to fit this > model?I'm thinking not, as you have that (t+1) back-reference in there which makes the calculated y(t) part of the expression. Pretty sure nlm won't handle that in the formula interface. However, you could use nlm or optim if you write a function to predict y and then wrap that in a function to calculate the residual sum of squares (taking the parameter vector and y[obs] as parameters), then minimise the residual SS. The hessian from either can then be used to estimate standard errors using the usual least-squares formulae. S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}