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-requ...@r-project.org wrote:
> Message: 37
> Date: Tue, 22 Oct 2013 17:52:28 +0000
> From: <wayne.w.jo...@shell.com>
> To: <R-help@r-project.org>
> Subject: [R]  nls model definition help
> Message-ID:
>       
> <823fb8ad8fd2f44a92284630a4aadf7e2f1b5...@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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to